Search in sources :

Example 1 with RunResult

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();
    }
}
Also used : InvocationType(org.jboss.as.ee.component.interceptors.InvocationType) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) RunResult(org.wildfly.extension.requestcontroller.RunResult)

Example 2 with RunResult

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));
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) ManagedReference(org.jboss.as.naming.ManagedReference) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) InjectionSource(org.jboss.as.ee.component.InjectionSource) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) Injector(org.jboss.msc.inject.Injector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) RunResult(org.wildfly.extension.requestcontroller.RunResult) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 3 with RunResult

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);
        }
    }
}
Also used : ServletRequestContext(io.undertow.servlet.handlers.ServletRequestContext) RunResult(org.wildfly.extension.requestcontroller.RunResult) Predicate(io.undertow.predicate.Predicate)

Aggregations

RunResult (org.wildfly.extension.requestcontroller.RunResult)3 ControlPoint (org.wildfly.extension.requestcontroller.ControlPoint)2 Predicate (io.undertow.predicate.Predicate)1 ServletRequestContext (io.undertow.servlet.handlers.ServletRequestContext)1 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 InjectionSource (org.jboss.as.ee.component.InjectionSource)1 InvocationType (org.jboss.as.ee.component.interceptors.InvocationType)1 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)1 RemoteViewInjectionSource (org.jboss.as.ejb3.remote.RemoteViewInjectionSource)1 RemoteViewManagedReferenceFactory (org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory)1 ManagedReference (org.jboss.as.naming.ManagedReference)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 Injector (org.jboss.msc.inject.Injector)1 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)1 ServiceName (org.jboss.msc.service.ServiceName)1 InjectedValue (org.jboss.msc.value.InjectedValue)1