final EJBLocator<?> locator = context.getLocator(); if (locator.getAffinity() == Affinity.NONE) { final Affinity targetAffinity = context.getTargetAffinity(); if (targetAffinity != null) { context.setLocator(locator.withNewAffinity(targetAffinity)); } else { final URI destination = context.getDestination(); if (destination != null) { context.setLocator(locator.withNewAffinity(URIAffinity.forUri(destination))); if (locator.getAffinity() instanceof ClusterAffinity && context.getWeakAffinity() == Affinity.NONE) { final Affinity targetAffinity = context.getTargetAffinity(); if (targetAffinity != null) { context.setWeakAffinity(targetAffinity); } else { final URI destination = context.getDestination(); if (destination != null) { context.setWeakAffinity(URIAffinity.forUri(destination));
<T> EJBSessionCreationInvocationContext createSessionCreationInvocationContext(StatelessEJBLocator<T> statelessLocator, AuthenticationContext authenticationContext) { EJBClientContext.InterceptorList interceptorList = getInterceptors(statelessLocator.getViewType()); return new EJBSessionCreationInvocationContext(statelessLocator, this, authenticationContext, interceptorList); }
public SessionID handleSessionCreation(final EJBSessionCreationInvocationContext context) throws Exception { final NamingProvider namingProvider = context.getAttachment(Keys.NAMING_PROVIDER_ATTACHMENT_KEY); if (namingProvider == null || context.getDestination() != null || context.getLocator().getAffinity() != Affinity.NONE) { return context.proceed(); } else { if (setDestination(context, namingProvider)) try { return context.proceed(); } catch (NoSuchEJBException | RequestSendFailedException e) { processMissingTarget(context); throw e; } else { throw Logs.INVOCATION.noMoreDestinations(); } } }
public SessionID handleSessionCreation(final EJBSessionCreationInvocationContext context) throws Exception { ConcurrentMap<Application, URI> applications = context.getAttachment(APPLICATIONS); if (applications != null) { URI destination = context.getDestination(); Application registered = updateOrFollowApplication(context, applications, false); try { return context.proceed(); } catch (NoSuchEJBException | RequestSendFailedException e) { if (registered != null) { // Clear sticky association only if this path registered it applications.remove(registered, destination); } throw e; } finally { context.removeAttachment(APPLICATIONS); context.removeAttachment(PREFERRED_DESTINATIONS); } } return context.proceed(); }
/** * Proceed with the next interceptor in the chain, calling the resolved receiver in the end. * * @return the session ID (not {@code null}) * @throws Exception if the EJB session creation failed for some reason */ public SessionID proceed() throws Exception { final int idx = interceptorChainIndex++; try { final EJBClientInterceptorInformation[] chain = interceptorList.getInformation(); if (idx > chain.length) { throw Assert.unreachableCode(); } if (chain.length == idx) { final URI destination = getDestination(); final EJBReceiver receiver = getClientContext().resolveReceiver(destination, getLocator()); setReceiver(receiver); final SessionID sessionID = receiver.createSession(new EJBReceiverSessionCreationContext(this, authenticationContext)); if (sessionID == null) { throw Logs.INVOCATION.nullSessionID(receiver, getLocator().asStateless()); } retry = false; return sessionID; } else { return chain[idx].getInterceptorInstance().handleSessionCreation(this); } } finally { interceptorChainIndex --; } }
<T> StatefulEJBLocator<T> createSession(final EJBSessionCreationInvocationContext context, final StatelessEJBLocator<T> statelessLocator, final NamingProvider namingProvider) throws Exception { if (namingProvider != null) context.putAttachment(Keys.NAMING_PROVIDER_ATTACHMENT_KEY, namingProvider); Throwable t; try { sessionID = context.proceed(); break; } catch (RequestSendFailedException r) { if (! context.shouldRetry()) { throw o; if (! context.shouldRetry()) { Exception e = new RequestSendFailedException(o.getClass().getSimpleName() + ": " + o.getMessage(), o.getCause()); e.setStackTrace(o.getStackTrace()); final Affinity affinity = context.getLocator().getAffinity();
protected SessionID createSession(final EJBReceiverSessionCreationContext context) throws Exception { final StatelessEJBLocator<?> statelessLocator = context.getClientInvocationContext().getLocator().asStateless(); final AuthenticationContext authenticationContext = context.getAuthenticationContext(); try { IoFuture<ConnectionPeerIdentity> futureConnection = getConnection(context.getClientInvocationContext(), context.getClientInvocationContext().getDestination(), authenticationContext); final ConnectionPeerIdentity identity = futureConnection.getInterruptibly(); final EJBClientChannel ejbClientChannel = getClientChannel(identity.getConnection()); final StatefulEJBLocator<?> result = ejbClientChannel.openSession(statelessLocator, identity, context.getClientInvocationContext()); return result.getSessionId(); } catch (IOException e) { final RequestSendFailedException failed = new RequestSendFailedException("Failed to create stateful EJB: " + e.getMessage(), true); failed.initCause(e); throw failed; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new CreateException("Stateful EJB creation interrupted"); } }
@Override public SessionID handleSessionCreation(EJBSessionCreationInvocationContext context) throws Exception { AbstractTransaction transaction = context.getTransaction(); // While session requests currently only utilize the caller thread, // this will support any future use of a worker. Additionally hides // TX from other interceptors, providing consistency with standard // invocation handling. if (transaction == null) { transaction = transactionManager.getTransaction(); context.setTransaction(transaction); } setupStickinessIfRequired(context, true, transaction); Transaction old = transactionManager.suspend(); try { return context.proceed(); } finally { transactionManager.resume(old); } }
public SessionID handleSessionCreation(final EJBSessionCreationInvocationContext context) throws Exception { if (context.getDestination() != null) { // already discovered! return context.proceed(); } List<Throwable> problems = executeDiscovery(context); if(WILDFLY_TESTSUITE_HACK && context.getDestination() == null) { Thread.sleep(2000); problems = executeDiscovery(context); } SessionID sessionID; try { sessionID = context.proceed(); } catch (NoSuchEJBException | RequestSendFailedException e) { processMissingTarget(context); throw withSuppressed(e, problems); } catch (Exception t) { throw withSuppressed(t, problems); } setupSessionAffinities(context); return sessionID; }
/** * Optionally handle a session creation invocation. Explicit session creation is always a blocking operation. The * default operation forwards to the next interceptor in the chain. * * @param context the session creation invocation context (not {@code null}) * @return the stateful EJB locator (must not be {@code null}) * @throws Exception if an invocation error occurred */ default SessionID handleSessionCreation(EJBSessionCreationInvocationContext context) throws Exception { return context.proceed(); }
protected SessionID createSession(final EJBReceiverSessionCreationContext receiverContext) throws Exception { final StatelessEJBLocator<?> statelessLocator = receiverContext.getClientInvocationContext().getLocator().asStateless(); final EjbDeploymentInformation ejbInfo = findBean(statelessLocator); final EJBComponent component = ejbInfo.getEjbComponent(); if (!(component instanceof StatefulSessionComponent)) { throw EjbLogger.ROOT_LOGGER.notStatefulSessionBean(statelessLocator.getAppName(), statelessLocator.getModuleName(), statelessLocator.getDistinctName(), statelessLocator.getBeanName()); } component.waitForComponentStart(); return ((StatefulSessionComponent) component).createSession(); }
public <T> StatefulEJBLocator<T> openSession(final StatelessEJBLocator<T> statelessLocator, final ConnectionPeerIdentity identity, EJBSessionCreationInvocationContext clientInvocationContext) throws Exception { SessionOpenInvocation<T> invocation = invocationTracker.addInvocation(id -> new SessionOpenInvocation<>(id, statelessLocator, clientInvocationContext)); try (MessageOutputStream out = invocationTracker.allocateMessage()) { out.write(Protocol.OPEN_SESSION_REQUEST); out.writeShort(invocation.getIndex()); writeRawIdentifier(statelessLocator, out); if (version >= 3) { out.writeInt(identity.getId()); invocation.setOutflowHandle(writeTransaction(clientInvocationContext.getTransaction(), out)); } } catch (IOException e) { CreateException createException = new CreateException(e.getMessage()); createException.initCause(e); throw createException; } // await the response return invocation.getResult(); }
static <T> T createSessionProxy(final StatelessEJBLocator<T> statelessLocator, Supplier<AuthenticationContext> authenticationContextSupplier, NamingProvider namingProvider) throws Exception { final EJBClientContext clientContext = EJBClientContext.getCurrent(); // this is the auth context to use just for the invocation final AuthenticationContext authenticationContext; if (authenticationContextSupplier != null) { authenticationContext = authenticationContextSupplier.get(); } else { authenticationContext = AuthenticationContext.captureCurrent(); } final EJBSessionCreationInvocationContext context = clientContext.createSessionCreationInvocationContext(statelessLocator, authenticationContext); final StatefulEJBLocator<T> statefulLocator = clientContext.createSession(context, statelessLocator, namingProvider); final T proxy = createProxy(statefulLocator, authenticationContextSupplier); final Affinity weakAffinity = context.getWeakAffinity(); if (weakAffinity != null && Affinity.NONE != weakAffinity) { setWeakAffinity(proxy, weakAffinity); } return proxy; }
/** * Proceed with the next interceptor in the chain, calling the resolved receiver in the end. * * @return the session ID (not {@code null}) * @throws Exception if the EJB session creation failed for some reason */ public SessionID proceed() throws Exception { final int idx = interceptorChainIndex++; try { final EJBClientInterceptorInformation[] chain = interceptorList.getInformation(); if (idx > chain.length) { throw Assert.unreachableCode(); } if (chain.length == idx) { final URI destination = getDestination(); final EJBReceiver receiver = getClientContext().resolveReceiver(destination, getLocator()); setReceiver(receiver); final SessionID sessionID = receiver.createSession(new EJBReceiverSessionCreationContext(this, authenticationContext)); if (sessionID == null) { throw Logs.INVOCATION.nullSessionID(receiver, getLocator().asStateless()); } retry = false; return sessionID; } else { return chain[idx].getInterceptorInstance().handleSessionCreation(this); } } finally { interceptorChainIndex --; } }
<T> StatefulEJBLocator<T> createSession(final EJBSessionCreationInvocationContext context, final StatelessEJBLocator<T> statelessLocator, final NamingProvider namingProvider) throws Exception { if (namingProvider != null) context.putAttachment(Keys.NAMING_PROVIDER_ATTACHMENT_KEY, namingProvider); Throwable t; try { sessionID = context.proceed(); break; } catch (RequestSendFailedException r) { if (! context.shouldRetry()) { throw o; if (! context.shouldRetry()) { Exception e = new RequestSendFailedException(o.getClass().getSimpleName() + ": " + o.getMessage(), o.getCause()); e.setStackTrace(o.getStackTrace()); final Affinity affinity = context.getLocator().getAffinity();
public SessionID handleSessionCreation(final EJBSessionCreationInvocationContext context) throws Exception { ConcurrentMap<Application, URI> applications = context.getAttachment(APPLICATIONS); if (applications != null) { URI destination = context.getDestination(); Application registered = updateOrFollowApplication(context, applications, false); try { return context.proceed(); } catch (NoSuchEJBException | RequestSendFailedException e) { if (registered != null) { // Clear sticky association only if this path registered it applications.remove(registered, destination); } throw e; } finally { context.removeAttachment(APPLICATIONS); context.removeAttachment(PREFERRED_DESTINATIONS); } } return context.proceed(); }
protected SessionID createSession(final EJBReceiverSessionCreationContext receiverContext) throws Exception { final EJBLocator<?> locator = receiverContext.getClientInvocationContext().getLocator(); URI uri = receiverContext.getClientInvocationContext().getDestination(); final AuthenticationContext context = receiverContext.getAuthenticationContext(); final AuthenticationContextConfigurationClient client = CLIENT;
@Override public SessionID handleSessionCreation(EJBSessionCreationInvocationContext context) throws Exception { AbstractTransaction transaction = context.getTransaction(); // While session requests currently only utilize the caller thread, // this will support any future use of a worker. Additionally hides // TX from other interceptors, providing consistency with standard // invocation handling. if (transaction == null) { transaction = transactionManager.getTransaction(); context.setTransaction(transaction); } setupStickinessIfRequired(context, true, transaction); Transaction old = transactionManager.suspend(); try { return context.proceed(); } finally { transactionManager.resume(old); } }
public SessionID handleSessionCreation(final EJBSessionCreationInvocationContext context) throws Exception { if (context.getDestination() != null) { // already discovered! return context.proceed(); } List<Throwable> problems = executeDiscovery(context); if(WILDFLY_TESTSUITE_HACK && context.getDestination() == null) { Thread.sleep(2000); problems = executeDiscovery(context); } SessionID sessionID; try { sessionID = context.proceed(); } catch (NoSuchEJBException | RequestSendFailedException e) { processMissingTarget(context); throw withSuppressed(e, problems); } catch (Exception t) { throw withSuppressed(t, problems); } setupSessionAffinities(context); return sessionID; }
public SessionID handleSessionCreation(final EJBSessionCreationInvocationContext context) throws Exception { try { return context.proceed(); } catch (NoSuchEJBException e) { // EJB is not present on target node! removeNode(context); throw e; } }