private EJBClientContext getContext(final Connection connection) { synchronized (contextByConnection) { EJBClientContext ret = contextByConnection.get(connection); if(ret == null) { ret = EJBClientContext.create(); ret.registerConnection(connection); contextByConnection.put(connection, ret); connection.addCloseHandler(new CloseHandler<Connection>() { @Override public void handleClose(final Connection connection, final IOException e) { synchronized (contextByConnection) { contextByConnection.remove(connection); } } }); } return ret; } } }
public static RemoteNamingStoreEJBClientHandler setupEJBClientContext(final Properties ejbClientProperties, final List<RemoteContext.CloseTask> closeTasks) { EJBClientConfiguration clientConfiguration = new PropertiesBasedEJBClientConfiguration(ejbClientProperties); final EJBClientContext ejbClientContext = EJBClientContext.create(clientConfiguration); final String ejbClientContextName = EJB_CLIENT_CONTEXT_NAME_PREFIX + nextEJBClientContextNumber.addAndGet(1); final EJBClientContextIdentifier ejbClientContextIdentifier = new NamedEJBClientContextIdentifier(ejbClientContextName); // register the context with the selector registerEJBClientContextWithSelector(ejbClientContextIdentifier, ejbClientContext); // add a close task which closes the EJB client context when the remote naming context is closed if (closeTasks != null) { closeTasks.add(new RemoteNamingEJBClientContextCloseTask(ejbClientContext)); } return new RemoteNamingStoreEJBClientHandler(ejbClientContextIdentifier, ejbClientContext); }
@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; }
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 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); }