public AMI_Router_refreshSessionI(Application app, SessionPingThread ping) { _app = app; _ping = ping; }
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; bool restart = false; status = 0; SessionPingThread ping = null; Thread pingThread = null; try { communicator__ = Ice.Util.initialize(ref args, initData); _router = Glacier2.RouterPrxHelper.uncheckedCast(communicator().getDefaultRouter()); if (_router == null) { Ice.Util.getProcessLogger().error(appName__ + ": no Glacier2 router configured"); status = 1; } else { // // The default is to destroy when a signal is received. // if (signalPolicy__ == Ice.SignalPolicy.HandleSignals) { destroyOnInterrupt(); } // // If createSession throws, we're done. // try { _session = createSession(); _createdSession = true; } catch (Ice.LocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); status = 1; } if (_createdSession) { long timeout = _router.getSessionTimeout(); if (timeout > 0) { ping = new SessionPingThread(this, _router, (timeout * 1000) / 2); pingThread = new Thread(new ThreadStart(ping.run)); pingThread.Start(); } _category = _router.getCategoryForClient(); status = runWithSession(args); } } } // // We want to restart on those exceptions that indicate a // break down in communications, but not those exceptions that // indicate a programming logic error (i.e., marshal, protocol // failure, etc). // catch (RestartSessionException) { restart = true; } catch (Ice.ConnectionRefusedException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.ConnectionLostException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.UnknownLocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.RequestFailedException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.TimeoutException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch (Ice.LocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); status = 1; } catch (System.Exception ex) { Ice.Util.getProcessLogger().error("unknown exception:\n" + ex.ToString()); status = 1; } // // Don't want any new interrupt. And at this point // (post-run), it would not make sense to release a held // signal to run shutdown or destroy. // if (signalPolicy__ == Ice.SignalPolicy.HandleSignals) { ignoreInterrupt(); } mutex__.Lock(); try { while (callbackInProgress__) { mutex__.Wait(); } if (destroyed__) { communicator__ = null; } else { destroyed__ = true; // // And communicator__ != null, meaning will be // destroyed next, destroyed__ = true also ensures that // any remaining callback won't do anything // } } finally { mutex__.Unlock(); } if (ping != null) { ping.done(); ping = null; while (true) { #if COMPACT pingThread.Join(); break; #else try { pingThread.Join(); break; } catch (ThreadInterruptedException) { } #endif } pingThread = null; } if (_createdSession && _router != null) { try { _router.destroySession(); } 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()); } _router = null; } if (communicator__ != null) { try { communicator__.destroy(); } catch (Ice.LocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); status = 1; } catch (System.Exception ex) { Ice.Util.getProcessLogger().error("unknown exception:\n" + ex.ToString()); status = 1; } 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; _createdSession = false; _category = null; return(restart); }
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; bool restart = false; status = 0; SessionPingThread ping = null; Thread pingThread = null; try { communicator__ = Ice.Util.initialize(ref args, initData); _router = Glacier2.RouterPrxHelper.uncheckedCast(communicator().getDefaultRouter()); if(_router == null) { Ice.Util.getProcessLogger().error(appName__ + ": no Glacier2 router configured"); status = 1; } else { // // The default is to destroy when a signal is received. // if(signalPolicy__ == Ice.SignalPolicy.HandleSignals) { destroyOnInterrupt(); } // // If createSession throws, we're done. // try { _session = createSession(); _createdSession = true; } catch(Ice.LocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); status = 1; } if(_createdSession) { long timeout = _router.getSessionTimeout(); if(timeout > 0) { ping = new SessionPingThread(this, _router, (timeout * 1000) / 2); pingThread = new Thread(new ThreadStart(ping.run)); pingThread.Start(); } _category = _router.getCategoryForClient(); status = runWithSession(args); } } } // // We want to restart on those exceptions that indicate a // break down in communications, but not those exceptions that // indicate a programming logic error (i.e., marshal, protocol // failure, etc). // catch(RestartSessionException) { restart = true; } catch(Ice.ConnectionRefusedException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch(Ice.ConnectionLostException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch(Ice.UnknownLocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch(Ice.RequestFailedException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch(Ice.TimeoutException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); restart = true; } catch(Ice.LocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); status = 1; } catch(System.Exception ex) { Ice.Util.getProcessLogger().error("unknown exception:\n" + ex.ToString()); status = 1; } // // Don't want any new interrupt. And at this point // (post-run), it would not make sense to release a held // signal to run shutdown or destroy. // if(signalPolicy__ == Ice.SignalPolicy.HandleSignals) { ignoreInterrupt(); } mutex__.Lock(); try { while(callbackInProgress__) { mutex__.Wait(); } if(destroyed__) { communicator__ = null; } else { destroyed__ = true; // // And communicator__ != null, meaning will be // destroyed next, destroyed__ = true also ensures that // any remaining callback won't do anything // } } finally { mutex__.Unlock(); } if(ping != null) { ping.done(); ping = null; while(true) { #if COMPACT pingThread.Join(); break; #else try { pingThread.Join(); break; } catch(ThreadInterruptedException) { } #endif } pingThread = null; } if(_createdSession && _router != null) { try { _router.destroySession(); } 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()); } _router = null; } if(communicator__ != null) { try { communicator__.destroy(); } catch(Ice.LocalException ex) { Ice.Util.getProcessLogger().error(ex.ToString()); status = 1; } catch(System.Exception ex) { Ice.Util.getProcessLogger().error("unknown exception:\n" + ex.ToString()); status = 1; } 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; _createdSession = false; _category = null; return restart; }