diff options
author | Mark Spruiell <mes@zeroc.com> | 2010-04-05 13:48:54 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2010-04-05 13:48:54 -0700 |
commit | 0a847eb2add5d58da1f37bcfef636fb17ec6c7f8 (patch) | |
tree | e3eff74295d166383aac139e5c5d2cad6013c7b7 | |
parent | another OpenSSL fix (diff) | |
download | ice-0a847eb2add5d58da1f37bcfef636fb17ec6c7f8.tar.bz2 ice-0a847eb2add5d58da1f37bcfef636fb17ec6c7f8.tar.xz ice-0a847eb2add5d58da1f37bcfef636fb17ec6c7f8.zip |
bug 4718 - Glacier2 helpers need to trap CommunicatorDestroyedException
-rw-r--r-- | cpp/src/Glacier2Lib/Application.cpp | 13 | ||||
-rw-r--r-- | cs/src/Glacier2/Application.cs | 113 | ||||
-rw-r--r-- | cs/src/Glacier2/SessionCallback.cs | 32 | ||||
-rw-r--r-- | cs/src/Glacier2/SessionFactoryHelper.cs | 70 | ||||
-rw-r--r-- | cs/src/Glacier2/SessionHelper.cs | 79 | ||||
-rw-r--r-- | cs/src/Ice/PluginManagerI.cs | 2 | ||||
-rw-r--r-- | java/src/Glacier2/Application.java | 107 | ||||
-rw-r--r-- | java/src/Glacier2/SessionCallback.java | 12 | ||||
-rw-r--r-- | java/src/Glacier2/SessionFactoryHelper.java | 15 | ||||
-rw-r--r-- | java/src/Glacier2/SessionHelper.java | 61 |
10 files changed, 316 insertions, 188 deletions
diff --git a/cpp/src/Glacier2Lib/Application.cpp b/cpp/src/Glacier2Lib/Application.cpp index befb98bc0ff..2f587cd7a98 100644 --- a/cpp/src/Glacier2Lib/Application.cpp +++ b/cpp/src/Glacier2Lib/Application.cpp @@ -83,12 +83,23 @@ public: IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); while(true) { - _router->refreshSession_async(new AMI_Router_refreshSessionI(_app, this)); + try + { + _router->refreshSession_async(new AMI_Router_refreshSessionI(_app, this)); + } + catch(const Ice::CommunicatorDestroyedException&) + { + // + // AMI requests can raise CommunicatorDestroyedException directly. + // + break; + } if(!_done) { _monitor.timedWait(IceUtil::Time::seconds((int)_period)); } + if(_done) { break; diff --git a/cs/src/Glacier2/Application.cs b/cs/src/Glacier2/Application.cs index 4bbfbe3b1aa..0aa43a03704 100644 --- a/cs/src/Glacier2/Application.cs +++ b/cs/src/Glacier2/Application.cs @@ -15,7 +15,7 @@ using System.Threading; namespace Glacier2 { -/// <sumary> +/// <summary> /// Utility base class that makes it easy to to correctly initialize and finalize /// the Ice run time, as well as handle signals. Unless the application specifies /// a logger, Application installs a per-process logger that logs to the standard @@ -24,29 +24,29 @@ namespace Glacier2 /// Applications must create a derived class that implements the {@link #run} method. /// /// A program can contain only one instance of this class. -/// </sumary> +/// </summary> public abstract class Application : Ice.Application { - /// <sumary> + /// <summary> /// This exception is raised if the session should be restarted. - /// </sumary> + /// </summary> public class RestartSessionException : System.Exception { } - /// <sumary> + /// <summary> /// Initializes an instance that calls Communicator.shutdown if /// a signal is received. - /// </sumary> + /// </summary> public Application() { } - /// <sumary> + /// <summary> /// Initializes an instance that handles signals according to the signal /// policy. - /// </sumary> + /// </summary> /// <param name="signalPolicy">@param signalPolicy Determines how to /// respond to signals.</param> public @@ -54,17 +54,16 @@ public abstract class Application : Ice.Application { } - - /// <sumary> + /// <summary> /// Called once the communicator has been initialized and the Glacier2 session /// has been established. A derived class must implement <code>runWithSession</code>, /// which is the application's starting method. - /// </sumary> + /// </summary> /// <param name="args"> The argument vector for the application. Application /// scans the argument vector passed to <code>main</code> for options that are /// specific to the Ice run time and removes them; therefore, the vector passed - /// to <code>run</code> is free from Ice-related options and contains only options - /// and arguments that are application-specific.</param> + /// to <code>runWithSession</code> is free from Ice-related options and contains + /// only options and arguments that are application-specific.</param> /// /// <returns> The runWithSession method should return zero for successful /// termination, and non-zero otherwise. Application.main returns the @@ -73,22 +72,24 @@ public abstract class Application : Ice.Application public abstract int runWithSession(string[] args); - /// <sumary> + /// <summary> /// Run should not be overridden for Glacier2.Application. Instead /// runWithSession should be used. - /// </sumary> + /// </summary> public override int run(string[] args) { + // // This shouldn't be called. + // Debug.Assert(false); return 0; } - /// <sumary> + /// <summary> /// Called to restart the application's Glacier2 session. This /// method never returns. - /// </sumary> + /// </summary> /// <returns>throws RestartSessionException This exception is /// always thrown.</returns> /// @@ -98,28 +99,28 @@ public abstract class Application : Ice.Application throw new RestartSessionException(); } - /// <sumary> + /// <summary> /// Creates a new Glacier2 session. A call to createSession always /// precedes a call to runWithSession. If Ice.LocalException is thrown /// from this method, the application is terminated. - /// </sumary> + /// </summary> /// <returns> The Glacier2 session.</returns> public abstract Glacier2.SessionPrx createSession(); - /// <sumary> + /// <summary> /// Called when the base class detects that the session has been destroyed. /// A subclass can override this method to take action after the loss of /// connectivity with the Glacier2 router. - /// </sumary> + /// </summary> public virtual void sessionDestroyed() { } - /// <sumary> - /// Returns the Glacier2 router proxy - /// </sumary> + /// <summary> + /// Returns the Glacier2 router proxy. + /// </summary> /// <returns>The router proxy.</returns> public static Glacier2.RouterPrx router() @@ -127,9 +128,9 @@ public abstract class Application : Ice.Application return _router; } - /// <sumary> - /// Returns the Glacier2 session proxy - /// </sumary> + /// <summary> + /// Returns the Glacier2 session proxy. + /// </summary> /// <returns>The session proxy.</returns> public static Glacier2.SessionPrx session() @@ -137,12 +138,12 @@ public abstract class Application : Ice.Application return _session; } - /// <sumary> + /// <summary> /// Returns the category to be used in the identities of all of the client's /// callback objects. Clients must use this category for the router to /// forward callback requests to the intended client. /// Throws SessionNotExistException if no session exists. - /// </sumary> + /// </summary> /// <returns>The category.</returns> public string categoryForClient() @@ -154,10 +155,10 @@ public abstract class Application : Ice.Application return router().getCategoryForClient(); } - /// <sumary> + /// <summary> /// Create a new Ice identity for callback objects with the given /// identity name field. - /// </sumary> + /// </summary> /// <returns>The identity.</returns> public Ice.Identity createCallbackIdentity(string name) @@ -165,9 +166,9 @@ public abstract class Application : Ice.Application return new Ice.Identity(name, categoryForClient()); } - /// <sumary> + /// <summary> /// Adds a servant to the callback object adapter's Active Servant Map with a UUID. - /// </sumary> + /// </summary> /// <param name="servant">The servant to add.</param> /// <returns>The proxy for the servant.</returns> public Ice.ObjectPrx @@ -176,9 +177,9 @@ public abstract class Application : Ice.Application return objectAdapter().add(servant, createCallbackIdentity(Guid.NewGuid().ToString())); } - /// <sumary> - /// Creates an object adapter for callback objects. - /// </sumary> + /// <summary> + /// Returns an object adapter for callback objects, creating it if necessary. + /// </summary> /// <returns>The object adapter.</returns> public Ice.ObjectAdapter objectAdapter() @@ -243,7 +244,18 @@ public abstract class Application : Ice.Application { while(!_done) { - _router.refreshSession_async(new AMI_Router_refreshSessionI(_app, this)); + try + { + _router.refreshSession_async(new AMI_Router_refreshSessionI(_app, this)); + } + catch(Ice.CommunicatorDestroyedException) + { + // + // AMI requests can raise CommunicatorDestroyedException directly. + // + break; + } + if(!_done) { Monitor.Wait(this, (int)_period); @@ -274,7 +286,9 @@ public abstract class Application : Ice.Application protected override int doMain(string[] originArgs, Ice.InitializationData initData) { + // // Set the default properties for all Glacier2 applications. + // initData.properties.setProperty("Ice.ACM.Client", "0"); initData.properties.setProperty("Ice.RetryIntervals", "-1"); @@ -282,9 +296,11 @@ public abstract class Application : Ice.Application int ret = 0; do { - // A copy of the initialization data and the string seq + // + // A copy of the initialization data and the string array // needs to be passed to doMainInternal, as these can be // changed by the application. + // Ice.InitializationData id = (Ice.InitializationData)initData.Clone(); id.properties = id.properties.ice_clone_(); string[] args = (string[]) originArgs.Clone(); @@ -298,8 +314,10 @@ public abstract class Application : Ice.Application private bool doMain(string[] args, Ice.InitializationData initData, out int status) { + // // Reset internal state variables from Ice.Application. The // remainder are reset at the end of this method. + // callbackInProgress__ = false; destroyed__ = false; interrupted__ = false; @@ -316,7 +334,7 @@ public abstract class Application : Ice.Application _router = Glacier2.RouterPrxHelper.uncheckedCast(communicator().getDefaultRouter()); if(_router == null) { - Ice.Util.getProcessLogger().error(appName__ + ": no glacier2 router configured"); + Ice.Util.getProcessLogger().error(appName__ + ": no Glacier2 router configured"); status = 1; } else @@ -329,7 +347,9 @@ public abstract class Application : Ice.Application destroyOnInterrupt(); } + // // If createSession throws, we're done. + // try { _session = createSession(); @@ -350,10 +370,12 @@ public abstract class Application : Ice.Application } } } - // We want to restart on those exceptions which indicate a + // + // We want to restart on those exceptions that indicate a // break down in communications, but not those exceptions that - // indicate a programming logic error (ie: marshal, protocol + // indicate a programming logic error (i.e., marshal, protocol // failure, etc). + // catch(RestartSessionException) { restart = true; @@ -452,15 +474,21 @@ public abstract class Application : Ice.Application } catch(Ice.ConnectionLostException) { + // // Expected if another thread invoked on an object from the session concurrently. + // } catch(Glacier2.SessionNotExistException) { + // // This can also occur. + // } catch(System.Exception ex) { + // // Not expected. + // Ice.Util.getProcessLogger().error("unexpected exception when destroying the session:\n" + ex.ToString()); } @@ -486,9 +514,11 @@ public abstract class Application : Ice.Application communicator__ = null; } + // // Reset internal state. We cannot reset the Application state // here, since destroyed__ must remain true until we re-run // this method. + // _adapter = null; _router = null; _session = null; @@ -502,4 +532,5 @@ public abstract class Application : Ice.Application private static Glacier2.SessionPrx _session; private static bool _createdSession = false; } + } diff --git a/cs/src/Glacier2/SessionCallback.cs b/cs/src/Glacier2/SessionCallback.cs index 3f59fca4843..38203252694 100644 --- a/cs/src/Glacier2/SessionCallback.cs +++ b/cs/src/Glacier2/SessionCallback.cs @@ -11,45 +11,41 @@ using System; namespace Glacier2 { -/// <sumary> +/// <summary> /// A callback class to get notifications of status changes in the /// Glacier2 session. All callbacks on the SessionCallback interface /// occur in the main swing thread. -/// </sumary> +/// </summary> public interface SessionCallback { - /// <sumary> + /// <summary> /// Notifies the application that the communicator was created. - /// </sumary> + /// </summary> /// <param name="session">The Glacier2 session.</param> - void - createdCommunicator(SessionHelper session); + void createdCommunicator(SessionHelper session); - /// <sumary> + /// <summary> /// Notifies the application that the Glacier2 session has /// been established. - /// </sumary> + /// </summary> /// <param name="session">The established session.</param> - void - connected(SessionHelper session); + void connected(SessionHelper session); - /// <sumary> + /// <summary> /// Notifies the application that the Glacier2 session has been /// disconnected. - /// </sumary> + /// </summary> /// <param name="session">The disconnected session.</param> - void - disconnected(SessionHelper session); + void disconnected(SessionHelper session); - /// <sumary> + /// <summary> /// Notifies the application that the Glacier2 session /// establishment failed. - /// </sumary> + /// </summary> /// <param name="session">The session reporting the connection /// failure.</param> /// <param name="ex">The exception.</param> - void - connectFailed(SessionHelper session, Exception ex); + void connectFailed(SessionHelper session, Exception ex); } } diff --git a/cs/src/Glacier2/SessionFactoryHelper.cs b/cs/src/Glacier2/SessionFactoryHelper.cs index a6a3606dd3c..f6f79932bbc 100644 --- a/cs/src/Glacier2/SessionFactoryHelper.cs +++ b/cs/src/Glacier2/SessionFactoryHelper.cs @@ -13,19 +13,19 @@ using System.Text; namespace Glacier2 { -/// <sumary> +/// <summary> /// A helper class for using Glacier2 with GUI applications. /// /// Applications should create a session factory for each Glacier2 router to which the application will /// connect. To connect with the Glacier2 router, call SessionFactory.connect. The callback object is -/// notified of the various life cycle events. Once the session is torn down for whatever reason, the application -/// can use the session factory to create another connection. -/// </sumary> +/// notified of the various life cycle events. Once the session is torn down for whatever reason, the +/// application can use the session factory to create another connection. +/// </summary> public class SessionFactoryHelper { - /// <sumary> + /// <summary> /// Creates a SessionFactory object. - /// </sumary> + /// </summary> /// <param name="callback">The callback object for notifications.</param> public SessionFactoryHelper(SessionCallback callback) @@ -36,9 +36,9 @@ public class SessionFactoryHelper setDefaultProperties(); } - /// <sumary> + /// <summary> /// Creates a SessionFactory object. - /// </sumary> + /// </summary> /// <param name="initData">The initialization data to use when creating the communicator.</param> /// <param name="callback">The callback object for notifications.</param> public @@ -49,9 +49,9 @@ public class SessionFactoryHelper setDefaultProperties(); } - /// <sumary> + /// <summary> /// Creates a SessionFactory object. - /// </sumary> + /// </summary> /// <param name="properties">The properties to use when creating the communicator.</param> /// <param name="callback">The callback object for notifications.</param> public @@ -63,9 +63,9 @@ public class SessionFactoryHelper setDefaultProperties(); } - /// <sumary> + /// <summary> /// Set the router object identity. - /// </sumary> + /// </summary> /// <param name="identity">The Glacier2 router's identity.</param> public void setRouterIdentity(Ice.Identity identity) @@ -76,9 +76,9 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Returns the object identity of the Glacier2 router. - /// </sumary> + /// </summary> /// <returns> The Glacier2 router's identity.</returns> public Ice.Identity getRouterIdentity() @@ -89,9 +89,9 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Sets the host on which the Glacier2 router runs. - /// </sumary> + /// </summary> /// <param name="hostname">The host name (or IP address) of the router host.</param> public void setRouterHost(string hostname) @@ -102,9 +102,9 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Returns the host on which the Glacier2 router runs. - /// </sumary> + /// </summary> /// <returns>The Glacier2 router host.</returns> public string getRouterHost() @@ -115,9 +115,9 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Sets whether to connect with the Glacier2 router securely. - /// </sumary> + /// </summary> /// <param name="secure">If true, the client connects to the router /// via SSL; otherwise, the client connects via TCP.</param> public void @@ -129,9 +129,9 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Returns whether the session factory will establish a secure connection to the Glacier2 router. - /// </sumary> + /// </summary> /// <returns>The secure flag.</returns> public bool getSecure() @@ -142,9 +142,9 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Sets the connect and connection timeout for the Glacier2 router. - /// </sumary> + /// </summary> /// <param name="timeoutMillisecs">The timeout in milliseconds. A zero /// or negative timeout value indicates that the router proxy has no /// associated timeout.</param> @@ -157,9 +157,9 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Returns the connect and connection timeout associated with the Glacier2 router. - /// </sumary> + /// </summary> /// <returns>The timeout.</returns> public int getTimeout() @@ -170,9 +170,9 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Sets the Glacier2 router port to connect to. - /// </sumary> + /// </summary> /// <param name="port">The port. If 0, then the default port (4063 for TCP or /// 4064 for SSL) is used.</param> public void @@ -184,9 +184,9 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Returns the Glacier2 router port to connect to. - /// </sumary> + /// </summary> /// <returns>The port.</returns> public int getPort() @@ -211,13 +211,13 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Connects to the Glacier2 router using the associated SSL credentials. /// /// Once the connection is established, SesssionCallback.connected is called on /// the callback object; upon failure, SessionCallback.connectFailed is called /// with the exception. - /// </sumary> + /// </summary> /// <returns>The connected session.</returns> public SessionHelper connect() @@ -230,13 +230,13 @@ public class SessionFactoryHelper } } - /// <sumary> + /// <summary> /// Connect the Glacier2 session using user name and password credentials. /// /// Once the connection is established, SessionCallback.connected is called on /// the callback object; upon failure, SessionCallback.connectFailed is called /// with the exception. - /// </sumary> + /// </summary> /// <param name="username">The user name.</param> /// <param name="password">The password.</param> /// <returns>The connected session.</returns> @@ -254,7 +254,9 @@ public class SessionFactoryHelper private Ice.InitializationData createInitData() { + // // Clone the initialization data and properties. + // Ice.InitializationData initData = (Ice.InitializationData)_initData.Clone(); initData.properties = initData.properties.ice_clone_(); diff --git a/cs/src/Glacier2/SessionHelper.cs b/cs/src/Glacier2/SessionHelper.cs index c380579d3cf..bc897e38090 100644 --- a/cs/src/Glacier2/SessionHelper.cs +++ b/cs/src/Glacier2/SessionHelper.cs @@ -14,9 +14,9 @@ using System.Threading; namespace Glacier2 { -/// <sumary> +/// <summary> /// A helper class for using Glacier2 with GUI applications. -/// </sumary> +/// </summary> public class SessionHelper { private class SessionRefreshThread @@ -59,7 +59,18 @@ public class SessionHelper { while(true) { - _router.refreshSession_async(new RefreshI(_session, this)); + try + { + _router.refreshSession_async(new RefreshI(_session, this)); + } + catch(Ice.CommunicatorDestroyedException) + { + // + // AMI requests can raise CommunicatorDestroyedException directly. + // + break; + } + if(!_done) { try @@ -70,6 +81,7 @@ public class SessionHelper { } } + if(_done) { break; @@ -97,9 +109,9 @@ public class SessionHelper private bool _done = false; } - /// <sumary> + /// <summary> /// Creates a Glacier2 session. - /// </sumary> + /// </summary> /// <param name="callback">The callback for notifications about session /// establishment.</param> /// <param name="initData">The Ice.InitializationData for initializing @@ -110,12 +122,12 @@ public class SessionHelper _initData = initData; } - /// <sumary> + /// <summary> /// Destroys the Glacier2 session. /// /// Once the session has been destroyed, SessionCallback.disconnected is /// called on the associated callback object. - /// </sumary> + /// </summary> public void destroy() { @@ -129,24 +141,28 @@ public class SessionHelper if(_sessionRefresh == null) { + // // In this case a connecting session is being // destroyed. The communicator and session will be // destroyed when the connection establishment has // completed. + // return; } _session = null; + // // Run the destroyInternal in a thread. This is because it // destroyInternal makes remote invocations. + // Thread t = new Thread(new ThreadStart(destroyInternal)); t.Start(); } } - /// <sumary> + /// <summary> /// Returns the session's communicator object. - /// </sumary> + /// </summary> /// <returns>The communicator.</returns> public Ice.Communicator communicator() @@ -157,12 +173,12 @@ public class SessionHelper } } - /// <sumary> + /// <summary> /// Returns the category to be used in the identities of all of /// the client's callback objects. Clients must use this category /// for the router to forward callback requests to the intended /// client. - /// </sumary> + /// </summary> /// <returns>The category. Throws SessionNotExistException /// No session exists</returns> public string @@ -179,10 +195,10 @@ public class SessionHelper } } - /// <sumary> + /// <summary> /// Adds a servant to the callback object adapter's Active Servant /// Map with a UUID. - /// </sumary> + /// </summary> /// <param name="servant">The servant to add.</param> /// <returns>The proxy for the servant. Throws SessionNotExistException /// if no session exists.</returns> @@ -201,11 +217,11 @@ public class SessionHelper } } - /// <sumary> + /// <summary> /// Returns the Glacier2 session proxy. If the session hasn't been /// established yet, or the session has already been destroyed, /// throws SessionNotExistException. - /// </sumary> + /// </summary> /// <returns>The session proxy, or throws SessionNotExistException /// if no session exists.</returns> public Glacier2.SessionPrx @@ -221,9 +237,9 @@ public class SessionHelper } } - /// <sumary> + /// <summary> /// Returns true if there is an active session, otherwise returns false. - /// </sumary> + /// </summary> /// <returns>true if session exists or false if no session exists.</returns> public bool isConnected() @@ -234,9 +250,9 @@ public class SessionHelper } } - /// <sumary> - /// Creates an object adapter for callback objects. - /// </sumary> + /// <summary> + /// Returns an object adapter for callback objects, creating it if necessary. + /// </summary> /// <return>The object adapter. throws SessionNotExistException /// if no session exists.</return> public Ice.ObjectAdapter @@ -245,7 +261,9 @@ public class SessionHelper return internalObjectAdapter(); } + // // Only call this method when the calling thread owns the lock + // private Ice.ObjectAdapter internalObjectAdapter() { @@ -264,13 +282,13 @@ public class SessionHelper } } - /// <sumary> + /// <summary> /// Connects to the Glacier2 router using the associated SSL credentials. /// - /// Once the connection is established, SessionCallback.connected} is called on + /// Once the connection is established, SessionCallback.connected is called on /// the callback object; upon failure, SessionCallback.exception is called with /// the exception. - /// </sumary> + /// </summary> public void connect() { @@ -283,12 +301,12 @@ public class SessionHelper } } - /// <sumary> + /// <summary> /// Connects a Glacier2 session using user name and password credentials. /// /// Once the connection is established, SessionCallback.connected is called on the callback object; /// upon failure SessionCallback.exception is called with the exception. - /// </sumary> + /// </summary> /// <param name="username">The user name.</param> /// <param name="password">The password.</param> public void @@ -316,7 +334,9 @@ public class SessionHelper return; } + // // Assign the session after _destroy is checked. + // _session = session; _connected = true; @@ -353,15 +373,21 @@ public class SessionHelper } catch(Ice.ConnectionLostException) { + // // Expected if another thread invoked on an object from the session concurrently. + // } catch(SessionNotExistException) { + // // This can also occur. + // } catch(Exception e) { + // // Not expected. + // _communicator.getLogger().warning("SessionHelper: unexpected exception when destroying the session:\n" + e); } @@ -402,8 +428,7 @@ public class SessionHelper } } - delegate Glacier2.SessionPrx - ConnectStrategy(Glacier2.RouterPrx router); + delegate Glacier2.SessionPrx ConnectStrategy(Glacier2.RouterPrx router); private void connectImpl(ConnectStrategy factory) diff --git a/cs/src/Ice/PluginManagerI.cs b/cs/src/Ice/PluginManagerI.cs index 8fda6d87848..86ee3de831b 100644 --- a/cs/src/Ice/PluginManagerI.cs +++ b/cs/src/Ice/PluginManagerI.cs @@ -402,7 +402,7 @@ namespace Ice catch(System.Exception ex) { // - // IceSSL is not supported with Mono 1.2. We avoid throwing an exception in that case, + // IceSSL is not yet supported with Mono. We avoid throwing an exception in that case, // so the same configuration can be used with Mono or Visual C#. // if(IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono && name == "IceSSL") diff --git a/java/src/Glacier2/Application.java b/java/src/Glacier2/Application.java index 463d35aa9c8..cddb824a93d 100644 --- a/java/src/Glacier2/Application.java +++ b/java/src/Glacier2/Application.java @@ -75,7 +75,6 @@ public abstract class Application extends Ice.Application super(signalPolicy); } - /** * Called once the communicator has been initialized and the Glacier2 session * has been established. A derived class must implement <code>runWithSession</code>, @@ -169,7 +168,8 @@ public abstract class Application extends Ice.Application * @throws SessionNotExistException No session exists. **/ public String - categoryForClient() throws SessionNotExistException + categoryForClient() + throws SessionNotExistException { if(_router == null) { @@ -185,7 +185,8 @@ public abstract class Application extends Ice.Application * @throws SessionNotExistException No session exists. **/ public Ice.Identity - createCallbackIdentity(String name) throws SessionNotExistException + createCallbackIdentity(String name) + throws SessionNotExistException { return new Ice.Identity(name, categoryForClient()); } @@ -197,7 +198,8 @@ public abstract class Application extends Ice.Application * @throws SessionNotExistException No session exists. **/ public Ice.ObjectPrx - addWithUUID(Ice.Object servant) throws SessionNotExistException + addWithUUID(Ice.Object servant) + throws SessionNotExistException { return objectAdapter().add(servant, createCallbackIdentity(java.util.UUID.randomUUID().toString())); } @@ -208,7 +210,8 @@ public abstract class Application extends Ice.Application * @throws SessionNotExistException No session exists. */ public synchronized Ice.ObjectAdapter - objectAdapter() throws SessionNotExistException + objectAdapter() + throws SessionNotExistException { if(_adapter == null) { @@ -236,35 +239,45 @@ public abstract class Application extends Ice.Application { while(true) { - _router.refreshSession_async(new Glacier2.AMI_Router_refreshSession() - { - public void - ice_response() - { - } - - public void - ice_exception(Ice.LocalException ex) - { - // Here the session has gone. The thread - // terminates, and we notify the - // application that the session has been - // destroyed. - done(); - sessionDestroyed(); - } - - public void - ice_exception(Ice.UserException ex) + try + { + _router.refreshSession_async(new Glacier2.AMI_Router_refreshSession() { - // Here the session has gone. The thread - // terminates, and we notify the - // application that the session has been - // destroyed. - done(); - sessionDestroyed(); - } - }); + public void + ice_response() + { + } + + public void + ice_exception(Ice.LocalException ex) + { + // + // Here the session has gone. The thread terminates, and we notify the + // application that the session has been destroyed. + // + done(); + sessionDestroyed(); + } + + public void + ice_exception(Ice.UserException ex) + { + // + // Here the session has gone. The thread terminates, and we notify the + // application that the session has been destroyed. + // + done(); + sessionDestroyed(); + } + }); + } + catch(Ice.CommunicatorDestroyedException ex) + { + // + // AMI requests can raise CommunicatorDestroyedException directly. + // + break; + } if(!_done) { @@ -302,7 +315,9 @@ public abstract class Application extends Ice.Application protected int doMain(Ice.StringSeqHolder argHolder, Ice.InitializationData initData) { + // // Set the default properties for all Glacier2 applications. + // initData.properties.setProperty("Ice.ACM.Client", "0"); initData.properties.setProperty("Ice.RetryIntervals", "-1"); @@ -310,9 +325,11 @@ public abstract class Application extends Ice.Application Ice.IntHolder ret = new Ice.IntHolder(); do { - // A copy of the initialization data and the string seq + // + // A copy of the initialization data and the string array // needs to be passed to doMainInternal, as these can be // changed by the application. + // Ice.InitializationData id = (Ice.InitializationData)initData.clone(); id.properties = id.properties._clone(); Ice.StringSeqHolder h = new Ice.StringSeqHolder(); @@ -327,8 +344,10 @@ public abstract class Application extends Ice.Application private boolean doMain(Ice.StringSeqHolder argHolder, Ice.InitializationData initData, Ice.IntHolder status) { + // // Reset internal state variables from Ice.Application. The // remainder are reset at the end of this method. + // _callbackInProgress = false; _destroyed = false; _interrupted = false; @@ -357,7 +376,9 @@ public abstract class Application extends Ice.Application destroyOnInterrupt(); } + // // If createSession throws, we're done. + // try { _session = createSession(); @@ -377,10 +398,12 @@ public abstract class Application extends Ice.Application } } } - // We want to restart on those exceptions which indicate a + // + // We want to restart on those exceptions that indicate a // break down in communications, but not those exceptions that - // indicate a programming logic error (ie: marshal, protocol + // indicate a programming logic error (i.e., marshal, protocol // failure, etc). + // catch(RestartSessionException ex) { restart = true; @@ -429,7 +452,9 @@ public abstract class Application extends Ice.Application status.value = 1; } + // // This clears any set interrupt. + // if(_signalPolicy == Ice.SignalPolicy.HandleSignals) { defaultInterrupt(); @@ -458,7 +483,7 @@ public abstract class Application extends Ice.Application // // And _communicator != null, meaning will be // destroyed next, _destroyed = true also ensures that - // any remaining callback won't do anything + // any remaining callback won't do anything. // } } @@ -488,15 +513,21 @@ public abstract class Application extends Ice.Application } catch(Ice.ConnectionLostException ex) { + // // Expected if another thread invoked on an object from the session concurrently. + // } catch(Glacier2.SessionNotExistException ex) { + // // This can also occur. + // } catch(Throwable ex) { + // // Not expected. + // Ice.Util.getProcessLogger().error("unexpected exception when destroying the session:\n" + IceInternal.Ex.toString(ex)); } @@ -530,9 +561,11 @@ public abstract class Application extends Ice.Application } } + // // Reset internal state. We cannot reset the Application state // here, since _destroyed must remain true until we re-run // this method. + // _adapter = null; _router = null; _session = null; diff --git a/java/src/Glacier2/SessionCallback.java b/java/src/Glacier2/SessionCallback.java index ac096010d9a..2af9d214108 100644 --- a/java/src/Glacier2/SessionCallback.java +++ b/java/src/Glacier2/SessionCallback.java @@ -20,16 +20,14 @@ public interface SessionCallback * * @param session The Glacier2 session. */ - void - createdCommunicator(SessionHelper session); + void createdCommunicator(SessionHelper session); /** * Notifies the application that the Glacier2 session has been established. * * @param session The established session. */ - void - connected(SessionHelper session) + void connected(SessionHelper session) throws SessionNotExistException; /** @@ -37,8 +35,7 @@ public interface SessionCallback * * @param session The disconnected session. */ - void - disconnected(SessionHelper session); + void disconnected(SessionHelper session); /** * Notifies the application that the Glacier2 session establishment failed. @@ -47,6 +44,5 @@ public interface SessionCallback * failure. * @param ex The exception. */ - void - connectFailed(SessionHelper session, Throwable ex); + void connectFailed(SessionHelper session, Throwable ex); } diff --git a/java/src/Glacier2/SessionFactoryHelper.java b/java/src/Glacier2/SessionFactoryHelper.java index 324e93e4046..37914ac5d00 100644 --- a/java/src/Glacier2/SessionFactoryHelper.java +++ b/java/src/Glacier2/SessionFactoryHelper.java @@ -26,7 +26,8 @@ public class SessionFactoryHelper * @throws {@link Ice.InitializationException} */ public - SessionFactoryHelper(SessionCallback callback) throws Ice.InitializationException + SessionFactoryHelper(SessionCallback callback) + throws Ice.InitializationException { initialize(callback, new Ice.InitializationData(), Ice.Util.createProperties()); } @@ -39,7 +40,8 @@ public class SessionFactoryHelper * @throws {@link Ice.InitializationException} */ public - SessionFactoryHelper(Ice.InitializationData initData, SessionCallback callback) throws Ice.InitializationException + SessionFactoryHelper(Ice.InitializationData initData, SessionCallback callback) + throws Ice.InitializationException { initialize(callback, initData, initData.properties); } @@ -52,7 +54,8 @@ public class SessionFactoryHelper * @throws {@link Ice.InitializationException} */ public - SessionFactoryHelper(Ice.Properties properties, SessionCallback callback) throws Ice.InitializationException + SessionFactoryHelper(Ice.Properties properties, SessionCallback callback) + throws Ice.InitializationException { initialize(callback, new Ice.InitializationData(), properties); } @@ -63,8 +66,8 @@ public class SessionFactoryHelper { if(callback == null) { - throw new Ice.InitializationException("Attempt to create a SessionFactoryHelper with a null SessionCallback" + - "argument"); + throw new Ice.InitializationException("Attempt to create a SessionFactoryHelper with a null " + + "SessionCallback argument"); } if(initData == null) @@ -250,7 +253,9 @@ public class SessionFactoryHelper private Ice.InitializationData createInitData() { + // // Clone the initialization data and properties. + // Ice.InitializationData initData = (Ice.InitializationData)_initData.clone(); initData.properties = initData.properties._clone(); diff --git a/java/src/Glacier2/SessionHelper.java b/java/src/Glacier2/SessionHelper.java index e0ca6dd2c9d..66b15a4ebd8 100644 --- a/java/src/Glacier2/SessionHelper.java +++ b/java/src/Glacier2/SessionHelper.java @@ -28,24 +28,35 @@ public class SessionHelper { while(true) { - _router.refreshSession_async(new Glacier2.AMI_Router_refreshSession() + try { - public void ice_response() + _router.refreshSession_async(new Glacier2.AMI_Router_refreshSession() { - } + public void ice_response() + { + } - public void ice_exception(Ice.LocalException ex) - { - done(); - SessionHelper.this.destroy(); - } + public void ice_exception(Ice.LocalException ex) + { + done(); + SessionHelper.this.destroy(); + } + + public void ice_exception(Ice.UserException ex) + { + done(); + SessionHelper.this.destroy(); + } + }); + } + catch(Ice.CommunicatorDestroyedException ex) + { + // + // AMI requests can raise CommunicatorDestroyedException directly. + // + break; + } - public void ice_exception(Ice.UserException ex) - { - done(); - SessionHelper.this.destroy(); - } - }); if(!_done) { try @@ -56,6 +67,7 @@ public class SessionHelper { } } + if(_done) { break; @@ -106,10 +118,12 @@ public class SessionHelper _destroy = true; if(_refreshThread == null) { + // // In this case a connecting session is being // destroyed. The communicator and session will be // destroyed when the connection establishment has // completed. + // return; } _session = null; @@ -127,8 +141,10 @@ public class SessionHelper // Ignore } + // // Run the destroyInternal in a thread. This is because it // destroyInternal makes remote invocations. + // new Thread(new Runnable() { public void run() @@ -225,7 +241,9 @@ public class SessionHelper return internalObjectAdapter(); } + // // Only call this method when the calling thread owns the lock + // private Ice.ObjectAdapter internalObjectAdapter() throws SessionNotExistException @@ -301,7 +319,9 @@ public class SessionHelper return; } + // // Assign the session after _destroy is checked. + // _session = session; _connected = true; @@ -329,8 +349,9 @@ public class SessionHelper } catch(SecurityException ex) { - // Ignore. Unsigned applets cannot registered shutdown - // hooks. + // + // Ignore. Unsigned applets cannot registered shutdown hooks. + // } dispatchCallback(new Runnable() @@ -360,15 +381,21 @@ public class SessionHelper } catch(Ice.ConnectionLostException e) { + // // Expected if another thread invoked on an object from the session concurrently. + // } catch(SessionNotExistException e) { + // // This can also occur. + // } catch(Throwable e) { + // // Not expected. + // _communicator.getLogger().warning("SessionHelper: unexpected exception when destroying the session:\n" + e); } _router = null; @@ -400,7 +427,9 @@ public class SessionHelper } _communicator = null; + // // Notify the callback that the session is gone. + // dispatchCallback(new Runnable() { public void run() |