public void bind(final ClientEndpoint endpoint) { final Connection conn = endpoint.getConnection(); if (conn instanceof TcpIpConnection) { Address address = new Address(conn.getRemoteSocketAddress()); ((TcpIpConnection) conn).setEndPoint(address); } ClientEvent event = new ClientEvent( endpoint.getUuid(), ClientEventType.CONNECTED, endpoint.getSocketAddress(), endpoint.getClientType()); sendClientEvent(event); }
@Override public void removeEndpoint(final ClientEndpoint ce, boolean closeImmediately) { checkNotNull(ce, "endpoint can't be null"); ClientEndpointImpl endpoint = (ClientEndpointImpl) ce; endpoints.remove(endpoint.getConnection()); logger.info("Destroying " + endpoint); try { endpoint.destroy(); } catch (LoginException e) { logger.warning(e); } final Connection connection = endpoint.getConnection(); if (closeImmediately) { try { connection.close(); } catch (Throwable e) { logger.warning("While closing client connection: " + connection, e); } } else { nodeEngine .getExecutionService() .schedule( new Runnable() { public void run() { if (connection.isAlive()) { try { connection.close(); } catch (Throwable e) { logger.warning("While closing client connection: " + e.toString()); } } } }, DESTROY_ENDPOINT_DELAY_MS, TimeUnit.MILLISECONDS); } ClientEvent event = new ClientEvent( endpoint.getUuid(), ClientEventType.DISCONNECTED, endpoint.getSocketAddress(), endpoint.getClientType()); clientEngine.sendClientEvent(event); }