diff options
author | Matthew Newhook <matthew@zeroc.com> | 2008-08-18 14:11:56 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2008-08-18 14:11:56 -0230 |
commit | 81092d2fedc964062ac30f03cad4bb6469aafa1b (patch) | |
tree | a442196a518fae1a1eaa2ff9185142a73460807f /java/demo/Database/library/SessionI.java | |
parent | remove QueryActiveException. (diff) | |
download | ice-81092d2fedc964062ac30f03cad4bb6469aafa1b.tar.bz2 ice-81092d2fedc964062ac30f03cad4bb6469aafa1b.tar.xz ice-81092d2fedc964062ac30f03cad4bb6469aafa1b.zip |
SQL setup is now more automatic.
Diffstat (limited to 'java/demo/Database/library/SessionI.java')
-rw-r--r-- | java/demo/Database/library/SessionI.java | 123 |
1 files changed, 102 insertions, 21 deletions
diff --git a/java/demo/Database/library/SessionI.java b/java/demo/Database/library/SessionI.java index 610cb8e4201..5b94172b2c0 100644 --- a/java/demo/Database/library/SessionI.java +++ b/java/demo/Database/library/SessionI.java @@ -11,14 +11,13 @@ import Demo.*; class SessionI extends _SessionDisp { - public - SessionI(ConnectionPool pool, Ice.Logger logger, Ice.ObjectAdapter adapter) + static public SessionI + getSession(Ice.Identity id) { - _pool = pool; - _logger = logger; - _timestamp = System.currentTimeMillis(); - _libraryImpl = new LibraryI(_logger, _pool); - _library = LibraryPrxHelper.uncheckedCast(adapter.addWithUUID(_libraryImpl)); + synchronized(_sessions) + { + return _sessions.get(id); + } } synchronized public LibraryPrx @@ -50,21 +49,30 @@ class SessionI extends _SessionDisp } _destroyed = true; - _logger.trace("Session", "The session " + c.id + " is now destroyed."); - _libraryImpl.destroy(); - try + _logger.trace("Session", "session " + c.id + " is now destroyed."); + + // Remove the session from the sessions map. + synchronized(_sessions) { - if(c != null) - { - c.adapter.remove(c.id); - c.adapter.remove(_library.ice_getIdentity()); - } + Object o = _sessions.remove(_library.ice_getIdentity()); + assert o != null; } - catch(Ice.ObjectAdapterDeactivatedException e) + + java.util.Iterator<QueryProxyPair> p = _queries.iterator(); + while(p.hasNext()) { - // This method is called on shutdown of the server, in - // which case this exception is expected. + try + { + p.next().proxy.destroy(); + } + catch(Ice.ObjectNotExistException e) + { + // Ignore, it could have already been destroyed. + } } + + // This method is never called on shutdown of the server. + c.adapter.remove(c.id); } // Called on application shutdown. @@ -74,7 +82,13 @@ class SessionI extends _SessionDisp if(!_destroyed) { _destroyed = true; - _libraryImpl.shutdown(); + + // Shutdown each of the associated query objects. + java.util.Iterator<QueryProxyPair> p = _queries.iterator(); + while(p.hasNext()) + { + p.next().impl.shutdown(); + } } } @@ -88,10 +102,77 @@ class SessionI extends _SessionDisp return _timestamp; } + synchronized public void + add(BookQueryResultPrx proxy, BookQueryResultI impl) + { + // If the session has been destroyed, then destroy the book + // result, and raise an ObjectNotExistException. + if(_destroyed) + { + proxy.destroy(); + throw new Ice.ObjectNotExistException(); + } + _queries.add(new QueryProxyPair(proxy, impl)); + } + + synchronized public void + reapQueries() + { + if(_destroyed) + { + throw new Ice.ObjectNotExistException(); + } + + java.util.Iterator<QueryProxyPair> p = _queries.iterator(); + while(p.hasNext()) + { + QueryProxyPair pair = p.next(); + try + { + pair.proxy.ice_ping(); + } + catch(Ice.ObjectNotExistException e) + { + p.remove(); + } + } + } + + SessionI(Ice.Logger logger, Ice.ObjectAdapter adapter) + { + _logger = logger; + _timestamp = System.currentTimeMillis(); + + Ice.Identity id = new Ice.Identity(); + id.category = "library"; + id.name = Ice.Util.generateUUID(); + _library = LibraryPrxHelper.uncheckedCast(adapter.createProxy(id)); + + // Add the library to the sessions map. + synchronized(_sessions) + { + _sessions.put(_library.ice_getIdentity(), this); + } + } + + static class QueryProxyPair + { + QueryProxyPair(BookQueryResultPrx p, BookQueryResultI i) + { + proxy = p; + impl = i; + } + + BookQueryResultPrx proxy; + BookQueryResultI impl; + }; + + private static java.util.Map<Ice.Identity, SessionI> _sessions = + new java.util.HashMap<Ice.Identity, SessionI>(); + + private java.util.List<QueryProxyPair> _queries = new java.util.LinkedList<QueryProxyPair>(); private Ice.Logger _logger; - private ConnectionPool _pool; private boolean _destroyed = false; // true if destroy() was called, false otherwise. private long _timestamp; // The last time the session was refreshed. private LibraryPrx _library; - private LibraryI _libraryImpl; } |