/** * @param askForReconnect - true = connection was lost because of error and * ask the user if he want to try to reconnect */ @Override public synchronized void disconnect(boolean askForReconnect) { if (isConnected()) { logger.info("DISCONNECT (still connected)"); sessionState = SessionState.DISCONNECTING; } if (connection == null || sessionState == SessionState.DISCONNECTED) { return; } try { callbackClient.removeListener(callbackHandler); callbackClient.disconnect(); TransporterClient.destroyTransporterClient(server); } catch (Throwable ex) { logger.fatal("Error disconnecting ...", ex); } if (sessionState == SessionState.DISCONNECTING || sessionState == SessionState.CONNECTING) { sessionState = SessionState.DISCONNECTED; logger.info("Disconnected ... "); if (askForReconnect) { client.showError("Network error. You have been disconnected from " + connection.getHost()); } client.disconnected(askForReconnect); // MageFrame with check to reconnect pingTime.clear(); } }
/** * In this test the connection is configured for push callbacks implemented in * Remoting by polling the server for callbacks and pushing them (on the client * side) to the InvokerCallbackHandler. Acknowledgements are made from * TestCallbackHandler.handleCallback() by an explicit call to * Client.acknowledgeCallback() after the callbacks have been received. */ public void testPolledCallbackApplicationAcknowledgements() { try { // Register callback handler. InvokerCallbackHandler callbackHandler = new AcknowledgingCallbackHandler(client); HashMap metadata = new HashMap(); metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "1000"); client.addListener(callbackHandler, metadata); // Request callbacks from server. client.invoke(CallbackAcknowledgeServer.APPLICATION_ACKNOWLDEGEMENTS); Thread.sleep(2000); // Unregister callback handler. client.removeListener(callbackHandler); } catch (Throwable e) { System.out.println("failure: " + e.getMessage()); } }
/** * In this test the connection is configured for push callbacks implemented in * Remoting by polling the server for callbacks and pushing them (on the client * side) to the InvokerCallbackHandler. Acknowledgements are handled implicitly * by Remoting. */ public void testPolledCallbackRemotingAcknowledgements() { try { // Register callback handler. InvokerCallbackHandler callbackHandler = new NonAcknowledgingCallbackHandler(); HashMap metadata = new HashMap(); metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "1000"); client.addListener(callbackHandler, metadata); // Request callbacks from server. client.invoke(CallbackAcknowledgeServer.REMOTING_ACKNOWLDEGEMENTS); Thread.sleep(2000); // Unregister callback handler. client.removeListener(callbackHandler); } catch (Throwable e) { System.out.println("failure: " + e.getMessage()); } }
/** * In this test the connection is configured for true push callbacks. * Acknowledgements are made from TestCallbackHandler.handleCallback() * by an explicit call to Client.acknowledgeCallback() after the callbacks * have been received. */ public void testPushCallbackApplicationAcknowledgements() { try { // Register callback handler. InvokerCallbackHandler callbackHandler = new AcknowledgingCallbackHandler(client); client.addListener(callbackHandler, null, null, true); // Request callbacks from servrr. client.invoke(CallbackAcknowledgeServer.APPLICATION_ACKNOWLDEGEMENTS); // Unregister callback handler. client.removeListener(callbackHandler); } catch (Throwable e) { System.out.println("failure: " + e.getMessage()); } }
public void tearDown() throws Throwable { while (!handler.gotCallbacks) Thread.sleep(1000); client.removeListener(handler); if(connector != null) { connector.stop(); connector.destroy(); connector = null; } locator = null; if(client != null) { client.disconnect(); client = null; } }
public void tearDown() throws Throwable { while (!handler.gotCallbacks) Thread.sleep(1000); client.removeListener(handler); if(connector != null) { connector.stop(); connector.destroy(); connector = null; } locator = null; if(client != null) { client.disconnect(); client = null; } }
public void tearDown() throws Throwable { while (!handler.gotCallbacks) Thread.sleep(1000); client.removeListener(handler); if(connector != null) { connector.stop(); connector.destroy(); connector = null; } locator = null; if(client != null) { client.disconnect(); client = null; } }
/** * In this test the connection is configured for true push callbacks, and * Acknowledgements are handled implicitly by Remoting. */ public void testPushCallbackRemotingAcknowledgements() { try { // Register callback handler. InvokerCallbackHandler callbackHandler = new NonAcknowledgingCallbackHandler(); client.addListener(callbackHandler, null, null, true); // Request callbacks from server. client.invoke(CallbackAcknowledgeServer.REMOTING_ACKNOWLDEGEMENTS); // Unregister callback handler. client.removeListener(callbackHandler); } catch (Throwable e) { System.out.println("failure: " + e.getMessage()); } }
public void tearDown() throws Throwable { while (!handler.gotCallbacks) Thread.sleep(1000); client.removeListener(handler); if(connector != null) { connector.stop(); connector.destroy(); connector = null; } locator = null; if(client != null) { client.disconnect(); client = null; } }
public void tearDown() throws Throwable { while (!handler.gotCallbacks) Thread.sleep(1000); client.removeListener(handler); if(connector != null) { connector.stop(); connector.destroy(); connector = null; } locator = null; if(client != null) { client.disconnect(); client = null; } }
public void tearDown() throws Throwable { while (!handler.gotCallbacks) Thread.sleep(1000); client.removeListener(handler); if(connector != null) { connector.stop(); connector.destroy(); connector = null; } locator = null; if(client != null) { client.disconnect(); client = null; } }
/** * Shows how to register for pull callbacks and then get any callbacks * that are waiting on the server. * * @throws Throwable */ public void testPullCallback() throws Throwable { // our impplementation of the InvokerCallbackHandler interface, which // is defined as an inner class below. CallbackHandler callbackHandler = new CallbackHandler(); // by passing only the callback handler, will indicate pull callbacks remotingClient.addListener(callbackHandler); // the callback server generates callback messages on its own and need // to give a few seconds to generate them. Thread.currentThread().sleep(2000); // call also make regular invocations on the server at any time. makeInvocation(); // go get our callbacks residing on the server List callbacks = remotingClient.getCallbacks(callbackHandler); Iterator itr = callbacks.iterator(); while(itr.hasNext()) { Callback callbackObject = (Callback) itr.next(); System.out.println("Pull Callback value = " + callbackObject.getCallbackObject()); } // remove callback handler from server remotingClient.removeListener(callbackHandler); }
/** * Registers callback listener and asks CallbackPoller to print statistics. */ public void getPolledCallbacks(String locatorURI) throws Throwable { System.out.println("Calling remoting server with locator uri of: " + locatorURI); InvokerLocator locator = new InvokerLocator(locatorURI); Client client = new Client(locator); client.connect(); // Registter callback handler and tell CallbackPoller to report statistics. CallbackHandler callbackHandler = new CallbackHandler(); HashMap metadata = new HashMap(); metadata.put(CallbackPoller.REPORT_STATISTICS, "true"); client.addListener(callbackHandler, metadata); // Wait for callbacks to received, processed, and acknowledged. Thread.sleep(20000); // remove callback handler from server client.removeListener(callbackHandler); client.disconnect(); }
client.removeListener(callbackHandler);
remotingClient.removeListener(callbackHandler);