use of org.wildfly.extension.requestcontroller.RunResult in project wildfly by wildfly.
the class EjbSuspendInterceptor method processInvocation.
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
InvocationType invocation = context.getPrivateData(InvocationType.class);
if (invocation != InvocationType.REMOTE && invocation != InvocationType.MESSAGE_DELIVERY) {
return context.proceed();
}
// see if control point accepts or rejects this invocation
EJBComponent component = getComponent(context, EJBComponent.class);
ControlPoint entryPoint = component.getControlPoint();
RunResult result = entryPoint.beginRequest();
if (result == RunResult.REJECTED && !component.getEjbSuspendHandlerService().acceptInvocation(context)) {
// if control point rejected, check with suspend handler
throw EjbLogger.ROOT_LOGGER.containerSuspended();
}
try {
return context.proceed();
} finally {
if (result == RunResult.REJECTED)
component.getEjbSuspendHandlerService().invocationComplete();
else
entryPoint.requestComplete();
}
}
use of org.wildfly.extension.requestcontroller.RunResult in project wildfly by wildfly.
the class EjbJndiBindingsDeploymentUnitProcessor method registerControlPointBinding.
private void registerControlPointBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName, final DeploymentUnit deploymentUnit) {
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
final InjectedValue<ControlPoint> controlPointInjectedValue = new InjectedValue<>();
final RemoteViewInjectionSource delegate = new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
final ServiceName depName = ControlPointService.serviceName(deploymentUnit.getParent() == null ? deploymentUnit.getName() : deploymentUnit.getParent().getName(), EJBComponentSuspendDeploymentUnitProcessor.ENTRY_POINT_NAME + deploymentUnit.getName() + "." + componentDescription.getComponentName());
componentDescription.getConfigurators().add((context, description, configuration) -> {
viewClassLoader.setValue(Values.immediateValue(configuration.getModuleClassLoader()));
configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.addDependency(depName, ControlPoint.class, controlPointInjectedValue));
});
// we need to wrap the injection source to allow graceful shutdown to function, although this is not ideal
// as it will also reject local lookups as well, although in general local code should never be looking up the
// exported bindings
// the other option would be to reject it at the remote naming service level, however then we loose the per-deployment granularity
final InjectionSource is = new InjectionSource() {
@Override
public void getResourceValue(ResolutionContext resolutionContext, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final InjectedValue<ManagedReferenceFactory> delegateInjection = new InjectedValue<>();
delegate.getResourceValue(resolutionContext, serviceBuilder, phaseContext, delegateInjection);
injector.inject(new RemoteViewManagedReferenceFactory(moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient) {
@Override
public ManagedReference getReference() {
ControlPoint cp = controlPointInjectedValue.getValue();
try {
RunResult res = cp.beginRequest();
if (res != RunResult.RUN) {
throw EjbLogger.ROOT_LOGGER.containerSuspended();
}
try {
return delegateInjection.getValue().getReference();
} finally {
cp.requestComplete();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
};
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, is));
}
use of org.wildfly.extension.requestcontroller.RunResult in project wildfly by wildfly.
the class GlobalRequestControllerHandler method handleRequest.
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
RunResult result = entryPoint.beginRequest();
try {
if (result == RunResult.RUN) {
next.handleRequest(exchange);
} else {
boolean allowed = false;
for (Predicate allow : allowSuspendedRequests) {
if (allow.resolve(exchange)) {
allowed = true;
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (src != null) {
src.getServletRequest().setAttribute(ORG_WILDFLY_SUSPENDED, "true");
}
next.handleRequest(exchange);
break;
}
}
if (!allowed) {
exchange.setStatusCode(503);
exchange.endExchange();
}
}
} finally {
if (result == RunResult.RUN && (exchange.isComplete() || !exchange.isDispatched())) {
entryPoint.requestComplete();
} else if (result == RunResult.RUN) {
exchange.addExchangeCompleteListener(listener);
}
}
}
Aggregations