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, outboundConnectionService.getProtocol());
context.registerEJBReceiver(ejbReceiver);
numRemotingReceivers++;
}
logger.debug("Added " + numRemotingReceivers + " remoting EJB receivers to descriptor based EJB client context " + startContext.getController().getName());
}