diff options
-rw-r--r-- | cpp/demo/book/map_filesystem/.gitignore | 2 | ||||
-rw-r--r-- | cpp/demo/book/map_filesystem/FilesystemI.cpp | 223 | ||||
-rw-r--r-- | java/demo/book/map_filesystem/DirectoryI.java | 337 | ||||
-rw-r--r-- | java/demo/book/map_filesystem/FileI.java | 191 |
4 files changed, 376 insertions, 377 deletions
diff --git a/cpp/demo/book/map_filesystem/.gitignore b/cpp/demo/book/map_filesystem/.gitignore index ed77790e489..ff2ee807d48 100644 --- a/cpp/demo/book/map_filesystem/.gitignore +++ b/cpp/demo/book/map_filesystem/.gitignore @@ -5,6 +5,8 @@ client server Filesystem.cpp Filesystem.h +FilesystemDB.cpp +FilesystemDB.h IdentityFileEntryMap.cpp IdentityFileEntryMap.h IdentityDirectoryEntryMap.cpp diff --git a/cpp/demo/book/map_filesystem/FilesystemI.cpp b/cpp/demo/book/map_filesystem/FilesystemI.cpp index 4d382253390..f37dcf8fdd7 100644 --- a/cpp/demo/book/map_filesystem/FilesystemI.cpp +++ b/cpp/demo/book/map_filesystem/FilesystemI.cpp @@ -30,27 +30,26 @@ FileI::name(const Ice::Current& c) for(;;) { - try - { + try + { IdentityFileEntryMap::iterator p = fileDB.find(c.id); if(p == fileDB.end()) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } return p->second.name; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } - Lines FileI::read(const Ice::Current& c) { @@ -59,23 +58,23 @@ FileI::read(const Ice::Current& c) for(;;) { - try - { + try + { IdentityFileEntryMap::iterator p = fileDB.find(c.id); if(p == fileDB.end()) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } return p->second.text; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } @@ -87,8 +86,8 @@ FileI::write(const Filesystem::Lines& text, const Ice::Current& c) for(;;) { - try - { + try + { IdentityFileEntryMap::iterator p = fileDB.find(c.id); if(p == fileDB.end()) { @@ -98,15 +97,15 @@ FileI::write(const Filesystem::Lines& text, const Ice::Current& c) entry.text = text; p.set(entry); break; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } @@ -119,8 +118,8 @@ FileI::destroy(const Ice::Current& c) for(;;) { - try - { + try + { // The transaction is necessary since we are altering two // records in one atomic action. // @@ -146,15 +145,15 @@ FileI::destroy(const Ice::Current& c) fileDB.erase(p); txn.commit(); break; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } @@ -178,7 +177,7 @@ DirectoryI::DirectoryI(const Ice::CommunicatorPtr& communicator, const string& e { const Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); IdentityDirectoryEntryMap dirDB(connection, directoriesDB()); - + // Create the record for the root directory if necessary. // for(;;) @@ -215,23 +214,23 @@ DirectoryI::name(const Ice::Current& c) for(;;) { - try - { + try + { IdentityDirectoryEntryMap::iterator p = directoryDB.find(c.id); if(p == directoryDB.end()) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } return p->second.name; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } @@ -243,8 +242,8 @@ DirectoryI::list(const Ice::Current& c) for(;;) { - try - { + try + { IdentityDirectoryEntryMap::iterator p = directoryDB.find(c.id); if(p == directoryDB.end()) { @@ -257,15 +256,15 @@ DirectoryI::list(const Ice::Current& c) result.push_back(q->second); } return result; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } @@ -277,8 +276,8 @@ DirectoryI::find(const string& name, const Ice::Current& c) for(;;) { - try - { + try + { IdentityDirectoryEntryMap::iterator p = directoryDB.find(c.id); if(p == directoryDB.end()) { @@ -290,15 +289,15 @@ DirectoryI::find(const string& name, const Ice::Current& c) throw NoSuchName(name); } return q->second; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } @@ -310,8 +309,8 @@ DirectoryI::createDirectory(const string& name, const Ice::Current& c) for(;;) { - try - { + try + { // The transaction is necessary since we are altering two // records in one atomic action. // @@ -349,15 +348,15 @@ DirectoryI::createDirectory(const string& name, const Ice::Current& c) txn.commit(); return proxy; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } @@ -370,8 +369,8 @@ DirectoryI::createFile(const string& name, const Ice::Current& c) for(;;) { - try - { + try + { // The transaction is necessary since we are altering two // records in one atomic action. // @@ -410,15 +409,15 @@ DirectoryI::createFile(const string& name, const Ice::Current& c) txn.commit(); return proxy; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } @@ -430,8 +429,8 @@ DirectoryI::destroy(const Ice::Current& c) for(;;) { - try - { + try + { // The transaction is necessary since we are altering two // records in one atomic action. // @@ -464,15 +463,15 @@ DirectoryI::destroy(const Ice::Current& c) directoryDB.erase(p); txn.commit(); break; - } - catch(const Freeze::DeadlockException&) - { - continue; - } - catch(const Freeze::DatabaseException& ex) - { - halt(ex); - } + } + catch(const Freeze::DeadlockException&) + { + continue; + } + catch(const Freeze::DatabaseException& ex) + { + halt(ex); + } } } diff --git a/java/demo/book/map_filesystem/DirectoryI.java b/java/demo/book/map_filesystem/DirectoryI.java index 8b688a7baf0..0c54e9faf0b 100644 --- a/java/demo/book/map_filesystem/DirectoryI.java +++ b/java/demo/book/map_filesystem/DirectoryI.java @@ -18,89 +18,89 @@ public class DirectoryI extends _DirectoryDisp _communicator = communicator; _envName = envName; - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, directoriesDB()); // Create the record for the root directory if necessary. // - for(;;) - { - try - { + for(;;) + { + try + { Ice.Identity rootId = new Ice.Identity("RootDir", ""); - DirectoryEntry entry = (DirectoryEntry)dirDB.get(rootId); + DirectoryEntry entry = dirDB.get(rootId); if(entry == null) { dirDB.put(rootId, new DirectoryEntry("/", new Ice.Identity("", ""), null)); } - break; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } - } - } - finally - { + break; + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } + } + } + finally + { connection.close(); - } + } } public String name(Ice.Current c) { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, directoriesDB()); - for(;;) - { - try - { - DirectoryEntry entry = (DirectoryEntry)dirDB.get(c.id); + for(;;) + { + try + { + DirectoryEntry entry = dirDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); } return entry.name; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } - } - } - finally - { + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } + } + } + finally + { connection.close(); - } + } } public NodeDesc[] list(Ice.Current c) { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, directoriesDB()); - for(;;) - { - try - { - DirectoryEntry entry = (DirectoryEntry)dirDB.get(c.id); + for(;;) + { + try + { + DirectoryEntry entry = dirDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); @@ -112,37 +112,37 @@ public class DirectoryI extends _DirectoryDisp result[i] = p.next(); } return result; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } - } - } - finally - { + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } + } + } + finally + { connection.close(); - } + } } public NodeDesc find(String name, Ice.Current c) throws NoSuchName { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, directoriesDB()); - for(;;) - { - try - { - DirectoryEntry entry = (DirectoryEntry)dirDB.get(c.id); + for(;;) + { + try + { + DirectoryEntry entry = dirDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); @@ -153,43 +153,43 @@ public class DirectoryI extends _DirectoryDisp throw new NoSuchName(name); } return nd; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } - } - } - finally - { + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } + } + } + finally + { connection.close(); - } + } } public FilePrx createFile(String name, Ice.Current c) throws NameInUse { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, FileI.filesDB()); IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, directoriesDB()); - for(;;) - { + for(;;) + { // The transaction is necessary since we are altering // two records in one atomic action. // Freeze.Transaction txn = null; - try - { + try + { txn = connection.beginTransaction(); - DirectoryEntry entry = (DirectoryEntry)dirDB.get(c.id); + DirectoryEntry entry = dirDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); @@ -212,15 +212,15 @@ public class DirectoryI extends _DirectoryDisp txn = null; return proxy; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } finally { if(txn != null) @@ -228,33 +228,33 @@ public class DirectoryI extends _DirectoryDisp txn.rollback(); } } - } - } - finally - { + } + } + finally + { connection.close(); - } + } } public DirectoryPrx createDirectory(String name, Ice.Current c) throws NameInUse { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, directoriesDB()); - for(;;) - { + for(;;) + { // The transaction is necessary since we are altering // two records in one atomic action. // Freeze.Transaction txn = null; - try - { + try + { txn = connection.beginTransaction(); - DirectoryEntry entry = (DirectoryEntry)dirDB.get(c.id); + DirectoryEntry entry = dirDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); @@ -277,15 +277,15 @@ public class DirectoryI extends _DirectoryDisp txn = null; return proxy; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } finally { if(txn != null) @@ -293,33 +293,33 @@ public class DirectoryI extends _DirectoryDisp txn.rollback(); } } - } - } - finally - { + } + } + finally + { connection.close(); - } + } } public void destroy(Ice.Current c) throws PermissionDenied { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, directoriesDB()); - for(;;) - { + for(;;) + { // The transaction is necessary since we are altering // two records in one atomic action. // Freeze.Transaction txn = null; - try - { + try + { txn = connection.beginTransaction(); - DirectoryEntry entry = (DirectoryEntry)dirDB.get(c.id); + DirectoryEntry entry = dirDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); @@ -333,7 +333,7 @@ public class DirectoryI extends _DirectoryDisp throw new PermissionDenied("Cannot destroy non-empty directory"); } - DirectoryEntry dirEntry = (DirectoryEntry)dirDB.get(entry.parent); + DirectoryEntry dirEntry = dirDB.get(entry.parent); if(dirEntry == null) { halt(new Freeze.DatabaseException("consistency error: directory without parent")); @@ -343,19 +343,19 @@ public class DirectoryI extends _DirectoryDisp dirDB.put(entry.parent, dirEntry); dirDB.remove(c.id); - + txn.commit(); txn = null; break; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } finally { if(txn != null) @@ -363,30 +363,29 @@ public class DirectoryI extends _DirectoryDisp txn.rollback(); } } - } - } - finally - { + } + } + finally + { connection.close(); - } + } } private void halt(Freeze.DatabaseException e) { - // - // If this fails its very bad news. We log the error and - // then kill the server. - // - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - e.printStackTrace(pw); - pw.flush(); - _communicator.getLogger().error("fatal database error\n" + sw.toString() + - "\n*** Halting JVM ***"); - Runtime.getRuntime().halt(1); + // + // If this is called it's very bad news. We log the error and + // then kill the server. + // + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + e.printStackTrace(pw); + pw.flush(); + _communicator.getLogger().error("fatal database error\n" + sw.toString() + "\n*** Halting JVM ***"); + Runtime.getRuntime().halt(1); } - + public static String directoriesDB() { diff --git a/java/demo/book/map_filesystem/FileI.java b/java/demo/book/map_filesystem/FileI.java index e8d09b4a959..bd7fabe10ba 100644 --- a/java/demo/book/map_filesystem/FileI.java +++ b/java/demo/book/map_filesystem/FileI.java @@ -22,87 +22,87 @@ public class FileI extends _FileDisp public String name(Ice.Current c) { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, filesDB()); - for(;;) - { - try - { - FileEntry entry = (FileEntry)fileDB.get(c.id); + for(;;) + { + try + { + FileEntry entry = fileDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); } return entry.name; - } - catch(Freeze.DeadlockException ex) - { - continue; - } + } + catch(Freeze.DeadlockException ex) + { + continue; + } catch(Freeze.DatabaseException ex) { halt(ex); } - } - } - finally - { + } + } + finally + { connection.close(); - } + } } public String[] read(Ice.Current c) { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, filesDB()); - for(;;) - { - try - { - FileEntry entry = (FileEntry)fileDB.get(c.id); + for(;;) + { + try + { + FileEntry entry = fileDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); } return entry.text; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } - } - } - finally - { + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } + } + } + finally + { connection.close(); - } + } } public void write(String[] text, Ice.Current c) throws GenericError { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, filesDB()); - for(;;) - { - try - { - FileEntry entry = (FileEntry)fileDB.get(c.id); + for(;;) + { + try + { + FileEntry entry = fileDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); @@ -110,43 +110,43 @@ public class FileI extends _FileDisp entry.text = text; fileDB.put(c.id, entry); break; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } - } - } - finally - { + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } + } + } + finally + { connection.close(); - } + } } public void destroy(Ice.Current c) throws PermissionDenied { - Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); - try - { + Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName); + try + { IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, filesDB()); IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, DirectoryI.directoriesDB()); - for(;;) - { + for(;;) + { Freeze.Transaction txn = null; - try - { + try + { // The transaction is necessary since we are // altering two records in one atomic action. // txn = connection.beginTransaction(); - FileEntry entry = (FileEntry)fileDB.get(c.id); + FileEntry entry = fileDB.get(c.id); if(entry == null) { throw new Ice.ObjectNotExistException(); @@ -162,19 +162,19 @@ public class FileI extends _FileDisp dirDB.put(entry.parent, dirEntry); fileDB.remove(c.id); - + txn.commit(); txn = null; break; - } - catch(Freeze.DeadlockException ex) - { - continue; - } - catch(Freeze.DatabaseException ex) - { - halt(ex); - } + } + catch(Freeze.DeadlockException ex) + { + continue; + } + catch(Freeze.DatabaseException ex) + { + halt(ex); + } finally { if(txn != null) @@ -182,12 +182,12 @@ public class FileI extends _FileDisp txn.rollback(); } } - } - } - finally - { + } + } + finally + { connection.close(); - } + } } public static String @@ -199,17 +199,16 @@ public class FileI extends _FileDisp private void halt(Freeze.DatabaseException e) { - // - // If this fails its very bad news. We log the error and - // then kill the server. - // - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - e.printStackTrace(pw); - pw.flush(); - _communicator.getLogger().error("fatal database error\n" + sw.toString() + - "\n*** Halting JVM ***"); - Runtime.getRuntime().halt(1); + // + // If this is called it's very bad news. We log the error and + // then kill the server. + // + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + e.printStackTrace(pw); + pw.flush(); + _communicator.getLogger().error("fatal database error\n" + sw.toString() + "\n*** Halting JVM ***"); + Runtime.getRuntime().halt(1); } private Ice.Communicator _communicator; |