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());
}
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);
}
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;
}
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));
}
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);
}
}
Aggregations