Search in sources :

Example 1 with SessionID

use of org.jboss.ejb.client.SessionID in project wildfly by wildfly.

the class EjbCorbaServant method prepareInterceptorContext.

private void prepareInterceptorContext(final SkeletonStrategy op, final Object[] params, final InterceptorContext interceptorContext) throws IOException, ClassNotFoundException {
    if (!home) {
        if (componentView.getComponent() instanceof StatefulSessionComponent) {
            final SessionID sessionID = (SessionID) unmarshalIdentifier();
            interceptorContext.putPrivateData(SessionID.class, sessionID);
        }
    }
    interceptorContext.setContextData(new HashMap<>());
    interceptorContext.setParameters(params);
    interceptorContext.setMethod(op.getMethod());
    interceptorContext.putPrivateData(ComponentView.class, componentView);
    interceptorContext.putPrivateData(Component.class, componentView.getComponent());
    interceptorContext.setTransaction(inboundTxCurrent == null ? null : inboundTxCurrent.getCurrentTransaction());
}
Also used : StatefulSessionComponent(org.jboss.as.ejb3.component.stateful.StatefulSessionComponent) SessionID(org.jboss.ejb.client.SessionID)

Example 2 with SessionID

use of org.jboss.ejb.client.SessionID in project wildfly by wildfly.

the class StatefulSessionSynchronizationInterceptorTestCase method testDifferentTx.

/**
     * After the bean is accessed within a tx and the tx has committed, the
     * association should be gone (and thus it is ready for another tx).
     */
@Test
public void testDifferentTx() throws Exception {
    final Interceptor interceptor = new StatefulSessionSynchronizationInterceptor(true);
    final InterceptorContext context = new InterceptorContext();
    context.setInterceptors(Arrays.asList(noop()));
    final StatefulSessionComponent component = mock(StatefulSessionComponent.class);
    context.putPrivateData(Component.class, component);
    when(component.getAccessTimeout(null)).thenReturn(defaultAccessTimeout());
    Cache<SessionID, StatefulSessionComponentInstance> cache = mock(Cache.class);
    when(component.getCache()).thenReturn(cache);
    final TransactionSynchronizationRegistry transactionSynchronizationRegistry = mock(TransactionSynchronizationRegistry.class);
    when(component.getTransactionSynchronizationRegistry()).thenReturn(transactionSynchronizationRegistry);
    when(transactionSynchronizationRegistry.getTransactionKey()).thenReturn("TX1");
    final List<Synchronization> synchronizations = new LinkedList<Synchronization>();
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Synchronization synchronization = (Synchronization) invocation.getArguments()[0];
            synchronizations.add(synchronization);
            return null;
        }
    }).when(transactionSynchronizationRegistry).registerInterposedSynchronization((Synchronization) any());
    final StatefulSessionComponentInstance instance = new StatefulSessionComponentInstance(component, org.jboss.invocation.Interceptors.getTerminalInterceptor(), Collections.EMPTY_MAP, Collections.emptyMap());
    context.putPrivateData(ComponentInstance.class, instance);
    interceptor.processInvocation(context);
    // commit
    for (Synchronization synchronization : synchronizations) {
        synchronization.beforeCompletion();
    }
    for (Synchronization synchronization : synchronizations) {
        synchronization.afterCompletion(Status.STATUS_COMMITTED);
    }
    synchronizations.clear();
    when(transactionSynchronizationRegistry.getTransactionKey()).thenReturn("TX2");
    interceptor.processInvocation(context);
}
Also used : Synchronization(javax.transaction.Synchronization) LinkedList(java.util.LinkedList) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InterceptorContext(org.jboss.invocation.InterceptorContext) Interceptor(org.jboss.invocation.Interceptor) SessionID(org.jboss.ejb.client.SessionID) Test(org.junit.Test)

Example 3 with SessionID

use of org.jboss.ejb.client.SessionID in project wildfly by wildfly.

the class InfinispanBeanEntryExternalizer method readObject.

@Override
public InfinispanBeanEntry<SessionID> readObject(ObjectInput input) throws IOException, ClassNotFoundException {
    InfinispanBeanEntry<SessionID> entry = new InfinispanBeanEntry<>(input.readUTF(), EXTERNALIZER.readObject(input));
    long time = input.readLong();
    if (time > 0) {
        entry.setLastAccessedTime(new Date(time));
    }
    return entry;
}
Also used : SessionID(org.jboss.ejb.client.SessionID) Date(java.util.Date)

Example 4 with SessionID

use of org.jboss.ejb.client.SessionID in project wildfly by wildfly.

the class KeyMapperTestCase method test.

@Test
public void test() {
    TwoWayKey2StringMapper mapper = new KeyMapper();
    Assert.assertTrue(mapper.isSupportedType(InfinispanBeanKey.class));
    Assert.assertTrue(mapper.isSupportedType(InfinispanBeanGroupKey.class));
    Set<String> formatted = new HashSet<>();
    SessionID id = new UUIDSessionID(UUID.randomUUID());
    BeanKey<SessionID> beanKey = new InfinispanBeanKey<>(id);
    String formattedBeanKey = mapper.getStringMapping(beanKey);
    Assert.assertEquals(beanKey, mapper.getKeyMapping(formattedBeanKey));
    Assert.assertTrue(formatted.add(formattedBeanKey));
    BeanGroupKey<SessionID> beanGroupKey = new InfinispanBeanGroupKey<>(id);
    String formattedBeanGroupKey = mapper.getStringMapping(beanGroupKey);
    Assert.assertEquals(beanGroupKey, mapper.getKeyMapping(formattedBeanGroupKey));
    Assert.assertTrue(formatted.add(formattedBeanGroupKey));
}
Also used : TwoWayKey2StringMapper(org.infinispan.persistence.keymappers.TwoWayKey2StringMapper) UUIDSessionID(org.jboss.ejb.client.UUIDSessionID) InfinispanBeanKey(org.wildfly.clustering.ejb.infinispan.bean.InfinispanBeanKey) InfinispanBeanGroupKey(org.wildfly.clustering.ejb.infinispan.group.InfinispanBeanGroupKey) UUIDSessionID(org.jboss.ejb.client.UUIDSessionID) SessionID(org.jboss.ejb.client.SessionID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with SessionID

use of org.jboss.ejb.client.SessionID in project wildfly by wildfly.

the class StatefulComponentInstanceInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
    StatefulSessionComponent component = getComponent(context, StatefulSessionComponent.class);
    // TODO: this is a contract with the client interceptor
    SessionID sessionId = context.getPrivateData(SessionID.class);
    if (sessionId == null) {
        throw EjbLogger.ROOT_LOGGER.statefulSessionIdIsNull(component.getComponentName());
    }
    ROOT_LOGGER.debugf("Looking for stateful component instance with session id: %s", sessionId);
    StatefulSessionComponentInstance instance = component.getCache().get(sessionId);
    if (instance == null) {
        //This exception will be transformed into the correct exception type by the exception transforming interceptor
        throw EjbLogger.ROOT_LOGGER.couldNotFindEjb(sessionId.toString());
    }
    try {
        context.putPrivateData(ComponentInstance.class, instance);
        return context.proceed();
    } catch (Exception ex) {
        if (component.shouldDiscard(ex, context.getMethod())) {
            ROOT_LOGGER.tracef(ex, "Removing bean %s because of exception", sessionId);
            instance.discard();
        }
        throw ex;
    } catch (final Error e) {
        ROOT_LOGGER.tracef(e, "Removing bean %s because of error", sessionId);
        instance.discard();
        throw e;
    } catch (final Throwable t) {
        ROOT_LOGGER.tracef(t, "Removing bean %s because of Throwable", sessionId);
        instance.discard();
        throw new RuntimeException(t);
    }
}
Also used : SessionID(org.jboss.ejb.client.SessionID)

Aggregations

SessionID (org.jboss.ejb.client.SessionID)11 Component (org.jboss.as.ee.component.Component)3 ComponentView (org.jboss.as.ee.component.ComponentView)3 StatefulSessionComponent (org.jboss.as.ejb3.component.stateful.StatefulSessionComponent)3 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)2 EjbDeploymentInformation (org.jboss.as.ejb3.deployment.EjbDeploymentInformation)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CancellationException (java.util.concurrent.CancellationException)1 Executor (java.util.concurrent.Executor)1