use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class MessageDrivenComponentDescription method setupViewInterceptors.
@Override
protected void setupViewInterceptors(EJBViewDescription view) {
// let the super do its job
super.setupViewInterceptors(view);
view.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException {
//add the invocation type to the start of the chain
//TODO: is there a cleaner way to do this?
configuration.addViewInterceptor(new ImmediateInterceptorFactory(new Interceptor() {
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
context.putPrivateData(InvocationType.class, InvocationType.MESSAGE_DELIVERY);
return context.proceed();
}
}), InterceptorOrder.View.INVOCATION_TYPE);
// add the instance associating interceptor at the start of the interceptor chain
configuration.addViewInterceptor(MessageDrivenComponentInstanceAssociatingFactory.instance(), InterceptorOrder.View.ASSOCIATING_INTERCEPTOR);
final MessageDrivenComponentDescription mdb = (MessageDrivenComponentDescription) componentConfiguration.getComponentDescription();
if (mdb.getTransactionManagementType() == TransactionManagementType.CONTAINER) {
configuration.addViewInterceptor(CMTTxInterceptor.FACTORY, InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
}
}
});
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class CurrentInvocationContext method getEjbContext.
public static EJBContextImpl getEjbContext() {
final InterceptorContext context = get();
if (context == null) {
throw EjbLogger.ROOT_LOGGER.noEjbContextAvailable();
}
final ComponentInstance component = context.getPrivateData(ComponentInstance.class);
if (!(component instanceof EjbComponentInstance)) {
throw EjbLogger.ROOT_LOGGER.currentComponentNotAEjb(component);
}
return ((EjbComponentInstance) component).getEjbContext();
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class NonFunctionalTimerService method assertInvocationAllowed.
private void assertInvocationAllowed() {
AllowedMethodsInformation.checkAllowed(MethodType.TIMER_SERVICE_METHOD);
final InterceptorContext currentInvocationContext = CurrentInvocationContext.get();
if (currentInvocationContext == null) {
return;
}
// If the method in current invocation context is null,
// then it represents a lifecycle callback invocation
Method invokedMethod = currentInvocationContext.getMethod();
if (invokedMethod == null) {
// it's a lifecycle callback
Component component = currentInvocationContext.getPrivateData(Component.class);
if (!(component instanceof SingletonComponent)) {
throw EjbLogger.EJB3_TIMER_LOGGER.failToInvokeTimerServiceDoLifecycle();
}
}
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class TimedObjectInvokerImpl method callTimeout.
@Override
public void callTimeout(final TimerImpl timer, final Method timeoutMethod) throws Exception {
final Interceptor interceptor;
synchronized (this) {
if (!started) {
//this can happen if an invocation has been triggered as the deployment is shutting down
throw EjbLogger.EJB3_TIMER_LOGGER.timerInvocationFailedDueToInvokerNotBeingStarted();
}
interceptor = timeoutInterceptors.get(timeoutMethod);
}
if (interceptor == null) {
throw EjbLogger.EJB3_TIMER_LOGGER.failToInvokeTimeout(timeoutMethod);
}
final InterceptorContext context = new InterceptorContext();
context.setContextData(new HashMap<String, Object>());
context.setMethod(timeoutMethod);
if (timeoutMethod.getParameterTypes().length == 0) {
context.setParameters(new Object[0]);
} else {
final Object[] params = new Object[1];
params[0] = timer;
context.setParameters(params);
}
context.setTimer(timer);
context.putPrivateData(Component.class, ejbComponent.getValue());
context.putPrivateData(MethodIntf.class, MethodIntf.TIMER);
context.putPrivateData(InvocationType.class, InvocationType.TIMER);
interceptor.processInvocation(context);
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class TimerServiceImpl method isLifecycleCallbackInvocation.
/**
* Returns true if the {@link CurrentInvocationContext} represents a lifecycle
* callback invocation. Else returns false.
* <p>
* This method internally relies on {@link CurrentInvocationContext#get()} to obtain
* the current invocation context.
* <ul>
* <li>If the context is available then it looks for the method that was invoked.
* The absence of a method indicates a lifecycle callback.</li>
* <li>If the context is <i>not</i> available, then this method returns false (i.e.
* it doesn't consider the current invocation as a lifecycle callback). This is
* for convenience, to allow the invocation of {@link javax.ejb.TimerService} methods
* in the absence of {@link CurrentInvocationContext}</li>
* </ul>
* <p/>
* </p>
*
* @return
*/
protected boolean isLifecycleCallbackInvocation() {
final InterceptorContext currentInvocationContext = CurrentInvocationContext.get();
if (currentInvocationContext == null) {
return false;
}
// If the method in current invocation context is null,
// then it represents a lifecycle callback invocation
Method invokedMethod = currentInvocationContext.getMethod();
if (invokedMethod == null) {
// it's a lifecycle callback
return true;
}
// not a lifecycle callback
return false;
}
Aggregations