@Override public void reconnect() throws IOException { Connection connection = null; try { final IoFuture<Connection> futureConnection = NetworkUtil.connect(endpoint, destinationHost, destinationPort, null, connectionCreationOptions, callbackHandler, null); connection = IoFutureHelper.get(futureConnection, connectionTimeout, TimeUnit.MILLISECONDS); logger.debug("Successfully reconnected to connection " + connection); } catch (Exception e) { logger.debug("Failed to re-connect to " + this.destinationHost + ":" + this.destinationPort, e); } if (connection == null) { return; } try { final EJBReceiver ejbReceiver = new RemotingConnectionEJBReceiver(connection, this, channelCreationOptions); RemotingConnectionClusterNodeManager.this.clusterContext.registerEJBReceiver(ejbReceiver); } finally { // if we successfully re-connected then unregister this ReconnectHandler from the EJBClientContext RemotingConnectionClusterNodeManager.this.clusterContext.getEJBClientContext().unregisterReconnectHandler(this); } } }
private void registerRemotingEJBReceivers(final StartContext startContext, final EJBClientContext context) { final ServiceRegistry serviceRegistry = startContext.getController().getServiceContainer(); int numRemotingReceivers = 0; for (final Map.Entry<ServiceName, InjectedValue<AbstractOutboundConnectionService>> entry : this.remotingOutboundConnections.entrySet()) { final InjectedValue<AbstractOutboundConnectionService> injectedValue = entry.getValue(); final AbstractOutboundConnectionService outboundConnectionService = injectedValue.getValue(); final String connectionName = outboundConnectionService.getConnectionName(); logger.debug("Creating remoting EJB receiver for connection " + connectionName); final long connectionTimeout = this.connectionTimeouts.get(connectionName) <= 0 ? DEFAULT_CONNECTION_TIMEOUT : this.connectionTimeouts.get(connectionName); final OptionMap options = this.channelCreationOpts.get(connectionName) == null ? OptionMap.EMPTY : this.channelCreationOpts.get(connectionName); Connection connection = null; final ReconnectHandler reconnectHandler = new OutboundConnectionReconnectHandler(serviceRegistry, entry.getKey(), context, connectionTimeout, options); try { final IoFuture<Connection> futureConnection = outboundConnectionService.connect(); connection = IoFutureHelper.get(futureConnection, connectionTimeout, TimeUnit.MILLISECONDS); } catch (Exception e) { // just log a message and register a reconnect handler logger.debug("Failed to create a connection for " + connectionName + ". A reconnect handler will be added to the client context", e); context.registerReconnectHandler(reconnectHandler); continue; } final RemotingConnectionEJBReceiver ejbReceiver = new RemotingConnectionEJBReceiver(connection, reconnectHandler, options); context.registerEJBReceiver(ejbReceiver); numRemotingReceivers++; } logger.debug("Added " + numRemotingReceivers + " remoting EJB receivers to descriptor based EJB client context " + startContext.getController().getName()); }
private synchronized void createConnection() { try { endpoint = Remoting.createEndpoint("endpoint", OptionMap.EMPTY); endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE)); // open a connection final IoFuture<Connection> futureConnection = endpoint.connect(new URI(hostUrl), OptionMap.create(Options.SASL_POLICY_NOANONYMOUS, Boolean.FALSE, Options.SASL_POLICY_NOPLAINTEXT, Boolean.FALSE), callbackHandler); connection = IoFutureHelper.get(futureConnection, 30L, TimeUnit.SECONDS); final EJBClientContext ejbClientContext = EJBClientContext.create(); ejbClientContext.registerConnection(connection); this.clientContext = ejbClientContext; } catch (IOException e) { throw new RuntimeException(e); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
@Override public void reconnect() throws IOException { this.reconnectAttemptCount++; final ServiceController serviceController = this.serviceRegistry.getService(this.outboundConnectionServiceName); if (serviceController == null) { // the outbound connection service is no longer available, so unregister this // reconnect handler from the EJB client context logger.debug("Unregistering " + this + " since " + this.outboundConnectionServiceName + " is no longer available"); this.clientContext.unregisterReconnectHandler(this); return; } final AbstractOutboundConnectionService outboundConnectionService = (AbstractOutboundConnectionService) serviceController.getValue(); try { final IoFuture<Connection> futureConnection = outboundConnectionService.connect(); final Connection connection = IoFutureHelper.get(futureConnection, connectionTimeout, TimeUnit.MILLISECONDS); logger.debug("Successful reconnect attempt#" + this.reconnectAttemptCount + " to outbound connection " + this.outboundConnectionServiceName); // successfully reconnected so unregister this reconnect handler this.clientContext.unregisterReconnectHandler(this); // register the newly reconnected connection final EJBReceiver receiver = new RemotingConnectionEJBReceiver(connection, this, channelCreationOpts); this.clientContext.registerEJBReceiver(receiver); } catch (Exception e) { logger.debug("Reconnect attempt#" + this.reconnectAttemptCount + " failed for outbound connection " + this.outboundConnectionServiceName, e); } } }
final IoFuture<Connection> futureConnection = NetworkUtil.connect(endpoint, destinationHost, destinationPort, null, connectionCreationOptions, callbackHandler, null); connection = IoFutureHelper.get(futureConnection, 5000, TimeUnit.MILLISECONDS); final long timeout = clusterNodeConfiguration == null ? clusterConfiguration.getConnectionTimeout() : clusterNodeConfiguration.getConnectionTimeout(); connection = IoFutureHelper.get(futureConnection, timeout, TimeUnit.MILLISECONDS); final IoFuture<Connection> futureConnection = NetworkUtil.connect(endpoint, destinationHost, destinationPort, null, connectionCreationOptions, callbackHandler, null); connection = IoFutureHelper.get(futureConnection, 5000, TimeUnit.MILLISECONDS);