use of org.jboss.ejb.client.SessionID in project wildfly by wildfly.
the class StatefulComponentSessionIdGeneratingInterceptor method processInvocation.
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
final Component component = context.getPrivateData(Component.class);
if (component instanceof StatefulSessionComponent == false) {
throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
}
ComponentClientInstance clientInstance = context.getPrivateData(ComponentClientInstance.class);
SessionID existing = context.getPrivateData(SessionID.class);
if (existing != null) {
clientInstance.setViewInstanceData(SessionID.class, existing);
} else {
StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
statefulComponent.waitForComponentStart();
StatefulSessionComponentInstance statefulSessionComponentInstance = statefulComponent.getCache().create();
clientInstance.setViewInstanceData(SessionID.class, statefulSessionComponentInstance.getId());
}
// move to the next interceptor in chain
return context.proceed();
}
use of org.jboss.ejb.client.SessionID in project wildfly by wildfly.
the class StatefulRemoteViewInstanceFactory method createViewInstance.
@Override
public ManagedReference createViewInstance(final ComponentView componentView, final Map<Object, Object> contextData) throws Exception {
SessionID sessionID = (SessionID) contextData.get(SessionID.class);
final StatefulEJBLocator<?> statefulEJBLocator;
final StatefulSessionComponent statefulSessionComponent = (StatefulSessionComponent) componentView.getComponent();
if (sessionID == null) {
statefulEJBLocator = EJBClient.createSession(StatelessEJBLocator.create(componentView.getViewClass(), identifier, Affinity.LOCAL));
} else {
statefulEJBLocator = StatefulEJBLocator.create(componentView.getViewClass(), identifier, sessionID, statefulSessionComponent.getCache().getStrictAffinity());
}
final Object ejbProxy = EJBClient.createProxy(statefulEJBLocator);
return new ValueManagedReference(new ImmediateValue<Object>(ejbProxy));
}
use of org.jboss.ejb.client.SessionID in project wildfly by wildfly.
the class StatefulRemoveInterceptor method processInvocation.
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
final Component component = context.getPrivateData(Component.class);
//if a session bean is participating in a transaction, it
//is an error for a client to invoke the remove method
//on the session object's home or component interface.
final ComponentView view = context.getPrivateData(ComponentView.class);
if (view != null) {
Ejb2xViewType viewType = view.getPrivateData(Ejb2xViewType.class);
if (viewType != null) {
//this means it is an EJB 2.x view
//which is not allowed to remove while enrolled in a TX
final StatefulTransactionMarker marker = context.getPrivateData(StatefulTransactionMarker.class);
if (marker != null && !marker.isFirstInvocation()) {
throw EjbLogger.ROOT_LOGGER.cannotRemoveWhileParticipatingInTransaction();
}
}
}
// just log a WARN and throw back the original exception
if (component instanceof StatefulSessionComponent == false) {
throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
}
final StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
Object invocationResult = null;
try {
// proceed
invocationResult = context.proceed();
} catch (Exception e) {
// then just throw back the exception and don't remove the session instance.
if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod()) && this.retainIfException) {
throw e;
}
// otherwise, just remove it and throw back the original exception
final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
final SessionID sessionId = statefulComponentInstance.getId();
statefulComponent.removeSession(sessionId);
throw e;
}
final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
final SessionID sessionId = statefulComponentInstance.getId();
// just remove the session because of a call to @Remove method
statefulComponent.removeSession(sessionId);
// return the invocation result
return invocationResult;
}
use of org.jboss.ejb.client.SessionID in project wildfly by wildfly.
the class StatefulIdentityInterceptor method processInvocation.
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
if (context.getMethod().getName().equals("equals") || context.getMethod().getName().equals("isIdentical")) {
final Object other = context.getParameters()[0];
final ComponentView componentView = context.getPrivateData(ComponentView.class);
final Class<?> proxyType = componentView.getProxyClass();
final SessionID sessionId = context.getPrivateData(SessionID.class);
if (proxyType.isAssignableFrom(other.getClass())) {
//SessionIdHolder as the other side
return other.equals(new SessionIdHolder(sessionId));
} else if (other instanceof SessionIdHolder) {
return sessionId.equals(((SessionIdHolder) other).sessionId);
} else {
return false;
}
} else if (context.getMethod().getName().equals("hashCode")) {
final SessionID sessionId = context.getPrivateData(SessionID.class);
//use the identity of the component view as a hash code
return sessionId.hashCode();
} else {
return context.proceed();
}
}
use of org.jboss.ejb.client.SessionID 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();
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 (Exception t) {
EjbLogger.REMOTE_LOGGER.exceptionGeneratingSessionId(t, statefulSessionComponent.getComponentName(), ejbIdentifier);
sessionOpenRequest.writeException(t);
return;
}
sessionOpenRequest.convertToStateful(sessionID);
};
execute(sessionOpenRequest, runnable, false);
return ignored -> cancelled.set(true);
}
Aggregations