summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2002-03-13 17:40:34 +0000
committerMatthew Newhook <matthew@zeroc.com>2002-03-13 17:40:34 +0000
commit56ff80265761eda3f54ef343c3654dd1aa4cce0c (patch)
tree56ca3d6b054f7edfe5c1f06f131d81656f2111ed /java
parentAdded project files for Freeze/library demo (diff)
downloadice-56ff80265761eda3f54ef343c3654dd1aa4cce0c.tar.bz2
ice-56ff80265761eda3f54ef343c3654dd1aa4cce0c.tar.xz
ice-56ff80265761eda3f54ef343c3654dd1aa4cce0c.zip
Added Freeze/library demo.
Diffstat (limited to 'java')
-rw-r--r--java/ant/Slice2FreezeJTask$Dict.classbin1092 -> 1092 bytes
-rw-r--r--java/ant/Slice2FreezeJTask.classbin5660 -> 5722 bytes
-rw-r--r--java/ant/Slice2FreezeJTask.java22
-rw-r--r--java/demo/Freeze/bench/Client.java12
-rw-r--r--java/demo/Freeze/build.xml2
-rw-r--r--java/demo/Freeze/library/BookFactory.java33
-rw-r--r--java/demo/Freeze/library/BookI.java118
-rw-r--r--java/demo/Freeze/library/Client.java25
-rw-r--r--java/demo/Freeze/library/Collocated.java100
-rw-r--r--java/demo/Freeze/library/Grammar.java188
-rw-r--r--java/demo/Freeze/library/Library.ice233
-rw-r--r--java/demo/Freeze/library/LibraryI.java235
-rw-r--r--java/demo/Freeze/library/Parser.java371
-rw-r--r--java/demo/Freeze/library/RunParser.java104
-rw-r--r--java/demo/Freeze/library/Scanner.java288
-rw-r--r--java/demo/Freeze/library/Server.java108
-rw-r--r--java/demo/Freeze/library/Token.java42
-rw-r--r--java/demo/Freeze/library/books32
-rw-r--r--java/demo/Freeze/library/build.xml62
-rw-r--r--java/demo/Freeze/library/config9
-rw-r--r--java/demo/Freeze/library/db/.dummy0
-rw-r--r--java/demo/Freeze/phonebook/Collocated.java1
-rw-r--r--java/demo/Freeze/phonebook/Parser.java24
-rw-r--r--java/demo/Freeze/phonebook/PhoneBookI.java1
-rw-r--r--java/demo/Freeze/phonebook/RunParser.java36
-rw-r--r--java/demo/Freeze/phonebook/Server.java1
-rw-r--r--java/src/Ice/Application.java7
27 files changed, 2024 insertions, 30 deletions
diff --git a/java/ant/Slice2FreezeJTask$Dict.class b/java/ant/Slice2FreezeJTask$Dict.class
index 481778d8215..f06a22dbbcd 100644
--- a/java/ant/Slice2FreezeJTask$Dict.class
+++ b/java/ant/Slice2FreezeJTask$Dict.class
Binary files differ
diff --git a/java/ant/Slice2FreezeJTask.class b/java/ant/Slice2FreezeJTask.class
index 39207cfeb45..977ecec11c1 100644
--- a/java/ant/Slice2FreezeJTask.class
+++ b/java/ant/Slice2FreezeJTask.class
Binary files differ
diff --git a/java/ant/Slice2FreezeJTask.java b/java/ant/Slice2FreezeJTask.java
index fe360eb93dd..e10ff48d3b9 100644
--- a/java/ant/Slice2FreezeJTask.java
+++ b/java/ant/Slice2FreezeJTask.java
@@ -117,11 +117,10 @@ public class Slice2FreezeJTask extends org.apache.tools.ant.Task
public FileSet
createFileset()
{
- if (_fileSet == null)
- {
- _fileSet = new FileSet();
- }
- return _fileSet;
+ FileSet fileset = new FileSet();
+ _fileSets.add(fileset);
+
+ return fileset;
}
public Dict
@@ -147,21 +146,24 @@ public class Slice2FreezeJTask extends org.apache.tools.ant.Task
boolean build = false;
java.util.List sliceFiles = new java.util.LinkedList();
- if (_fileSet != null)
+ java.util.Iterator p = _fileSets.iterator();
+ while (p.hasNext())
{
- DirectoryScanner scanner = _fileSet.getDirectoryScanner(project);
+ FileSet fileset = (FileSet)p.next();
+
+ DirectoryScanner scanner = fileset.getDirectoryScanner(project);
String[] files = scanner.getIncludedFiles();
for (int i = 0; i < files.length; i++)
{
- File slice = new File(_fileSet.getDir(project), files[i]);
+ File slice = new File(fileset.getDir(project), files[i]);
sliceFiles.add(slice);
}
}
java.util.List tagFiles = new java.util.LinkedList();
- java.util.Iterator p = _dicts.iterator();
+ p = _dicts.iterator();
while (p.hasNext())
{
//
@@ -289,7 +291,7 @@ public class Slice2FreezeJTask extends org.apache.tools.ant.Task
private File _tagDir = new File(".");
private File _outputDir = null;
private Path _includePath = null;
- private FileSet _fileSet = null;
+ private java.util.List _fileSets = new java.util.LinkedList();
public class Dict
{
diff --git a/java/demo/Freeze/bench/Client.java b/java/demo/Freeze/bench/Client.java
index 7872ec17e25..f802fb6c765 100644
--- a/java/demo/Freeze/bench/Client.java
+++ b/java/demo/Freeze/bench/Client.java
@@ -161,7 +161,7 @@ class TestApp extends Freeze.Application
}
void
- GeneratedRead(IntIntMap m, int reads, Generator gen)
+ generatedRead(IntIntMap m, int reads, Generator gen)
{
_watch.start();
for (int i = 0; i < reads; ++i)
@@ -203,15 +203,15 @@ class TestApp extends Freeze.Application
//
// Do some read tests.
//
- GeneratedRead(m, _repetitions, new SequentialGenerator(1000, 1000));
- GeneratedRead(m, _repetitions, new SequentialGenerator(2000, 2009));
- GeneratedRead(m, _repetitions, new SequentialGenerator(3000, 3099));
- GeneratedRead(m, _repetitions, new SequentialGenerator(4000, 4999));
+ generatedRead(m, _repetitions, new SequentialGenerator(1000, 1000));
+ generatedRead(m, _repetitions, new SequentialGenerator(2000, 2009));
+ generatedRead(m, _repetitions, new SequentialGenerator(3000, 3099));
+ generatedRead(m, _repetitions, new SequentialGenerator(4000, 4999));
//
// Do a random read test.
//
- GeneratedRead(m, _repetitions, new RandomGenerator(0, 10000));
+ generatedRead(m, _repetitions, new RandomGenerator(0, 10000));
//
// Remove each record.
diff --git a/java/demo/Freeze/build.xml b/java/demo/Freeze/build.xml
index d9005b0c4cb..2a0f552813d 100644
--- a/java/demo/Freeze/build.xml
+++ b/java/demo/Freeze/build.xml
@@ -2,11 +2,13 @@
<target name="all">
<ant dir="phonebook"/>
+ <ant dir="library"/>
<ant dir="bench"/>
</target>
<target name="clean">
<ant dir="phonebook" target="clean"/>
+ <ant dir="library" target="clean"/>
<ant dir="bench" target="clean"/>
</target>
diff --git a/java/demo/Freeze/library/BookFactory.java b/java/demo/Freeze/library/BookFactory.java
new file mode 100644
index 00000000000..061c49bdf67
--- /dev/null
+++ b/java/demo/Freeze/library/BookFactory.java
@@ -0,0 +1,33 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class BookFactory implements Ice.ObjectFactory
+{
+ public Ice.Object
+ create(String type)
+ {
+ assert(type.equals("::Book"));
+ return new BookI(_library, _evictor);
+ }
+
+ public void
+ destroy()
+ {
+ }
+
+ BookFactory(LibraryI library, Freeze.Evictor evictor)
+ {
+ _library = library;
+ _evictor = evictor;
+ }
+
+ private LibraryI _library;
+ private Freeze.Evictor _evictor;
+}
diff --git a/java/demo/Freeze/library/BookI.java b/java/demo/Freeze/library/BookI.java
new file mode 100644
index 00000000000..22bbbd1af8c
--- /dev/null
+++ b/java/demo/Freeze/library/BookI.java
@@ -0,0 +1,118 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class BookI extends Book
+{
+ //
+ // No read/write mutexes in Java - hence use native
+ // syncronization.
+ //
+
+ public BookDescription
+ getBookDescription(Ice.Current current)
+ {
+ //
+ // Immutable.
+ //
+ return _description;
+ }
+
+ synchronized public String
+ getRenterName(Ice.Current current)
+ throws BookNotRentedException
+ {
+ if (_rentalCustomerName.length() == 0)
+ {
+ throw new BookNotRentedException();
+ }
+ return _rentalCustomerName;
+ }
+
+ synchronized public void
+ rentBook(String name, Ice.Current current)
+ throws BookRentedException
+ {
+ if (_rentalCustomerName.length() != 0)
+ {
+ throw new BookRentedException();
+ }
+ _rentalCustomerName = name;
+ }
+
+ synchronized public void
+ returnBook(Ice.Current current)
+ throws BookNotRentedException
+ {
+ if (_rentalCustomerName.length() != 0)
+ {
+ throw new BookNotRentedException();
+ }
+ _rentalCustomerName = new String();;
+ }
+
+ synchronized public void
+ destroy(Ice.Current current)
+ throws DatabaseException
+ {
+ try
+ {
+ _library.remove(_description);
+
+ //
+ // This can throw EvictorDeactivatedException (which
+ // indicates an internal error). The exception is
+ // currently ignored.
+ //
+ _evictor.destroyObject(createIdentity(_description.isbn));
+ }
+ catch(Freeze.DBNotFoundException ex)
+ {
+ //
+ // Raised by remove. Ignore.
+ //
+ }
+ catch(Freeze.DBException ex)
+ {
+ DatabaseException e = new DatabaseException();
+ e.message = ex.message;
+ throw e;
+ }
+ }
+
+ public static Ice.Identity
+ createIdentity(String isbn)
+ {
+ //
+ // Note that the identity category is important since the
+ // locator was installed for the category 'book'.
+ //
+ Ice.Identity ident = new Ice.Identity();
+ ident.category = "book";
+ ident.name = isbn;
+
+ return ident;
+ }
+
+ BookI(LibraryI library, Freeze.Evictor evictor)
+ {
+ _library = library;
+ _evictor = evictor;
+
+ //
+ // This could be avoided by having two constructors (one for
+ // new creation of a book, and the other for restoring a
+ // previously saved book).
+ //
+ _rentalCustomerName = new String();
+ }
+
+ private LibraryI _library;
+ private Freeze.Evictor _evictor;
+}
diff --git a/java/demo/Freeze/library/Client.java b/java/demo/Freeze/library/Client.java
new file mode 100644
index 00000000000..a1ce70b0caa
--- /dev/null
+++ b/java/demo/Freeze/library/Client.java
@@ -0,0 +1,25 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+public class Client extends Ice.Application
+{
+ public int
+ run(String[] args)
+ {
+ return RunParser.runParser(appName(), args, communicator());
+ }
+
+ static public void
+ main(String[] args)
+ {
+ Client app = new Client();
+ app.main("demo.Freeze.phonebook.Client", args, "config");
+ }
+}
diff --git a/java/demo/Freeze/library/Collocated.java b/java/demo/Freeze/library/Collocated.java
new file mode 100644
index 00000000000..873548e24d8
--- /dev/null
+++ b/java/demo/Freeze/library/Collocated.java
@@ -0,0 +1,100 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class PhoneBookCollocated extends Freeze.Application
+{
+ PhoneBookCollocated(String dbEnvName)
+ {
+ super(dbEnvName);
+ }
+
+ public int
+ runFreeze(String[] args, Freeze.DBEnvironment dbEnv)
+ {
+ Ice.Properties properties = communicator().getProperties();
+
+ Freeze.DB dbBooks = dbEnv.openDB("books", true);
+ Freeze.DB dbAuthors = dbEnv.openDB("authors", true);
+
+ //
+ // Create an Evictor for books.
+ //
+ Freeze.EvictorPersistenceMode mode;
+ int v = 0;
+ try
+ {
+ v = Integer.parseInt(properties.getProperty("Library.SaveAfterMutatingOperation"));
+ }
+ catch (NumberFormatException ex)
+ {
+ }
+
+ if(v != 0)
+ {
+ mode = Freeze.EvictorPersistenceMode.SaveAfterMutatingOperation;
+ }
+ else
+ {
+ mode = Freeze.EvictorPersistenceMode.SaveUponEviction;
+ }
+ Freeze.Evictor evictor = dbBooks.createEvictor(mode);
+
+ v = 0;
+ try
+ {
+ v = Integer.parseInt(properties.getProperty("Library.EvictorSize"));
+ }
+ catch (NumberFormatException ex)
+ {
+ }
+
+ if(v != 0)
+ {
+ evictor.setSize(v);
+ }
+
+ //
+ // Create an Object Adapter, use the Evictor as Servant
+ // Locator.
+ //
+ Ice.ObjectAdapter adapter = communicator().createObjectAdapter("LibraryAdapter");
+ adapter.addServantLocator(evictor, "book");
+
+ //
+ // Create the library, and add it to the Object Adapter.
+ //
+ LibraryI phoneBook = new LibraryI(adapter, dbAuthors, evictor);
+ adapter.add(phoneBook, Ice.Util.stringToIdentity("library"));
+
+ //
+ // Create and install a factory and initializer for books.
+ //
+ Ice.ObjectFactory bookFactory = new BookFactory(phoneBook, evictor);
+ communicator().addObjectFactory(bookFactory, "::Book");
+
+ //
+ // Everything ok, let's go.
+ //
+ int status = RunParser.runParser(appName(), args, communicator());
+ adapter.deactivate();
+
+ return status;
+ }
+}
+
+public class Collocated
+{
+ static public void
+ main(String[] args)
+ {
+ PhoneBookCollocated app = new PhoneBookCollocated("db");
+ app.main("test.Freeze.phonebook.Collocated", args, "config");
+ }
+}
diff --git a/java/demo/Freeze/library/Grammar.java b/java/demo/Freeze/library/Grammar.java
new file mode 100644
index 00000000000..e1f81d6c8f0
--- /dev/null
+++ b/java/demo/Freeze/library/Grammar.java
@@ -0,0 +1,188 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class Grammar
+{
+ Grammar(Parser p)
+ {
+ _parser = p;
+ _scanner = new Scanner(_parser);
+ }
+
+
+ static private class ParseError extends RuntimeException
+ {
+ ParseError(String msg)
+ {
+ super(msg);
+ }
+ }
+
+ void
+ parse()
+ {
+ while (true)
+ {
+ try
+ {
+ _token = _scanner.nextToken();
+ if (_token == null)
+ {
+ return;
+ }
+ else if (_token.type == Token.TOK_SEMI)
+ {
+ // Continue
+ }
+ else if (_token.type == Token.TOK_HELP)
+ {
+ _token = _scanner.nextToken();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+
+ _parser.usage();
+ }
+ else if (_token.type == Token.TOK_EXIT)
+ {
+ _token = _scanner.nextToken();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+
+ return;
+ }
+ else if (_token.type == Token.TOK_ADD_BOOK)
+ {
+ java.util.LinkedList s = strings();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+ _parser.addBook(s);
+ }
+ else if (_token.type == Token.TOK_FIND_ISBN)
+ {
+ java.util.LinkedList s = strings();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+ _parser.findIsbn(s);
+ }
+ else if (_token.type == Token.TOK_FIND_AUTHORS)
+ {
+ java.util.LinkedList s = strings();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+ _parser.findAuthors(s);
+ }
+ else if (_token.type == Token.TOK_NEXT_FOUND_BOOK)
+ {
+ _token = _scanner.nextToken();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+
+ _parser.nextFoundBook();
+ }
+ else if (_token.type == Token.TOK_PRINT_CURRENT)
+ {
+ _token = _scanner.nextToken();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+
+ _parser.printCurrent();
+ }
+ else if (_token.type == Token.TOK_RENT_BOOK)
+ {
+ java.util.LinkedList s = strings();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+ _parser.rentCurrent(s);
+ }
+ else if (_token.type == Token.TOK_RETURN_BOOK)
+ {
+ _token = _scanner.nextToken();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+ _parser.returnCurrent();
+ }
+ else if (_token.type == Token.TOK_REMOVE_CURRENT)
+ {
+ _token = _scanner.nextToken();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+
+ _parser.removeCurrent();
+ }
+ else if (_token.type == Token.TOK_SET_EVICTOR_SIZE)
+ {
+ java.util.LinkedList s = strings();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+ _parser.setEvictorSize(s);
+ }
+ else if (_token.type == Token.TOK_SHUTDOWN)
+ {
+ _token = _scanner.nextToken();
+ if (_token.type != Token.TOK_SEMI)
+ {
+ throw new ParseError("Expected ';'");
+ }
+
+ _parser.shutdown();
+ }
+ else
+ {
+ _parser.error("parse error");
+ }
+ }
+ catch(ParseError e)
+ {
+ _parser.error("Parse error: " + e.getMessage());
+ }
+ }
+ }
+
+ private java.util.LinkedList
+ strings()
+ {
+ java.util.LinkedList l = new java.util.LinkedList();
+ while (true)
+ {
+ _token = _scanner.nextToken();
+ if (_token.type != Token.TOK_STRING)
+ {
+ return l;
+ }
+ l.add(_token.value);
+ }
+ }
+
+ private Parser _parser;
+ private Scanner _scanner;
+ private Token _token;
+}
diff --git a/java/demo/Freeze/library/Library.ice b/java/demo/Freeze/library/Library.ice
new file mode 100644
index 00000000000..d89b61c2161
--- /dev/null
+++ b/java/demo/Freeze/library/Library.ice
@@ -0,0 +1,233 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#ifndef LIBRARY_ICE
+#define LIBRARY_ICE
+
+/**
+ *
+ * This exception is raised in the case of a database failure.
+ *
+ **/
+exception DatabaseException
+{
+ string message;
+};
+
+/**
+ *
+ * This exception is raised if the book already exists.
+ *
+ **/
+exception BookExistsException
+{
+};
+
+/**
+ *
+ * This exception is raised if a book has already been rented.
+ *
+ **/
+exception BookRentedException
+{
+};
+
+/**
+ *
+ * This exception is raised if the book has not been rented.
+ *
+ **/
+exception BookNotRentedException
+{
+};
+
+/**
+ *
+ * A description of a book.
+ *
+ **/
+struct BookDescription
+{
+ /** The ISBN number of the book. */
+ string isbn;
+
+ /** The title of the book. */
+ string title;
+
+ /** The authors of the book. */
+ string authors;
+};
+
+/**
+ *
+ * This class represents a book.
+ *
+ **/
+class Book
+{
+ /**
+ *
+ * Get a description of the book.
+ *
+ * @return The book description.
+ *
+ **/
+ ["nonmutating"] BookDescription getBookDescription();
+
+ /**
+ *
+ * Destroy the book. [destroy] is nonmutating. It doesn't change
+ * the state of the Book. It removes the Book completely, but
+ * doesn't touch state.
+ *
+ * @throws DatabaseException Raised if there is a problem with the
+ * database system.
+ *
+ **/
+ ["nonmutating"] void destroy()
+ throws DatabaseException;
+
+ /**
+ *
+ * Rent the book to the specified customer.
+ *
+ * @param name The name of the customer.
+ *
+ * @throws BookRentedException Raised if the book has already been
+ * rented.
+ *
+ **/
+ void rentBook(string name)
+ throws BookRentedException;
+
+ /**
+ *
+ * Get the name of the renter.
+ *
+ * @return The name the current rental customer.
+ *
+ * @throws BookNotRentedException Raised if the book is not
+ * currently rented.
+ *
+ **/
+ ["nonmutating"] string getRenterName()
+ throws BookNotRentedException;
+
+ /**
+ *
+ * Return the book.
+ *
+ * @throws BookNotRentedException Raised if the book is not
+ * currently rented.
+ *
+ **/
+ void returnBook()
+ throws BookNotRentedException;
+
+ /**
+ *
+ * The description for this book. Once a book has been created
+ * this information is immutable.
+ *
+ **/
+ BookDescription _description;
+
+ /**
+ *
+ * The name of the current rental customer, or the empty string if
+ * the book is not currently rented.
+ *
+ **/
+ string _rentalCustomerName;
+};
+
+/**
+ *
+ * A sequence of book proxies.
+ *
+ **/
+sequence<Book*> BookPrxSeq;
+
+/**
+ *
+ * This interface represents a library.
+ *
+ **/
+interface Library
+{
+ /**
+ *
+ * Create a book with the given description.
+ *
+ * @param description The book description.
+ *
+ * @return A proxy for the new book.
+ *
+ * @throws DatabaseException Raised if there is a problem with the
+ * database.
+ *
+ * @throws BookExistsException Raised if the book already exists.
+ *
+ **/
+ Book* createBook(BookDescription description)
+ throws DatabaseException, BookExistsException;
+
+ /**
+ *
+ * Find a book by its ISBN number.
+ *
+ * @param isbn The ISBN number.
+ *
+ * @return The result of the search, or an null proxy if the book
+ * was not found.
+ *
+ * @throws DatabaseException Raised if there is a problem with the database.
+ *
+ **/
+ ["nonmutating"] Book* findByIsbn(string isbn)
+ throws DatabaseException;
+
+ /**
+ *
+ * Find all books with a given authors.
+ *
+ * @param title The search parameters.
+ *
+ * @return The result of the search, or an empty sequence if no
+ * books were found.
+ *
+ * @throws DatabaseException Raised if there is a problem with the database.
+ *
+ **/
+ ["nonmutating"] BookPrxSeq findByAuthors(string authors)
+ throws DatabaseException;
+
+ /**
+ *
+ * Set the evictor size.
+ *
+ * @param size The new size for the evictor.
+ *
+ * @throws DatabaseException Raised if there is a problem with the
+ * database.
+ *
+ **/
+ ["nonmutating"] void setEvictorSize(int size)
+ throws DatabaseException;
+
+ /**
+ *
+ * Shutdown the server.
+ *
+ **/
+ ["nonmutating"] void shutdown();
+};
+
+#endif
diff --git a/java/demo/Freeze/library/LibraryI.java b/java/demo/Freeze/library/LibraryI.java
new file mode 100644
index 00000000000..8f1fd783033
--- /dev/null
+++ b/java/demo/Freeze/library/LibraryI.java
@@ -0,0 +1,235 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class LibraryI extends _LibraryDisp
+{
+ private BookPrx
+ isbnToBook(String isbn)
+ {
+ return BookPrxHelper.uncheckedCast(_adapter.createProxy(BookI.createIdentity(isbn)));
+ }
+
+ public synchronized BookPrx
+ createBook(BookDescription description, Ice.Current current)
+ throws DatabaseException, BookExistsException
+ {
+ BookPrx book = isbnToBook(description.isbn);
+
+ try
+ {
+ book.ice_ping();
+
+ //
+ // The book already exists.
+ //
+ throw new BookExistsException();
+ }
+ catch(Ice.ObjectNotExistException e)
+ {
+ //
+ // Book doesn't exist, ignore the exception.
+ //
+ }
+
+ //
+ // Create a new book Servant.
+ //
+ BookI bookI = new BookI(this, _evictor);
+ bookI._description = description;
+
+ Ice.Identity ident = BookI.createIdentity(description.isbn);
+
+ //
+ // Create a new Ice Object in the evictor, using the new
+ // identity and the new Servant.
+ //
+ // This can throw EvictorDeactivatedException (which indicates
+ // an internal error). The exception is currently ignored.
+ //
+ _evictor.createObject(ident, bookI);
+
+ try
+ {
+ //
+ // Add the isbn number to the authors map.
+ //
+ String[] isbnSeq = (String[])_authors.get(description.authors);
+ int length = (isbnSeq == null) ? 0 : isbnSeq.length;
+ String[] newIsbnSeq = new String[length+1];
+
+ if (isbnSeq != null)
+ {
+ System.arraycopy(isbnSeq, 0, newIsbnSeq, 0, length);
+ }
+ newIsbnSeq[length] = description.isbn;
+
+ _authors.put(description.authors, newIsbnSeq);
+
+ return book;
+ }
+ catch(Freeze.DBException ex)
+ {
+ DatabaseException e = new DatabaseException();
+ e.message = ex.message;
+ throw e;
+ }
+ }
+
+ //
+ // No locking is necessary since no internal mutable state is
+ // accessed.
+ //
+ public BookPrx
+ findByIsbn(String isbn, Ice.Current current)
+ throws DatabaseException
+ {
+ try
+ {
+ BookPrx book = isbnToBook(isbn);
+ book.ice_ping();
+
+ return book;
+ }
+ catch(Ice.ObjectNotExistException ex)
+ {
+ //
+ // Book doesn't exist, return a null proxy.
+ //
+ return null;
+ }
+ }
+
+ public synchronized BookPrx[]
+ findByAuthors(String authors, Ice.Current current)
+ throws DatabaseException
+ {
+ try
+ {
+ //
+ // Lookup all phone book books that match a name, and
+ // return them to the caller. See the comment in
+ // getNewIdentity why the prefix "N" is needed.
+ //
+ String[] isbnSeq = (String[])_authors.get(authors);
+
+ int length = (isbnSeq == null) ? 0 : isbnSeq.length;
+ BookPrx[] books = new BookPrx[length];
+
+ if (isbnSeq != null)
+ {
+ for (int i = 0; i < length; ++i)
+ {
+ books[i] = isbnToBook(isbnSeq[i]);
+ }
+ }
+
+ return books;
+ }
+ catch(Freeze.DBException ex)
+ {
+ DatabaseException e = new DatabaseException();
+ e.message = ex.message;
+ throw e;
+ }
+ }
+
+ public void
+ setEvictorSize(int size, Ice.Current current)
+ throws DatabaseException
+ {
+ //
+ // No synchronization necessary, _evictor is immutable.
+ //
+ _evictor.setSize(size);
+ }
+
+ public void
+ shutdown(Ice.Current current)
+ {
+ //
+ // No synchronization necessary, _adapter is immutable.
+ //
+ _adapter.getCommunicator().shutdown();
+ }
+
+ protected synchronized void
+ remove(BookDescription description)
+ throws DatabaseException
+ {
+ try
+ {
+ String[] isbnSeq = (String[])_authors.get(description.authors);
+
+ //
+ // If the title isn't found then raise a record not found
+ // exception.
+ //
+ if (isbnSeq == null)
+ {
+ throw new Freeze.DBNotFoundException();
+ }
+
+ int i;
+ for (i = 0; i < isbnSeq.length; ++i)
+ {
+ if (isbnSeq[i].equals(description.isbn))
+ {
+ break;
+ }
+ }
+
+ if (i >= isbnSeq.length)
+ {
+ throw new Freeze.DBNotFoundException();
+ }
+
+ if (isbnSeq.length == 1)
+ {
+ //
+ // If there are no further associated isbn numbers then remove
+ // the record.
+ //
+ _authors.remove(description.authors);
+ }
+ else
+ {
+ //
+ // Remove the isbn number from the sequence and write
+ // back the new record.
+ //
+ String[] newIsbnSeq = new String[isbnSeq.length-1];
+ System.arraycopy(isbnSeq, 0, newIsbnSeq, 0, i);
+ if (i < newIsbnSeq.length - 1)
+ {
+ System.arraycopy(isbnSeq, i+1, newIsbnSeq, i, isbnSeq.length - i - 1);
+ }
+
+ _authors.put(description.authors, newIsbnSeq);
+ }
+ }
+ catch(Freeze.DBException ex)
+ {
+ DatabaseException e = new DatabaseException();
+ e.message = ex.message;
+ throw e;
+ }
+ }
+
+ LibraryI(Ice.ObjectAdapter adapter, Freeze.DB db, Freeze.Evictor evictor)
+ {
+ _adapter = adapter;
+ _evictor = evictor;
+ _authors = new StringIsbnSeqDict(db);
+ }
+
+ private Ice.ObjectAdapter _adapter;
+ private Freeze.Evictor _evictor;
+ private StringIsbnSeqDict _authors;
+}
diff --git a/java/demo/Freeze/library/Parser.java b/java/demo/Freeze/library/Parser.java
new file mode 100644
index 00000000000..6eabc9a78c0
--- /dev/null
+++ b/java/demo/Freeze/library/Parser.java
@@ -0,0 +1,371 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class Parser
+{
+ public
+ Parser(Ice.Communicator communicator, LibraryPrx library)
+ {
+ _communicator = communicator;
+ _library = library;
+ }
+
+ public void
+ usage()
+ {
+ System.err.print(
+ "help Print this message.\n" +
+ "exit, quit Exit this program.\n" +
+ "add isbn title authors Create new book.\n" +
+ "isbn NUMBER Find the book with given ISBN number.\n" +
+ "authors NAME Find all books by the given authors.\n" +
+ "next Set the current book to the next one that was found.\n" +
+ "current Display the current book.\n" +
+ "rent NAME Rent the current book for customer NAME.\n" +
+ "return Return the currently rented book.\n" +
+ "remove Permanently remove the current book from the library.\n" +
+ "size SIZE Set the evictor size for books to SIZE.\n" +
+ "shutdown Shut the library server down.\n");
+ }
+
+ public void
+ addBook(java.util.LinkedList args)
+ {
+ if (args.size() != 3)
+ {
+ error("`add' requires at exactly three arguments (type `help' for more info)");
+ return;
+ }
+
+ try
+ {
+ BookDescription desc = new BookDescription();
+ desc.isbn = (String)args.get(0);
+ desc.title = (String)args.get(1);
+ desc.authors = (String)args.get(2);
+
+ BookPrx book = _library.createBook(desc);
+ System.out.println("added new book with isbn " + desc.isbn);
+ }
+ catch(DatabaseException ex)
+ {
+ error(ex.message);
+ }
+ catch(BookExistsException ex)
+ {
+ error("the book already exists.");
+ }
+ catch(Ice.LocalException ex)
+ {
+ error(ex.toString());
+ }
+ }
+
+ public void
+ findIsbn(java.util.LinkedList args)
+ {
+ if (args.size() != 1)
+ {
+ error("`isbn' requires exactly one argument (type `help' for more info)");
+ return;
+ }
+
+ try
+ {
+ _foundBooks = null;
+ _current = 0;
+
+ BookPrx book = _library.findByIsbn((String)args.get(0));
+ if (book == null)
+ {
+ System.out.println("no book with that ISBN number exists.");
+ }
+ else
+ {
+ _foundBooks = new BookPrx[1];
+ _foundBooks[0] = book;
+ printCurrent();
+ }
+ }
+ catch(DatabaseException ex)
+ {
+ error(ex.message);
+ }
+ catch(Ice.LocalException ex)
+ {
+ error(ex.toString());
+ }
+ }
+
+ public void
+ findAuthors(java.util.LinkedList args)
+ {
+ if (args.size() != 1)
+ {
+ error("`authors' requires exactly one argument (type `help' for more info)");
+ return;
+ }
+
+ try
+ {
+ _foundBooks = _library.findByAuthors((String)args.get(0));
+ _current = 0;
+ System.out.println("number of books found: " + _foundBooks.length);
+ printCurrent();
+ }
+ catch(DatabaseException ex)
+ {
+ error(ex.message);
+ }
+ catch(Ice.LocalException ex)
+ {
+ error(ex.toString());
+ }
+ }
+
+ public void
+ nextFoundBook()
+ {
+ if (_current != _foundBooks.length)
+ {
+ ++_current;
+ }
+ printCurrent();
+ }
+
+ public void
+ printCurrent()
+ {
+ try
+ {
+ if (_current != _foundBooks.length)
+ {
+ BookDescription desc = _foundBooks[_current].getBookDescription();
+ String renter = null;
+ try
+ {
+ renter = _foundBooks[_current].getRenterName();
+ }
+ catch(BookNotRentedException ex)
+ {
+ }
+
+ System.out.println("current book is:" );
+ System.out.println("isbn: " + desc.isbn);
+ System.out.println("title: " + desc.title);
+ System.out.println("authors: " + desc.authors);
+ if (renter != null)
+ {
+ System.out.println("rented: " + renter);
+ }
+ }
+ else
+ {
+ System.out.println("no current book");
+ }
+ }
+ catch(Ice.LocalException ex)
+ {
+ error(ex.toString());
+ }
+ }
+
+ public void
+ rentCurrent(java.util.LinkedList args)
+ {
+ if (args.size() != 1)
+ {
+ error("`rent' requires exactly one argument (type `help' for more info)");
+ return;
+ }
+
+ try
+ {
+ if (_current != _foundBooks.length)
+ {
+ _foundBooks[_current].rentBook((String)args.get(0));
+ System.out.println("the book is now rented by `" + (String)args.get(0) + "'");
+ }
+ else
+ {
+ System.out.println("no current book");
+ }
+ }
+ catch(BookRentedException ex)
+ {
+ System.out.println("the book has already been rented.");
+ }
+ catch(Ice.LocalException ex)
+ {
+ error(ex.toString());
+ }
+ }
+
+ public void
+ returnCurrent()
+ {
+ try
+ {
+ if (_current != _foundBooks.length)
+ {
+ _foundBooks[_current].returnBook();
+ System.out.println( "the book has been returned.");
+ }
+ else
+ {
+ System.out.println("no current book");
+ }
+ }
+ catch(BookNotRentedException ex)
+ {
+ System.out.println("the book is not currently rented.");
+ }
+ catch(Ice.LocalException ex)
+ {
+ error(ex.toString());
+ }
+ }
+
+ public void
+ removeCurrent()
+ {
+ try
+ {
+ if (_current != _foundBooks.length)
+ {
+ _foundBooks[_current].destroy();
+ System.out.println("removed current book" );
+ }
+ else
+ {
+ System.out.println("no current book" );
+ }
+ }
+ catch(DatabaseException ex)
+ {
+ error(ex.message);
+ }
+ catch(Ice.LocalException ex)
+ {
+ error(ex.toString());
+ }
+ }
+
+ public void
+ setEvictorSize(java.util.LinkedList args)
+ {
+ if (args.size() != 1)
+ {
+ error("`size' requires exactly one argument (type `help' for more info)");
+ return;
+ }
+
+ String s = (String)args.getFirst();
+ try
+ {
+ _library.setEvictorSize(Integer.parseInt(s));
+ }
+ catch (NumberFormatException ex)
+ {
+ error("not a number " + s);
+ }
+ catch(DatabaseException ex)
+ {
+ error(ex.message);
+ }
+ catch(Ice.LocalException ex)
+ {
+ error(ex.toString());
+ }
+ }
+
+ public void
+ shutdown()
+ {
+ try
+ {
+ _library.shutdown();
+ }
+ catch(Ice.LocalException ex)
+ {
+ error(ex.toString());
+ }
+ }
+
+ public void
+ error(String s)
+ {
+ System.err.println("error: " + s);
+ }
+
+ public void
+ warning(String s)
+ {
+ System.err.println("warning: " + s);
+ }
+
+ public String
+ getInput()
+ {
+ if (_interactive)
+ {
+ System.out.print(">>> ");
+ System.out.flush();
+ }
+
+ try
+ {
+ return _in.readLine();
+ }
+ catch(java.io.IOException e)
+ {
+ return null;
+ }
+ }
+
+ public int
+ parse()
+ {
+ _foundBooks = new BookPrx[0];
+ _current = 0;
+
+ _in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
+ _interactive = true;
+
+ Grammar g = new Grammar(this);
+ g.parse();
+
+ return 0;
+ }
+
+ public int
+ parse(java.io.BufferedReader in)
+ {
+ _foundBooks = new BookPrx[0];
+ _current = 0;
+
+ _in = in;
+ _interactive = false;
+
+ Grammar g = new Grammar(this);
+ g.parse();
+
+ return 0;
+ }
+
+ private BookPrx[] _foundBooks;
+ private int _current;
+
+ private Ice.Communicator _communicator;
+ private LibraryPrx _library;
+
+ private java.io.BufferedReader _in;
+ private boolean _interactive;
+}
diff --git a/java/demo/Freeze/library/RunParser.java b/java/demo/Freeze/library/RunParser.java
new file mode 100644
index 00000000000..ec2d045de3b
--- /dev/null
+++ b/java/demo/Freeze/library/RunParser.java
@@ -0,0 +1,104 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class RunParser
+{
+ static void
+ usage(String appName)
+ {
+ System.err.println("Usage: " + appName + " [options] [file...]\n");
+ System.err.print(
+ "Options:\n" +
+ "-h, --help Show this message.\n");
+ //"-v, --version Display the Ice version.\n"
+ }
+
+ static int
+ runParser(String appName, String[] args, Ice.Communicator communicator)
+ {
+ String file = null;
+ int idx = 0;
+
+ while (idx < args.length)
+ {
+ if (args[idx].equals("-h") | args[idx].equals("--help"))
+ {
+ usage(appName);
+ return 0;
+ }
+/*
+ else if (args[idx].equals("-v") || args[idx].equals("--version"))
+ {
+ cout + ICE_STRING_VERSION + endl;
+ return 0;
+ }
+*/
+ else if (args[idx].charAt(0) == '-')
+ {
+ System.err.println(appName + ": unknown option `" + args[idx] + "'");
+ usage(appName);
+ return 1;
+ }
+ else
+ {
+ if (file == null)
+ {
+ file = args[idx];
+ }
+ else
+ {
+ System.err.println(appName + ": only one file is supported.");
+ usage(appName);
+ return 1;
+ }
+ ++idx;
+ }
+ }
+
+ Ice.Properties properties = communicator.getProperties();
+ String refProperty = "Library.Library";
+ String ref = properties.getProperty(refProperty);
+ if (ref.length() == 0)
+ {
+ System.err.println(appName + ": property `" + refProperty + "' not set");
+ return 1;
+ }
+
+ Ice.ObjectPrx base = communicator.stringToProxy(ref);
+ LibraryPrx library = LibraryPrxHelper.checkedCast(base);
+ if (library == null)
+ {
+ System.err.println(appName + ": invalid object reference");
+ return 1;
+ }
+
+ Parser parser = new Parser(communicator, library);
+ int status;
+
+ if (file == null)
+ {
+ status = parser.parse();
+ }
+ else
+ {
+ try
+ {
+ status = parser.parse(new java.io.BufferedReader(new java.io.FileReader(file)));
+ }
+ catch(java.io.IOException ex)
+ {
+ status = 1;
+ ex.printStackTrace();
+ }
+ }
+
+ return status;
+ }
+}
diff --git a/java/demo/Freeze/library/Scanner.java b/java/demo/Freeze/library/Scanner.java
new file mode 100644
index 00000000000..acde889b68d
--- /dev/null
+++ b/java/demo/Freeze/library/Scanner.java
@@ -0,0 +1,288 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class Scanner
+{
+ Scanner(Parser p)
+ {
+ _parser = p;
+ }
+
+ Token
+ nextToken()
+ {
+ String s = next();
+ if (s == null)
+ {
+ return null;
+ }
+
+ if (s.equals(";"))
+ {
+ return new Token(Token.TOK_SEMI);
+ }
+ else if (s.equals("help"))
+ {
+ return new Token(Token.TOK_HELP);
+ }
+ else if (s.equals("exit") || s.equals("quit"))
+ {
+ return new Token(Token.TOK_EXIT);
+ }
+ else if (s.equals("add"))
+ {
+ return new Token(Token.TOK_ADD_BOOK);
+ }
+ else if (s.equals("isbn"))
+ {
+ return new Token(Token.TOK_FIND_ISBN);
+ }
+ else if (s.equals("authors"))
+ {
+ return new Token(Token.TOK_FIND_AUTHORS);
+ }
+ else if (s.equals("next"))
+ {
+ return new Token(Token.TOK_NEXT_FOUND_BOOK);
+ }
+ else if (s.equals("current"))
+ {
+ return new Token(Token.TOK_PRINT_CURRENT);
+ }
+ else if (s.equals("rent"))
+ {
+ return new Token(Token.TOK_RENT_BOOK);
+ }
+ else if (s.equals("return"))
+ {
+ return new Token(Token.TOK_RETURN_BOOK);
+ }
+ else if (s.equals("remove"))
+ {
+ return new Token(Token.TOK_REMOVE_CURRENT);
+ }
+ else if (s.equals("size"))
+ {
+ return new Token(Token.TOK_SET_EVICTOR_SIZE);
+ }
+ else if (s.equals("shutdown"))
+ {
+ return new Token(Token.TOK_SHUTDOWN);
+ }
+ else
+ {
+ return new Token(Token.TOK_STRING, s);
+ }
+ }
+
+ static private class EndOfInput extends Exception
+ {
+ }
+
+ private char
+ get()
+ throws EndOfInput
+ {
+ //
+ // If there is an character in the unget buffer, return it.
+ //
+ if (_unget)
+ {
+ _unget = false;
+ return _ungetChar;
+ }
+
+ //
+ // No current buffer?
+ //
+ if (_buf == null)
+ {
+ _buf = _parser.getInput();
+ _pos = 0;
+ if (_buf == null)
+ {
+ throw new EndOfInput();
+ }
+ }
+
+ //
+ // At the end-of-buffer?
+ //
+ while (_pos >= _buf.length())
+ {
+ _buf = null;
+ _pos = 0;
+ return '\n';
+ }
+
+ return _buf.charAt(_pos++);
+ }
+
+ //
+ // unget only works with one character.
+ //
+ private void
+ unget(char c)
+ {
+ assert(!_unget);
+ _unget = true;
+ _ungetChar = c;
+ }
+
+ private String
+ next()
+ {
+ //
+ // Eat any whitespace.
+ //
+ char c;
+ try
+ {
+ do
+ {
+ c = get();
+ }
+ while (Character.isWhitespace(c) && c != '\n');
+ }
+ catch(EndOfInput ignore)
+ {
+ return null;
+ }
+
+ StringBuffer buf = new StringBuffer();
+
+ if (c == ';' || c == '\n')
+ {
+ buf.append(';');
+ }
+ else if (c == '\'')
+ {
+ try
+ {
+ while(true)
+ {
+ c = get();
+ if (c == '\'')
+ {
+ break;
+ }
+ else
+ {
+ buf.append(c);
+ }
+ }
+ }
+ catch(EndOfInput e)
+ {
+ _parser.warning("EOF in string");
+ }
+ }
+ else if (c == '\"')
+ {
+ try
+ {
+ while (true)
+ {
+ c = get();
+ if (c == '\"')
+ {
+ break;
+ }
+ else if (c == '\\')
+ {
+ try
+ {
+ char next = get();
+ switch (next)
+ {
+ case '\\':
+ case '"':
+ {
+ buf.append(next);
+ break;
+ }
+
+ case 'n':
+ {
+ buf.append('\n');
+ break;
+ }
+
+ case 'r':
+ {
+ buf.append('\r');
+ break;
+ }
+
+ case 't':
+ {
+ buf.append('\t');
+ break;
+ }
+
+ case 'f':
+ {
+ buf.append('\f');
+ break;
+ }
+
+ default:
+ {
+ buf.append(c);
+ unget(next);
+ }
+ }
+ }
+ catch(EndOfInput e)
+ {
+ buf.append(c);
+ }
+ }
+ else
+ {
+ buf.append(c);
+ }
+ }
+ }
+ catch(EndOfInput e)
+ {
+ _parser.warning("EOF in string");
+ }
+ }
+ else
+ {
+ //
+ // Otherwise it's a string.
+ //
+ try
+ {
+ do
+ {
+ buf.append(c);
+ c = get();
+ }
+ while (!Character.isWhitespace(c) && c != ';' && c != '\n');
+
+ unget(c);
+ }
+ catch(EndOfInput ignore)
+ {
+ }
+ }
+
+ return buf.toString();
+ }
+
+ private Parser _parser;
+ private boolean _unget = false;
+ private char _ungetChar;
+ private String _buf = null;
+ private int _pos;
+}
diff --git a/java/demo/Freeze/library/Server.java b/java/demo/Freeze/library/Server.java
new file mode 100644
index 00000000000..b892c7e7606
--- /dev/null
+++ b/java/demo/Freeze/library/Server.java
@@ -0,0 +1,108 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class LibraryServer extends Freeze.Application
+{
+ LibraryServer(String dbEnvName)
+ {
+ super(dbEnvName);
+ }
+
+ public int
+ runFreeze(String[] args, Freeze.DBEnvironment dbEnv)
+ {
+ Ice.Properties properties = communicator().getProperties();
+
+ Freeze.DB dbBooks = dbEnv.openDB("books", true);
+ Freeze.DB dbAuthors = dbEnv.openDB("authors", true);
+
+ //
+ // Create an Evictor for books.
+ //
+ Freeze.EvictorPersistenceMode mode;
+ int v = 0;
+ try
+ {
+ v = Integer.parseInt(properties.getProperty("Library.SaveAfterMutatingOperation"));
+ }
+ catch (NumberFormatException ex)
+ {
+ }
+
+ if(v != 0)
+ {
+ mode = Freeze.EvictorPersistenceMode.SaveAfterMutatingOperation;
+ }
+ else
+ {
+ mode = Freeze.EvictorPersistenceMode.SaveUponEviction;
+ }
+ Freeze.Evictor evictor = dbBooks.createEvictor(mode);
+
+ v = 0;
+ try
+ {
+ v = Integer.parseInt(properties.getProperty("Library.EvictorSize"));
+ }
+ catch (NumberFormatException ex)
+ {
+ }
+
+ if(v != 0)
+ {
+ evictor.setSize(v);
+ }
+
+ //
+ // Create an Object Adapter, use the Evictor as Servant
+ // Locator.
+ //
+ Ice.ObjectAdapter adapter = communicator().createObjectAdapter("LibraryAdapter");
+ adapter.addServantLocator(evictor, "book");
+
+ //
+ // Create the library, and add it to the Object Adapter.
+ //
+ LibraryI phoneBook = new LibraryI(adapter, dbAuthors, evictor);
+ adapter.add(phoneBook, Ice.Util.stringToIdentity("library"));
+
+ //
+ // Create and install a factory and initializer for books.
+ //
+ Ice.ObjectFactory bookFactory = new BookFactory(phoneBook, evictor);
+ communicator().addObjectFactory(bookFactory, "::Book");
+
+ //
+ // Everything ok, let's go.
+ //
+ adapter.activate();
+
+ //
+ // TODO:
+ //
+ //shutdownOnInterrupt();
+
+ communicator().waitForShutdown();
+
+ //ignoreInterrupt();
+
+ return 0;
+ }
+}
+
+public class Server
+{
+ static public void
+ main(String[] args)
+ {
+ LibraryServer app = new LibraryServer("db");
+ app.main("test.Freeze.library.Server", args, "config");
+ }
+}
diff --git a/java/demo/Freeze/library/Token.java b/java/demo/Freeze/library/Token.java
new file mode 100644
index 00000000000..6eb3ecfef28
--- /dev/null
+++ b/java/demo/Freeze/library/Token.java
@@ -0,0 +1,42 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class Token
+{
+ public static final int TOK_HELP = 0;
+ public static final int TOK_EXIT = 1;
+ public static final int TOK_ADD_BOOK = 2;
+ public static final int TOK_FIND_ISBN = 3;
+ public static final int TOK_FIND_AUTHORS = 4;
+ public static final int TOK_NEXT_FOUND_BOOK = 5;
+ public static final int TOK_PRINT_CURRENT = 6;
+ public static final int TOK_RENT_BOOK = 7;
+ public static final int TOK_RETURN_BOOK = 8;
+ public static final int TOK_REMOVE_CURRENT = 9;
+ public static final int TOK_SET_EVICTOR_SIZE = 10;
+ public static final int TOK_SHUTDOWN = 11;
+ public static final int TOK_STRING = 12;
+ public static final int TOK_SEMI = 13;
+
+ int type;
+ String value;
+
+ Token(int t)
+ {
+ type = t;
+ value = null;
+ }
+
+ Token(int t, String v)
+ {
+ type = t;
+ value = v;
+ }
+}
diff --git a/java/demo/Freeze/library/books b/java/demo/Freeze/library/books
new file mode 100644
index 00000000000..45464404470
--- /dev/null
+++ b/java/demo/Freeze/library/books
@@ -0,0 +1,32 @@
+add '096447963X' 'The Dragon Style (Learn to Play Go, Volume III)' 'Janice Kim, Jeong Soo-Hyun' ;
+add '0964479613' 'Learn to Play Go: A Master's Guide to the Ultimate Game (Volume I)' 'Janice Kim, Jeong Soo-Hyun' ;
+add '0964479621' 'The Way of the Moving Horse (Learn to Play Go, Volume II)' 'Janice Kim, Jeong Soo-Hyun' ;
+add '0964479648' 'Battle Strategies (Learn to Play Go Series)' 'Janice Kim, Jeong Soo-Hyun' ;
+add '0201889544' 'The C++ Programming Language' 'Bjarne Stroustrup' ;
+add '0201543303' 'The Design and Evolution of C++' 'Bjarne Stroustrup' ;
+add '0201700735' 'The C++ Programming Language Special Edition' 'Bjarne Stroustrup' ;
+add '0201379260' 'The C++ Standard Library : A Tutorial and Reference' 'Nicolai M. Josuttis' ;
+add '0201749629' 'Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library' 'Scott Meyers' ;
+add '0201924889' 'Effective C++: 50 Specific Ways to Improve Your Programs and Design' 'Scott Meyers' ;
+add '020163371X' 'More Effective C++: 35 New Ways to Improve Your Programs and Designs' 'Scott Meyers' ;
+add '0201615622' 'Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions' 'Herb Sutter' ;
+add '020170434X' 'More Exceptional C++' 'Herb Sutter' ;
+add '0201704315' 'Modern C++ Design: Generic Programming and Design Patterns Applied' 'Andrei Alexandrescu' ;
+add '0735616353' 'Microsoft Visual C++ .NET Deluxe Learning Edition' 'Microsoft Corporation' ;
+add '0735615497' 'Programming with Microsoft Visual C++ .NET, Sixth Edition (Core Reference)' 'George Shepherd, David Kruglinski' ;
+add '0735614229' 'Applied Microsoft .NET Framework Programming' 'Jeffrey Richter' ;
+add '0735613702' 'Programming Windows(r) with C# (Core Reference)' 'Charles Petzold' ;
+add '0201729555' 'C# Primer: A Practical Approach' 'Stanley B. Lippman' ;
+add '0201824701' 'C++ Primer' 'Stanley B. Lippman, Josee Lajoie' ;
+add '0201485184' 'Essential C++' 'Stanley B. Lippman' ;
+add '020170353X' 'Accelerated C++: Practical Programming by Example' 'Andrew Koenig, Barbara E. Moo' ;
+add '0201423391' 'Ruminations on C++ : A Decade of Programming Insight and Experience' 'Andrew Koenig, Barbara E. Moo' ;
+add '0201179288' 'C Traps and Pitfalls' 'Andrew Koenig' ;
+add '0131103628' 'The C Programming Language' 'Brian W. Kernighan, Dennis M. Ritchie' ;
+add '020161586X' 'The Practice of Programming' 'Brian W. Kernighan, Rob Pike' ;
+add '013937681X' 'UNIX Programming Environment, The' 'Brian W. Kernighan, Rob Pike' ;
+add '0201563177' 'Advanced Programming in the UNIX(R) Environment' 'W. Richard Stevens' ;
+add '0201633469' 'The Protocols (TCP/IP Illustrated, Volume 1)' 'W. Richard Stevens' ;
+add '0201634953' 'TCP for Transactions, HTTP, NNTP, and the UNIX(R) Domain Protocols (TCP/IP Illustrated, Volume 3)' 'W. Richard Stevens' ;
+add '013490012X' 'UNIX Network Programming, Volume 1: Networking APIs - Sockets and XTI' 'W. Richard Stevens' ;
+add '0130810819' 'UNIX Network Programming: Interprocess Communications' 'W. Richard Stevens' ;
diff --git a/java/demo/Freeze/library/build.xml b/java/demo/Freeze/library/build.xml
new file mode 100644
index 00000000000..64694a4015c
--- /dev/null
+++ b/java/demo/Freeze/library/build.xml
@@ -0,0 +1,62 @@
+<project name="demo_Ice_hello" default="all" basedir=".">
+
+ <!-- set global properties for this build -->
+ <property name="top.dir" value="../../.."/>
+ <property name="lib.dir" value="${top.dir}/lib"/>
+ <property name="slice.dir" value="${top.dir}/../ice/slice"/>
+ <property name="class.dir" value="classes"/>
+ <property name="generated.dir" value="generated"/>
+ <property name="tags.dir" value="${generated.dir}/.tags"/>
+
+ <!-- install slice2java task -->
+ <taskdef name="slice2java" classpath="${top.dir}/ant"
+ classname="Slice2JavaTask" />
+
+ <!-- install slice2freezej task -->
+ <taskdef name="slice2freezej" classpath="${top.dir}/ant"
+ classname="Slice2FreezeJTask" />
+
+ <target name="init">
+ <!-- Create the time stamp -->
+ <tstamp/>
+ </target>
+
+ <target name="generate" depends="init">
+ <!-- Create the output directory for generated code -->
+ <mkdir dir="${generated.dir}"/>
+ <mkdir dir="${tags.dir}"/>
+ <slice2java tagdir="${tags.dir}" outputdir="${generated.dir}">
+ <includepath>
+ <pathelement path="${slice.dir}" />
+ </includepath>
+ <fileset dir="." includes="Library.ice"/>
+ </slice2java>
+ <slice2freezej tagdir="${tags.dir}" outputdir="${generated.dir}">
+ <includepath>
+ <pathelement path="${slice.dir}" />
+ </includepath>
+ <fileset dir="${slice.dir}/Ice">
+ <include name="BuiltinSequences.ice" />
+ </fileset>
+ <fileset dir="." includes="Library.ice"/>
+ <dict name="StringIsbnSeqDict" key="string" value="Ice::StringSeq"/>
+ </slice2freezej>
+ </target>
+
+ <target name="compile" depends="generate">
+ <mkdir dir="${class.dir}"/>
+ <javac srcdir="${generated.dir}" destdir="${class.dir}"
+ source="1.4" classpath="${lib.dir}" debug="${debug}"/>
+ <javac srcdir="." destdir="${class.dir}" source="1.4"
+ classpath="${lib.dir}" excludes="generated/**" debug="${debug}"/>
+ </target>
+
+ <target name="all" depends="compile"/>
+
+ <target name="clean">
+ <delete dir="${tags.dir}"/>
+ <delete dir="${generated.dir}"/>
+ <delete dir="${class.dir}"/>
+ </target>
+
+</project>
diff --git a/java/demo/Freeze/library/config b/java/demo/Freeze/library/config
new file mode 100644
index 00000000000..b99c1206db4
--- /dev/null
+++ b/java/demo/Freeze/library/config
@@ -0,0 +1,9 @@
+Ice.Adapter.LibraryAdapter.Endpoints=tcp -p 10000
+Ice.ConnectionWarnings=1
+#Ice.Trace.Network=3
+#Ice.Trace.Protocol=1
+Library.Library=library:tcp -p 10000
+Library.EvictorSize=3
+#Library.SaveAfterMutatingOperation=1
+Freeze.Trace.DB=1
+Freeze.Trace.Evictor=2
diff --git a/java/demo/Freeze/library/db/.dummy b/java/demo/Freeze/library/db/.dummy
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/java/demo/Freeze/library/db/.dummy
diff --git a/java/demo/Freeze/phonebook/Collocated.java b/java/demo/Freeze/phonebook/Collocated.java
index 9ee0626b4de..fe428d80dcb 100644
--- a/java/demo/Freeze/phonebook/Collocated.java
+++ b/java/demo/Freeze/phonebook/Collocated.java
@@ -45,6 +45,7 @@ class PhoneBookCollocated extends Freeze.Application
evictor = dbContacts.createEvictor(Freeze.EvictorPersistenceMode.SaveUponEviction);
}
+ v = 0;
try
{
v = Integer.parseInt(properties.getProperty("PhoneBook.EvictorSize"));
diff --git a/java/demo/Freeze/phonebook/Parser.java b/java/demo/Freeze/phonebook/Parser.java
index bdf3f24c905..152d5a066b6 100644
--- a/java/demo/Freeze/phonebook/Parser.java
+++ b/java/demo/Freeze/phonebook/Parser.java
@@ -296,8 +296,11 @@ class Parser
public String
getInput()
{
- System.out.print(">>> ");
- System.out.flush();
+ if (_interactive)
+ {
+ System.out.print(">>> ");
+ System.out.flush();
+ }
try
{
@@ -316,6 +319,22 @@ class Parser
_current = 0;
_in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
+ _interactive = true;
+
+ Grammar g = new Grammar(this);
+ g.parse();
+
+ return 0;
+ }
+
+ public int
+ parse(java.io.BufferedReader in)
+ {
+ _foundContacts = new ContactPrx[0];
+ _current = 0;
+
+ _in = in;
+ _interactive = false;
Grammar g = new Grammar(this);
g.parse();
@@ -330,4 +349,5 @@ class Parser
private PhoneBookPrx _phoneBook;
private java.io.BufferedReader _in;
+ private boolean _interactive;
}
diff --git a/java/demo/Freeze/phonebook/PhoneBookI.java b/java/demo/Freeze/phonebook/PhoneBookI.java
index 7a3673d1064..3abb1b76d66 100644
--- a/java/demo/Freeze/phonebook/PhoneBookI.java
+++ b/java/demo/Freeze/phonebook/PhoneBookI.java
@@ -303,7 +303,6 @@ class PhoneBookI extends _PhoneBookDisp
}
private Ice.ObjectAdapter _adapter;
- private Freeze.DB _db;
private Freeze.Evictor _evictor;
private NameIdentitiesDict _nameIdentitiesDict;
}
diff --git a/java/demo/Freeze/phonebook/RunParser.java b/java/demo/Freeze/phonebook/RunParser.java
index 80b4842fb81..d827af7a610 100644
--- a/java/demo/Freeze/phonebook/RunParser.java
+++ b/java/demo/Freeze/phonebook/RunParser.java
@@ -23,10 +23,9 @@ class RunParser
static int
runParser(String appName, String[] args, Ice.Communicator communicator)
{
- String commands;
- boolean debug = false;
-
- int idx = 1;
+ String file = null;
+ int idx = 0;
+
while (idx < args.length)
{
if (args[idx].equals("-h") | args[idx].equals("--help"))
@@ -49,6 +48,16 @@ class RunParser
}
else
{
+ if (file == null)
+ {
+ file = args[idx];
+ }
+ else
+ {
+ System.err.println(appName + ": only one file is supported.");
+ usage(appName);
+ return 1;
+ }
++idx;
}
}
@@ -71,12 +80,23 @@ class RunParser
}
Parser parser = new Parser(communicator, phoneBook);
- int status = 0;
+ int status;
- int parseStatus = parser.parse();
- if (parseStatus != 0)
+ if (file == null)
+ {
+ status = parser.parse();
+ }
+ else
{
- status = 1;
+ try
+ {
+ status = parser.parse(new java.io.BufferedReader(new java.io.FileReader(file)));
+ }
+ catch(java.io.IOException ex)
+ {
+ status = 1;
+ ex.printStackTrace();
+ }
}
return status;
diff --git a/java/demo/Freeze/phonebook/Server.java b/java/demo/Freeze/phonebook/Server.java
index 06bd41783df..8091e0b6f3b 100644
--- a/java/demo/Freeze/phonebook/Server.java
+++ b/java/demo/Freeze/phonebook/Server.java
@@ -45,6 +45,7 @@ class PhoneBookServer extends Freeze.Application
evictor = dbContacts.createEvictor(Freeze.EvictorPersistenceMode.SaveUponEviction);
}
+ v = 0;
try
{
v = Integer.parseInt(properties.getProperty("PhoneBook.EvictorSize"));
diff --git a/java/src/Ice/Application.java b/java/src/Ice/Application.java
index 4056e372186..30072e56b7c 100644
--- a/java/src/Ice/Application.java
+++ b/java/src/Ice/Application.java
@@ -47,17 +47,18 @@ public abstract class Application
try
{
+ StringSeqHolder argHolder = new StringSeqHolder(args);
if (configFile != null)
{
Properties properties =
- Util.createPropertiesFromFile(args, configFile);
+ Util.createPropertiesFromFile(argHolder, configFile);
_communicator = Util.initializeWithProperties(properties);
}
else
{
- _communicator = Util.initialize(args);
+ _communicator = Util.initialize(argHolder);
}
- status = run(args);
+ status = run(argHolder.value);
}
catch(LocalException ex)
{