callbackClient = new Client(clientLocator, "callback", clientMetadata); listenerMetadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "13000"); callbackClient.connect(new ClientConnectionListener(), listenerMetadata); callbackHandler = new CallbackHandler(); callbackClient.addListener(callbackHandler, callbackMetadata); Set callbackConnectors = callbackClient.getCallbackConnectors(callbackHandler); if (callbackConnectors.size() != 1) { logger.warn("There should be one callback Connector (number existing = " + callbackConnectors.size() + ')'); callbackClient.invoke(null); sessionId = callbackClient.getSessionId(); sessionState = SessionState.CONNECTED; logger.info("Connected to MAGE server at " + connection.getHost() + ':' + connection.getPort());
/** * @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(); } }
@Override public boolean isConnected() { if (callbackClient == null) { return false; } return callbackClient.isConnected(); }
public void connect() throws Exception { if (callBackClient != null) { if (callBackClient.isConnected()) return; callBackClient.connect(); } }
/** * Invokes JBoss Remoting using the given command. * Attempts to cache the client if sending the message was successful. * * @return object as a result of this call */ private Object invoke(Command command) throws Throwable { InvokerLocator locator = m_invokerLocator; if (locator == null) { throw new IllegalStateException("m_invokerLocator is null"); } Client client = m_client.get(); if (client != null && client.getInvoker() == null) { client.disconnect(); } if (client == null || !client.isConnected()) { client = new Client(locator, getSubsystem(), m_clientConfiguration); client.connect(); try { return client.invoke(command); } finally { cacheClient(client); } } // Note: Despite all the checks above, the client might have been // disconnected before invoke is reached. Let's hope that doesn't happen. return client.invoke(command); }
/** * This will create the Client. */ public void init() { try { String locatorURI = "multiplex://localhost:9090/?multiplexBindHost=localhost&multiplexBindPort=8080"; InvokerLocator locator = new InvokerLocator(locatorURI); client = new Client(locator, "sample"); client.connect(); System.out.println("Connected client to server at: " + client.getInvoker().getLocator().getLocatorURI()); } catch(Exception e) { e.printStackTrace(); } }
if (isConnected()) invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata); new InternalInvocation(InternalInvocation.REMOVELISTENER, null); invoke(ii, metadata); Client client = new Client(locator, subsystem); client.setSessionId(getSessionId()); client.connect(); InternalInvocation ii = new InternalInvocation(InternalInvocation.REMOVECLIENTLISTENER, new Object[]{callbackHandler}); client.invoke(ii, metadata); client.disconnect();
public void makeInvocation(String locatorURI) throws Throwable { // create InvokerLocator with the url type string // indicating the target remoting server to call upon. InvokerLocator locator = new InvokerLocator(locatorURI); System.out.println("Calling remoting server with locator uri of: " + locatorURI); Client remotingClient = new Client(locator); remotingClient.connect(); String request = "Do something"; System.out.println("Invoking server with request of '" + request + "'"); Object response = remotingClient.invoke(request); remotingClient.disconnect(); System.out.println("Invocation response: " + response); }
String listenerId = generateListenerId(callbackhandler); invoke(new InternalInvocation(InternalInvocation.ADDLISTENER, null), internalMetadata, callbackLocator); Client client = new Client(callbackLocator, subsystem); client.setSessionId(getSessionId()); client.connect(); new Object[]{callbackhandler, callbackHandlerObject}); client.invoke(i, internalMetadata); client.disconnect(); invoke(new InternalInvocation(InternalInvocation.ADDLISTENER, null), internalMetadata, callbackLocator);
Client client = new Client(locator, cconfig); client.connect(); ClientInvoker clientInvoker = client.getInvoker(); clientInvoker.setSocketFactory(sf2); System.out.println(getName() + ": " + client.invoke("test invoke()")); client.addListener(callbackHandler, callbackLocator, callbackHandleObject); client.disconnect(); callbackConnector.stop(); connector.stop();
public void makeClientCall() throws Throwable { handler = new SampleCallbackHandler(); // Need to add callback listener to get callback client.addListener(handler, locator, client.getSessionId()); // make invocation Object answer = client.invoke(new Integer(17)); System.out.println("invocation returns: " + ((Integer) answer).intValue()); }
public void makeInvocation(String locatorURI) throws Throwable { // create InvokerLocator with the url type string // indicating the target remoting server to call upon. InvokerLocator locator = new InvokerLocator(locatorURI); System.out.println("Calling remoting server with locator uri of: " + locatorURI); Client remotingClient = new Client(locator); remotingClient.connect(); NonSerializablePayload payload = new NonSerializablePayload("foo", 1); System.out.println("Invoking server with request of '" + payload + "'"); Object response = remotingClient.invoke(payload); System.out.println("Invocation response: " + response); }
/** * 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(); }
/** * Invoke the method remotely. * * @param param - payload for the server invoker handler. * @param metadata - any extra metadata that may be needed by the transport (i.e. GET or POST if * using http invoker) or if need to pass along extra data to the server invoker handler. */ public Object invoke(Object param, Map metadata) throws Throwable { return invoke(param, metadata, 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()); } }
if(!loaderClient.isConnected()) loaderClient.connect(); Object obj = loaderClient.invoke(marshallerMethodName, metadata);
/** * Disconnects the remoting client */ private void disconnect() { if (remotingClient != null) { remotingClient.disconnect(); } }
if(client.isConnected() && ClientListener.hasListeners()) client.setSessionId(serverId); Boolean continuePolling = (Boolean) client.invoke(new NameBasedInvocation("$GetNotifications$", new Object[]{}, new String[]{}),
client.addListener(callbackHandler); client.invoke(CallbackAcknowledgeServer.APPLICATION_ACKNOWLDEGEMENTS); List callbacks = client.getCallbacks(callbackHandler); client.acknowledgeCallbacks(callbackHandler, callbacks, responses); client.removeListener(callbackHandler);