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()); }
@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); } } }
@Override public synchronized void start(StartContext startContext) throws StartException { // setup the context with the receivers final EJBClientContext context; if (this.clientContextClassloader != null) { context = EJBClientContext.create(this.ejbClientConfiguration, this.clientContextClassloader); } else { context = EJBClientContext.create(this.ejbClientConfiguration); } // add the (optional) local EJB receiver final LocalEjbReceiver localEjbReceiver = this.localEjbReceiverInjectedValue.getOptionalValue(); if (localEjbReceiver != null) { context.registerEJBReceiver(localEjbReceiver); logger.debug("Added a local EJB receiver to descriptor based EJB client context named " + startContext.getController().getName()); } // now process the remoting receivers this.registerRemotingEJBReceivers(startContext, context); // we now have a fully configured EJB client context for use this.ejbClientContext = context; }
@Override public synchronized void start(final StartContext context) throws StartException { final EJBClientContext clientContext = EJBClientContext.create(new LocalOnlyEjbClientConfiguration()); // register the default local EJB receiver (if present - app clients don't have local EJB receivers) final LocalEjbReceiver localEjbReceiver = this.defaultLocalEJBReceiver.getOptionalValue(); if (localEjbReceiver != null) { clientContext.registerEJBReceiver(localEjbReceiver); } this.context = clientContext; if (this.lockSelectorOnStart) { // lock the EJB client context selector AccessController.doPrivileged(new LockSelectorAction()); } // the EJBClientContext selector is set to DefaultEJBClientContextSelector and is *locked* once // (in a static block of this service) so that restarting this service will not cause failures related // to resetting the selector. The DefaultEJBClientContextSelector is backed by a TCCLEJBClientContextSelectorService // which is what we set here during the service start, so that the selector has the correct service to return the // EJBClientContext. @see https://issues.jboss.org/browse/AS7-2998 for details DefaultEJBClientContextSelector.INSTANCE.setup(this.tcclEJBClientContextSelector.getValue(), this.context); }