@Override public boolean isConnected() { if (callbackClient == null) { return false; } return callbackClient.isConnected(); }
private void handleCannotConnectException(CannotConnectException ex) { logger.warn("Cannot connect", ex); Throwable t = ex.getCause(); String message = ""; while (t != null) { if (t instanceof ConnectException) { message = "Server is likely offline." + message; break; } if (t instanceof SocketException) { message = "Check your internet connection." + message; break; } if (t instanceof SocketTimeoutException) { message = "Server is not responding." + message; break; } if (t.getCause() != null && logger.isDebugEnabled()) { message = '\n' + t.getCause().getMessage() + message; logger.debug(t.getCause().getMessage()); } t = t.getCause(); } client.showMessage("Unable connect to server. " + message); if (logger.isTraceEnabled()) { logger.trace("StackTrace", t); } }
static boolean isAlreadyRunning(InvokerLocator serverLocator) { Map<String, String> metadata = new HashMap<>(); metadata.put(SocketWrapper.WRITE_TIMEOUT, String.valueOf(ConfigSettings.instance.getSocketWriteTimeout())); metadata.put("generalizeSocketException", "true"); try { MageServer testServer = (MageServer) TransporterClient.createTransporterClient(serverLocator.getLocatorURI(), MageServer.class, metadata); if (testServer != null) { testServer.getServerState(); return true; } } catch (Throwable t) { // assume server is not running } return false; }
break; InvokerLocator clientLocator = new InvokerLocator(connection.getURI()); server = (MageServer) TransporterClient.createTransporterClient(clientLocator.getLocatorURI(), MageServer.class, metadata); 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());
public void createRemotingClient(String locatorURI) throws Exception { client = new Client(new InvokerLocator(locatorURI)); client.connect(); }
public RemoteStrategyRemoting() throws Exception { String chatManagerUriString = Parameters.getParameter("chatManagerUri"); if (chatManagerUriString == null) chatManagerUriString = chatManagerLocatorDefault; InvokerLocator chatManagerLocator = new InvokerLocator(chatManagerUriString); managerClient = new Client(chatManagerLocator); managerClient.connect(); }
/** * @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(); } }
/** * Invokes the server invoker handler with the payload parameter passed. Same as calling * invoke(param, null); */ public Object invoke(Object param) throws Throwable { return invoke(param, null); }
@Override public Object invoke(final InvocationRequest invocation) throws Throwable { // Called for every client connecting to the server (after add Listener) String sessionId = invocation.getSessionId(); Map map = invocation.getRequestPayload(); String host; if (map != null) { InetAddress clientAddress = (InetAddress) invocation.getRequestPayload().get(Remoting.CLIENT_ADDRESS); host = clientAddress.getHostAddress(); } else { host = "localhost"; } Optional<Session> session = SessionManager.instance.getSession(sessionId); if (!session.isPresent()) { logger.error("Session not found : " + sessionId); } else { session.get().setHost(host); } return null; }
protected Client createClient(InvokerLocator locator, String subSystem) throws Exception { return new Client(locator, subSystem); } }
public static void destroyServerInvoker(ServerInvoker invoker) { if(invoker != null) { InvokerLocator locator = invoker.getLocator(); unregisterLocator(locator); } }
@Override public void handleConnectionException(Throwable throwable, Client client) { String sessionId = client.getSessionId(); Optional<Session> session = SessionManager.instance.getSession(sessionId); if (!session.isPresent()) { SessionManager.instance.disconnect(client.getSessionId(), DisconnectReason.LostConnection); logger.info("CLIENT DISCONNECTED - " + sessionInfo); logger.debug("Stack Trace", throwable); } else { SessionManager.instance.disconnect(client.getSessionId(), DisconnectReason.LostConnection); logger.info("LOST CONNECTION - " + sessionInfo); if (logger.isDebugEnabled()) {
public Home getHomeInUse() { if (homeInUse != null || isMultihome()) return homeInUse; return new Home(host, port); }
/** * narrow this invoker to a specific RemoteClientInvoker instance * * @return * @throws Exception */ public ClientInvoker narrow() throws Exception { return InvokerRegistry.createClientInvoker(this); }
/** * Gets the callbacks for specified callback handler. The handler is required because an id is * generated for each handler. So if have two callback handlers registered with the same server, * no other way to know for which handler to get the callbacks for. */ public List getCallbacks(InvokerCallbackHandler callbackHandler) throws Throwable { return getCallbacks(callbackHandler, null); }
/** * Removes specified connection listener. Will return true if it has already been registered, * false otherwise. */ public boolean removeConnectionListener(ConnectionListener listener) { if (connectionValidator == null) { return false; } return connectionValidator.removeConnectionListener(listener); }
public int acknowledgeCallback(InvokerCallbackHandler callbackHandler, Callback callback) throws Throwable { return acknowledgeCallback(callbackHandler, callback, null); }
if (cause instanceof InvocationFailureException) { InvocationFailureException exep = (InvocationFailureException) cause; if (exep.getCause() instanceof IOException) { if (exep.getCause().getMessage().startsWith("Field hash null is not available on current") || exep.getCause().getMessage().endsWith("end of file")) { addMessage = "Probably the server version is not compatible with the client. ";
/** * Constructor requiring the locator url back to the client's * StreamServer connector (actually the connector's server invoker). * * @param locatorURL * @throws Exception */ //private StreamHandler(String locatorURL) throws Exception public StreamHandler(String locatorURL) throws Exception { streamServerLocator = new InvokerLocator(locatorURL); streamClient = new Client(streamServerLocator); streamClient.connect(); }
/** * Returns an InetAddress for the client machine as seen by the server machine. * @return an InetAddress for the client machine as seen by the server machine. * @throws Throwable */ public InetAddress getAddressSeenByServer() throws Throwable { return (InetAddress) invoke("$GET_CLIENT_LOCAL_ADDRESS$"); }