Search in sources :

Example 1 with NotNull

use of org.wildfly.common.annotation.NotNull in project wildfly by wildfly.

the class AssociationImpl method receiveSessionOpenRequest.

@Override
@NotNull
public CancelHandle receiveSessionOpenRequest(@NotNull final SessionOpenRequest sessionOpenRequest) {
    final EJBIdentifier ejbIdentifier = sessionOpenRequest.getEJBIdentifier();
    final String appName = ejbIdentifier.getAppName();
    final String moduleName = ejbIdentifier.getModuleName();
    final String beanName = ejbIdentifier.getBeanName();
    final String distinctName = ejbIdentifier.getDistinctName();
    final EjbDeploymentInformation ejbDeploymentInformation = findEJB(appName, moduleName, distinctName, beanName);
    if (ejbDeploymentInformation == null) {
        sessionOpenRequest.writeNoSuchEJB();
        return CancelHandle.NULL;
    }
    final Component component = ejbDeploymentInformation.getEjbComponent();
    component.waitForComponentStart();
    if (!(component instanceof StatefulSessionComponent)) {
        sessionOpenRequest.writeNotStateful();
        return CancelHandle.NULL;
    }
    final StatefulSessionComponent statefulSessionComponent = (StatefulSessionComponent) component;
    // generate the session id and write out the response, possibly on a separate thread
    final AtomicBoolean cancelled = new AtomicBoolean();
    Runnable runnable = () -> {
        if (cancelled.get()) {
            sessionOpenRequest.writeCancelResponse();
            return;
        }
        final SessionID sessionID;
        try {
            sessionID = statefulSessionComponent.createSessionRemote();
        } catch (EJBComponentUnavailableException ex) {
            // if the Jakarta Enterprise Beans are shutting down when the invocation was done, then it's as good as the Jakarta Enterprise Beans not being available. The client has to know about this as
            // a "no such Jakarta Enterprise Beans" failure so that it can retry the invocation on a different node if possible.
            EjbLogger.EJB3_INVOCATION_LOGGER.debugf("Cannot handle session creation on bean: %s due to Jakarta Enterprise Beans component unavailability exception. Returning a no such Jakarta Enterprise Beans available message back to client", beanName);
            sessionOpenRequest.writeNoSuchEJB();
            return;
        } catch (ComponentIsStoppedException ex) {
            EjbLogger.EJB3_INVOCATION_LOGGER.debugf("Cannot handle session creation on bean: %s due to Jakarta Enterprise Beans component stopped exception. Returning a no such Jakarta Enterprise Beans available message back to client", beanName);
            sessionOpenRequest.writeNoSuchEJB();
            return;
        // TODO should we write a specifc response with a specific protocol letting client know that server is suspending?
        } catch (Exception t) {
            EjbLogger.REMOTE_LOGGER.exceptionGeneratingSessionId(t, statefulSessionComponent.getComponentName(), ejbIdentifier);
            sessionOpenRequest.writeException(t);
            return;
        }
        // do not update strongAffinity when it is of type NodeAffinity; this will be achieved on the client in DiscoveryInterceptor via targetAffinity
        Affinity strongAffinity = getStrongAffinity(statefulSessionComponent);
        if (strongAffinity != null && !(strongAffinity instanceof NodeAffinity)) {
            sessionOpenRequest.updateStrongAffinity(strongAffinity);
        }
        Affinity weakAffinity = getWeakAffinity(statefulSessionComponent, sessionID);
        if (weakAffinity != null && !Affinity.NONE.equals(weakAffinity)) {
            sessionOpenRequest.updateWeakAffinity(weakAffinity);
        }
        EjbLogger.EJB3_INVOCATION_LOGGER.debugf("Called receiveSessionOpenRequest ( bean = %s ): strong affinity = %s, weak affinity = %s \n", statefulSessionComponent.getClass().getName(), strongAffinity, weakAffinity);
        sessionOpenRequest.convertToStateful(sessionID);
    };
    execute(sessionOpenRequest, runnable, false, true);
    return ignored -> cancelled.set(true);
}
Also used : Arrays(java.util.Arrays) ClusterAffinity(org.jboss.ejb.client.ClusterAffinity) DeploymentRepositoryListener(org.jboss.as.ejb3.deployment.DeploymentRepositoryListener) SocketAddress(java.net.SocketAddress) NotNull(org.wildfly.common.annotation.NotNull) ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) ClusterTopologyListener(org.jboss.ejb.server.ClusterTopologyListener) SessionBeanComponent(org.jboss.as.ejb3.component.session.SessionBeanComponent) InetAddress(java.net.InetAddress) Future(java.util.concurrent.Future) EJBComponentUnavailableException(org.jboss.as.ejb3.component.EJBComponentUnavailableException) Map(java.util.Map) Affinity(org.jboss.ejb.client.Affinity) SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) InvocationRequest(org.jboss.ejb.server.InvocationRequest) Method(java.lang.reflect.Method) StatefulSessionComponent(org.jboss.as.ejb3.component.stateful.StatefulSessionComponent) Registry(org.wildfly.clustering.registry.Registry) CancellationException(java.util.concurrent.CancellationException) Group(org.wildfly.clustering.group.Group) StatefulEJBLocator(org.jboss.ejb.client.StatefulEJBLocator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ProtocolSocketBinding(org.jboss.as.network.ProtocolSocketBinding) InterceptorContext(org.jboss.invocation.InterceptorContext) InetSocketAddress(java.net.InetSocketAddress) ClientMapping(org.jboss.as.network.ClientMapping) EJBException(javax.ejb.EJBException) ModuleAvailabilityListener(org.jboss.ejb.server.ModuleAvailabilityListener) Registration(org.wildfly.clustering.Registration) RegistryListener(org.wildfly.clustering.registry.RegistryListener) List(java.util.List) WildFlySecurityManager(org.wildfly.security.manager.WildFlySecurityManager) EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) EJBModuleIdentifier(org.jboss.ejb.client.EJBModuleIdentifier) EJBLocator(org.jboss.ejb.client.EJBLocator) Request(org.jboss.ejb.server.Request) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ComponentIsStoppedException(org.jboss.as.ee.component.ComponentIsStoppedException) HashMap(java.util.HashMap) EJBIdentifier(org.jboss.ejb.client.EJBIdentifier) ArrayList(java.util.ArrayList) StatelessSessionComponent(org.jboss.as.ejb3.component.stateless.StatelessSessionComponent) DeploymentRepository(org.jboss.as.ejb3.deployment.DeploymentRepository) SessionOpenRequest(org.jboss.ejb.server.SessionOpenRequest) CancellationFlag(org.jboss.as.ejb3.component.interceptors.CancellationFlag) Executor(java.util.concurrent.Executor) Association(org.jboss.ejb.server.Association) ComponentView(org.jboss.as.ee.component.ComponentView) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NodeAffinity(org.jboss.ejb.client.NodeAffinity) InvocationType(org.jboss.as.ee.component.interceptors.InvocationType) EJBMethodLocator(org.jboss.ejb.client.EJBMethodLocator) SessionID(org.jboss.ejb.client.SessionID) EjbLogger(org.jboss.as.ejb3.logging.EjbLogger) ListenerHandle(org.jboss.ejb.server.ListenerHandle) EJBClientInvocationContext(org.jboss.ejb.client.EJBClientInvocationContext) Component(org.jboss.as.ee.component.Component) CancelHandle(org.jboss.ejb.server.CancelHandle) Collections(java.util.Collections) EJBComponentUnavailableException(org.jboss.as.ejb3.component.EJBComponentUnavailableException) NodeAffinity(org.jboss.ejb.client.NodeAffinity) EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) StatefulSessionComponent(org.jboss.as.ejb3.component.stateful.StatefulSessionComponent) ComponentIsStoppedException(org.jboss.as.ee.component.ComponentIsStoppedException) EJBComponentUnavailableException(org.jboss.as.ejb3.component.EJBComponentUnavailableException) CancellationException(java.util.concurrent.CancellationException) EJBException(javax.ejb.EJBException) ComponentIsStoppedException(org.jboss.as.ee.component.ComponentIsStoppedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterAffinity(org.jboss.ejb.client.ClusterAffinity) Affinity(org.jboss.ejb.client.Affinity) NodeAffinity(org.jboss.ejb.client.NodeAffinity) SessionBeanComponent(org.jboss.as.ejb3.component.session.SessionBeanComponent) StatefulSessionComponent(org.jboss.as.ejb3.component.stateful.StatefulSessionComponent) StatelessSessionComponent(org.jboss.as.ejb3.component.stateless.StatelessSessionComponent) Component(org.jboss.as.ee.component.Component) EJBIdentifier(org.jboss.ejb.client.EJBIdentifier) SessionID(org.jboss.ejb.client.SessionID) NotNull(org.wildfly.common.annotation.NotNull)

Aggregations

IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CancellationException (java.util.concurrent.CancellationException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Executor (java.util.concurrent.Executor)1 Future (java.util.concurrent.Future)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EJBException (javax.ejb.EJBException)1 Component (org.jboss.as.ee.component.Component)1