summaryrefslogtreecommitdiff
path: root/java/demo/book/map_filesystem/Server.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/demo/book/map_filesystem/Server.java')
-rw-r--r--java/demo/book/map_filesystem/Server.java79
1 files changed, 33 insertions, 46 deletions
diff --git a/java/demo/book/map_filesystem/Server.java b/java/demo/book/map_filesystem/Server.java
index 6fb5271bf44..da9ce6e8617 100644
--- a/java/demo/book/map_filesystem/Server.java
+++ b/java/demo/book/map_filesystem/Server.java
@@ -8,6 +8,7 @@
// **********************************************************************
import Filesystem.*;
+import FilesystemDB.*;
public class Server extends Ice.Application
{
@@ -20,56 +21,42 @@ public class Server extends Ice.Application
public int
run(String[] args)
{
- // Install object factories
+ // Create an object adapter
//
- communicator().addObjectFactory(PersistentFile.ice_factory(), PersistentFile.ice_staticId());
- communicator().addObjectFactory(PersistentDirectory.ice_factory(), PersistentDirectory.ice_staticId());
+ Ice.ObjectAdapter adapter = communicator().createObjectAdapter("MapFilesystem");
- // Create an object adapter (stored in the _adapter static member)
- //
- Ice.ObjectAdapter adapter =
- communicator().createObjectAdapter("MapFilesystem");
-
- // Create a Freeze connection and the map
- //
- Freeze.Connection connection = Freeze.Util.createConnection(communicator(), _envName);
- IdentityNodeMap persistentMap = new IdentityNodeMap(connection, "mapfs", true);
-
- // Set static members
- //
- FileI._map = persistentMap;
- DirectoryI._map = persistentMap;
- DirectoryI._adapter = adapter;
-
- // Find the persistent node for the root directory, or create it if not found
- //
- Ice.Identity rootId = Ice.Util.stringToIdentity("RootDir");
- PersistentDirectory pRoot = (PersistentDirectory)persistentMap.get(rootId);
- if(pRoot == null)
+ Freeze.Connection connection = null;
+ try
{
- pRoot = new PersistentDirectory();
- pRoot.name = "/";
- pRoot.nodes = new java.util.HashMap<String, NodeDesc>();
- persistentMap.put(rootId, pRoot);
+ // Open a connection to the files and directories
+ // database. This should remain open for the duration of the
+ // application for performance reasons.
+ //
+ connection = Freeze.Util.createConnection(communicator(), _envName);
+ IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, FileI.filesDB(), true);
+ IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(
+ connection, DirectoryI.directoriesDB(), true);
+
+ // Add default servants for the file and directory.
+ //
+ adapter.addDefaultServant(new FileI(communicator(), _envName), "file");
+ adapter.addDefaultServant(new DirectoryI(communicator(), _envName), "");
+
+ // Ready to accept requests now
+ //
+ adapter.activate();
+
+ // Wait until we are done
+ //
+ communicator().waitForShutdown();
}
-
- // Create the root directory (with name "/" and no parent)
- //
- DirectoryI root = new DirectoryI(rootId, pRoot, null);
- adapter.add(root, rootId);
-
- // Ready to accept requests now
- //
- adapter.activate();
-
- // Wait until we are done
- //
- communicator().waitForShutdown();
-
- // Clean up
- //
- connection.close();
-
+ finally
+ {
+ // Close the connection gracefully.
+ //
+ connection.close();
+ }
+
return 0;
}