Search in sources :

Example 6 with EJBComponent

use of org.jboss.as.ejb3.component.EJBComponent in project wildfly by wildfly.

the class LocalEjbReceiver method processInvocation.

@Override
protected void processInvocation(final EJBReceiverInvocationContext receiverContext) {
    final EJBClientInvocationContext invocation = receiverContext.getClientInvocationContext();
    final EJBLocator<?> locator = invocation.getLocator();
    final EjbDeploymentInformation ejb = findBean(locator);
    final EJBComponent ejbComponent = ejb.getEjbComponent();
    final Class<?> viewClass = invocation.getViewClass();
    final ComponentView view = ejb.getView(viewClass.getName());
    if (view == null) {
        throw EjbLogger.ROOT_LOGGER.viewNotFound(viewClass.getName(), ejb.getEjbName());
    }
    // make sure it's a remote view
    if (!ejb.isRemoteView(viewClass.getName())) {
        throw EjbLogger.ROOT_LOGGER.viewNotFound(viewClass.getName(), ejb.getEjbName());
    }
    final ClonerConfiguration paramConfig = new ClonerConfiguration();
    paramConfig.setClassCloner(new ClassLoaderClassCloner(ejb.getDeploymentClassLoader()));
    final ObjectCloner parameterCloner = createCloner(paramConfig);
    // TODO: this is not very efficient
    final Method method = view.getMethod(invocation.getInvokedMethod().getName(), DescriptorUtils.methodDescriptor(invocation.getInvokedMethod()));
    final boolean async = view.isAsynchronous(method) || invocation.isClientAsync();
    final Object[] parameters;
    if (invocation.getParameters() == null) {
        parameters = EMPTY_STRING_ARRAY;
    } else {
        parameters = new Object[invocation.getParameters().length];
        for (int i = 0; i < parameters.length; ++i) {
            parameters[i] = clone(method.getParameterTypes()[i], parameterCloner, invocation.getParameters()[i], allowPassByReference);
        }
    }
    final InterceptorContext interceptorContext = new InterceptorContext();
    interceptorContext.setParameters(parameters);
    interceptorContext.setMethod(method);
    interceptorContext.setTransaction(invocation.getTransaction());
    interceptorContext.setTarget(invocation.getInvokedProxy());
    // setup the context data in the InterceptorContext
    final Map<AttachmentKey<?>, ?> privateAttachments = invocation.getAttachments();
    final Map<String, Object> invocationContextData = invocation.getContextData();
    if (invocationContextData == null && privateAttachments.isEmpty()) {
        // no private or public data
        interceptorContext.setContextData(new HashMap<String, Object>());
    } else {
        final Map<String, Object> data = new HashMap<String, Object>();
        interceptorContext.setContextData(data);
        // write out public (application specific) context data
        if (invocationContextData != null)
            for (Map.Entry<String, Object> entry : invocationContextData.entrySet()) {
                data.put(entry.getKey(), entry.getValue());
            }
        if (!privateAttachments.isEmpty()) {
            // now write out the JBoss specific attachments under a single key and the value will be the
            // entire map of JBoss specific attachments
            data.put(EJBClientInvocationContext.PRIVATE_ATTACHMENTS_KEY, privateAttachments);
        }
        // Note: The code here is just for backward compatibility of 1.0.x version of Jakarta Enterprise Beans client project
        // against AS7 7.1.x releases. Discussion here https://github.com/jbossas/jboss-ejb-client/pull/11#issuecomment-6573863
        final boolean txIdAttachmentPresent = privateAttachments.containsKey(AttachmentKeys.TRANSACTION_ID_KEY);
        if (txIdAttachmentPresent) {
            // we additionally add/duplicate the transaction id under a different attachment key
            // to preserve backward compatibility. This is here just for 1.0.x backward compatibility
            data.put(TransactionID.PRIVATE_DATA_KEY, privateAttachments.get(AttachmentKeys.TRANSACTION_ID_KEY));
        }
    }
    interceptorContext.putPrivateData(Component.class, ejbComponent);
    interceptorContext.putPrivateData(ComponentView.class, view);
    if (locator.isStateful()) {
        interceptorContext.putPrivateData(SessionID.class, locator.asStateful().getSessionId());
    } else if (locator instanceof EntityEJBLocator) {
        throw EjbLogger.ROOT_LOGGER.ejbNotFoundInDeployment(locator);
    }
    final ClonerConfiguration config = new ClonerConfiguration();
    config.setClassCloner(new LocalInvocationClassCloner(WildFlySecurityManager.getClassLoaderPrivileged(invocation.getInvokedProxy().getClass())));
    final ObjectCloner resultCloner = createCloner(config);
    if (async) {
        if (ejbComponent instanceof SessionBeanComponent) {
            final CancellationFlag flag = new CancellationFlag();
            final SessionBeanComponent component = (SessionBeanComponent) ejbComponent;
            final boolean isAsync = view.isAsynchronous(method);
            final boolean oneWay = isAsync && method.getReturnType() == void.class;
            final boolean isSessionBean = view.getComponent() instanceof SessionBeanComponent;
            if (isAsync && isSessionBean && !oneWay) {
                interceptorContext.putPrivateData(CancellationFlag.class, flag);
            }
            final SecurityDomain securityDomain;
            if (WildFlySecurityManager.isChecking()) {
                securityDomain = AccessController.doPrivileged((PrivilegedAction<SecurityDomain>) SecurityDomain::getCurrent);
            } else {
                securityDomain = SecurityDomain.getCurrent();
            }
            final SecurityIdentity securityIdentity = securityDomain != null ? securityDomain.getCurrentSecurityIdentity() : null;
            final StartupCountdown.Frame frame = StartupCountdown.current();
            final Runnable task = () -> {
                if (!flag.runIfNotCancelled()) {
                    receiverContext.requestCancelled();
                    return;
                }
                StartupCountdown.restore(frame);
                try {
                    final Object result;
                    try {
                        result = view.invoke(interceptorContext);
                    } catch (Exception e) {
                        // WFLY-4331 - clone the exception of an async task
                        receiverContext.resultReady(new CloningExceptionProducer(resultCloner, e, allowPassByReference));
                        return;
                    }
                    // if the result is null, there is no cloning needed
                    if (result == null) {
                        receiverContext.resultReady(NULL_RESULT);
                        return;
                    }
                    // WFLY-4331 - clone the result of an async task
                    if (result instanceof Future) {
                        // blocking is very unlikely here, so just defer interrupts when they happen
                        boolean intr = Thread.interrupted();
                        Object asyncValue;
                        try {
                            for (; ; ) try {
                                asyncValue = ((Future<?>) result).get();
                                break;
                            } catch (InterruptedException e) {
                                intr = true;
                            } catch (ExecutionException e) {
                                // WFLY-4331 - clone the exception of an async task
                                receiverContext.resultReady(new CloningExceptionProducer(resultCloner, e, allowPassByReference));
                                return;
                            }
                        } finally {
                            if (intr)
                                Thread.currentThread().interrupt();
                        }
                        // if the return value is null, there is no cloning needed
                        if (asyncValue == null) {
                            receiverContext.resultReady(NULL_RESULT);
                            return;
                        }
                        receiverContext.resultReady(new CloningResultProducer(invocation, resultCloner, asyncValue, allowPassByReference));
                        return;
                    }
                    receiverContext.resultReady(new CloningResultProducer(invocation, resultCloner, result, allowPassByReference));
                } finally {
                    StartupCountdown.restore(null);
                }
            };
            invocation.putAttachment(CANCELLATION_FLAG_ATTACHMENT_KEY, flag);
            interceptorContext.putPrivateData(CancellationFlag.class, flag);
            final ExecutorService executor = component.getAsynchronousExecutor();
            if (executor == null) {
                receiverContext.resultReady(new EJBReceiverInvocationContext.ResultProducer.Failed(EjbLogger.ROOT_LOGGER.executorIsNull()));
            } else {
                // this normally isn't necessary unless the client didn't detect that it was an async method for some reason
                receiverContext.proceedAsynchronously();
                executor.execute(securityIdentity == null ? task : () -> securityIdentity.runAs(task));
            }
        } else {
            throw EjbLogger.ROOT_LOGGER.asyncInvocationOnlyApplicableForSessionBeans();
        }
    } else {
        final Object result;
        try {
            result = view.invoke(interceptorContext);
        } catch (Exception e) {
            // we even have to clone the exception type
            // to make sure it matches
            receiverContext.resultReady(new CloningExceptionProducer(resultCloner, e, allowPassByReference));
            return;
        }
        receiverContext.resultReady(new CloningResultProducer(invocation, resultCloner, result, allowPassByReference));
        for (Map.Entry<String, Object> entry : interceptorContext.getContextData().entrySet()) {
            if (entry.getValue() instanceof Serializable) {
                invocation.getContextData().put(entry.getKey(), entry.getValue());
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) AttachmentKey(org.jboss.ejb.client.AttachmentKey) PrivilegedAction(java.security.PrivilegedAction) InterceptorContext(org.jboss.invocation.InterceptorContext) ExecutionException(java.util.concurrent.ExecutionException) ObjectCloner(org.jboss.marshalling.cloner.ObjectCloner) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown) EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) Method(java.lang.reflect.Method) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) EntityEJBLocator(org.jboss.ejb.client.EntityEJBLocator) ExecutionException(java.util.concurrent.ExecutionException) SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) ComponentView(org.jboss.as.ee.component.ComponentView) SessionBeanComponent(org.jboss.as.ejb3.component.session.SessionBeanComponent) EJBClientInvocationContext(org.jboss.ejb.client.EJBClientInvocationContext) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) CancellationFlag(org.jboss.as.ejb3.component.interceptors.CancellationFlag) ClassLoaderClassCloner(org.jboss.marshalling.cloner.ClassLoaderClassCloner) HashMap(java.util.HashMap) Map(java.util.Map) ClonerConfiguration(org.jboss.marshalling.cloner.ClonerConfiguration)

Example 7 with EJBComponent

use of org.jboss.as.ejb3.component.EJBComponent in project wildfly by wildfly.

the class EjbIIOPService method start.

@Override
public synchronized void start(final StartContext startContext) throws StartException {
    try {
        final RiverMarshallerFactory factory = new RiverMarshallerFactory();
        final MarshallingConfiguration configuration = new MarshallingConfiguration();
        configuration.setClassResolver(new FilteringClassResolver(ModularClassResolver.getInstance(serviceModuleLoaderInjectedValue.getValue())));
        this.configuration = configuration;
        this.factory = factory;
        final TransactionManager jtsTransactionManager = transactionManagerInjectedValue.getValue().getTransactionManager();
        assert !(jtsTransactionManager instanceof ContextTransactionManager);
        // Should create a CORBA interface repository?
        final boolean interfaceRepositorySupported = false;
        // Build binding name of the bean.
        final EJBComponent component = ejbComponentInjectedValue.getValue();
        final String earApplicationName = component.getEarApplicationName();
        if (iiopMetaData != null && iiopMetaData.getBindingName() != null) {
            name = iiopMetaData.getBindingName();
        } else if (useQualifiedName) {
            if (component.getDistinctName() == null || component.getDistinctName().isEmpty()) {
                name = earApplicationName == null || earApplicationName.isEmpty() ? "" : earApplicationName + "/";
                name = name + component.getModuleName() + "/" + component.getComponentName();
            } else {
                name = earApplicationName == null || earApplicationName.isEmpty() ? "" : earApplicationName + "/";
                name = name + component.getModuleName() + "/" + component.getDistinctName() + "/" + component.getComponentName();
            }
        } else {
            name = component.getComponentName();
        }
        name = name.replace(".", "_");
        EjbLogger.DEPLOYMENT_LOGGER.iiopBindings(component.getComponentName(), component.getModuleName(), name);
        final ORB orb = this.orb.getValue();
        if (interfaceRepositorySupported) {
            // Create a CORBA interface repository for the enterprise bean
            iri = new InterfaceRepository(orb, irPoa.getValue(), name);
            // Add bean interface info to the interface repository
            iri.mapClass(remoteView.getValue().getViewClass());
            iri.mapClass(homeView.getValue().getViewClass());
            iri.finishBuild();
            EjbLogger.ROOT_LOGGER.cobraInterfaceRepository(name, orb.object_to_string(iri.getReference()));
        }
        IORSecurityConfigMetaData iorSecurityConfigMetaData = this.iorSecConfigMetaData.getOptionalValue();
        if (this.iiopMetaData != null && this.iiopMetaData.getIorSecurityConfigMetaData() != null)
            iorSecurityConfigMetaData = this.iiopMetaData.getIorSecurityConfigMetaData();
        // Create security policies if security metadata has been provided.
        List<Policy> policyList = new ArrayList<Policy>();
        if (iorSecurityConfigMetaData != null) {
            // Create csiv2Policy for both home and remote containing IorSecurityConfigMetadata.
            final Any secPolicy = orb.create_any();
            secPolicy.insert_Value(iorSecurityConfigMetaData);
            Policy csiv2Policy = orb.create_policy(CSIv2Policy.TYPE, secPolicy);
            policyList.add(csiv2Policy);
            // Add ZeroPortPolicy if ssl is required (it ensures home and remote IORs will have port 0 in the primary address).
            boolean sslRequired = false;
            if (iorSecurityConfigMetaData != null && iorSecurityConfigMetaData.getTransportConfig() != null) {
                IORTransportConfigMetaData tc = iorSecurityConfigMetaData.getTransportConfig();
                sslRequired = IORTransportConfigMetaData.INTEGRITY_REQUIRED.equals(tc.getIntegrity()) || IORTransportConfigMetaData.CONFIDENTIALITY_REQUIRED.equals(tc.getConfidentiality()) || IORTransportConfigMetaData.ESTABLISH_TRUST_IN_CLIENT_REQUIRED.equals(tc.getEstablishTrustInClient());
            }
            if (sslRequired) {
                policyList.add(ZeroPortPolicy.getPolicy());
            }
        }
        // TODO: what should this default to
        String securityDomainName = "CORBA_REMOTE";
        if (component.getSecurityMetaData() != null) {
            securityDomainName = component.getSecurityMetaData().getSecurityDomainName();
        }
        Policy[] policies = policyList.toArray(new Policy[policyList.size()]);
        // If there is an interface repository, then get the homeInterfaceDef from the IR
        InterfaceDef homeInterfaceDef = null;
        if (iri != null) {
            Repository ir = iri.getReference();
            homeInterfaceDef = InterfaceDefHelper.narrow(ir.lookup_id(homeRepositoryIds[0]));
        }
        // Get the POACurrent object
        Current poaCurrent = CurrentHelper.narrow(orb.resolve_initial_references("POACurrent"));
        // Instantiate home servant, bind it to the servant registry, and create CORBA reference to the EJBHome.
        final EjbCorbaServant homeServant = new EjbCorbaServant(poaCurrent, homeMethodMap, homeRepositoryIds, homeInterfaceDef, orb, homeView.getValue(), factory, configuration, jtsTransactionManager, module.getClassLoader(), true, securityDomainName, component.getSecurityDomain());
        homeServantRegistry = poaRegistry.getValue().getRegistryWithPersistentPOAPerServant();
        ReferenceFactory homeReferenceFactory = homeServantRegistry.bind(homeServantName(name), homeServant, policies);
        final org.omg.CORBA.Object corbaRef = homeReferenceFactory.createReference(homeRepositoryIds[0]);
        // we do this twice to force eager dynamic stub creation
        ejbHome = (EJBHome) PortableRemoteObject.narrow(corbaRef, EJBHome.class);
        final HomeHandleImplIIOP homeHandle = new HomeHandleImplIIOP(orb.object_to_string(corbaRef));
        homeServant.setHomeHandle(homeHandle);
        // Initialize beanPOA and create metadata
        // This is a session bean (lifespan: transient)
        beanServantRegistry = poaRegistry.getValue().getRegistryWithTransientPOAPerServant();
        if (component instanceof StatelessSessionComponent) {
            // Stateless session bean
            ejbMetaData = new EJBMetaDataImplIIOP(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, true, homeHandle);
        } else {
            // Stateful session bean
            ejbMetaData = new EJBMetaDataImplIIOP(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, false, homeHandle);
        }
        homeServant.setEjbMetaData(ejbMetaData);
        // If there is an interface repository, then get the beanInterfaceDef from the IR
        InterfaceDef beanInterfaceDef = null;
        if (iri != null) {
            final Repository ir = iri.getReference();
            beanInterfaceDef = InterfaceDefHelper.narrow(ir.lookup_id(beanRepositoryIds[0]));
        }
        // Instantiate the ejb object servant and bind it to the servant registry.
        final EjbCorbaServant beanServant = new EjbCorbaServant(poaCurrent, beanMethodMap, beanRepositoryIds, beanInterfaceDef, orb, remoteView.getValue(), factory, configuration, jtsTransactionManager, module.getClassLoader(), false, securityDomainName, component.getSecurityDomain());
        beanReferenceFactory = beanServantRegistry.bind(beanServantName(name), beanServant, policies);
        // Register bean home in local CORBA naming context
        rebind(corbaNamingContext.getValue(), name, corbaRef);
        EjbLogger.ROOT_LOGGER.debugf("Home IOR for %s bound to %s in CORBA naming service", component.getComponentName(), this.name);
        // now eagerly force stub creation, so de-serialization of stubs will work correctly
        final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
        try {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
            try {
                DynamicStubFactoryFactory.makeStubClass(homeView.getValue().getViewClass());
            } catch (Exception e) {
                EjbLogger.ROOT_LOGGER.dynamicStubCreationFailed(homeView.getValue().getViewClass().getName(), e);
            }
            try {
                DynamicStubFactoryFactory.makeStubClass(remoteView.getValue().getViewClass());
            } catch (Exception e) {
                EjbLogger.ROOT_LOGGER.dynamicStubCreationFailed(remoteView.getValue().getViewClass().getName(), e);
            }
        } finally {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
        }
    } catch (Exception e) {
        throw new StartException(e);
    }
}
Also used : ZeroPortPolicy(com.sun.corba.se.spi.extension.ZeroPortPolicy) CSIv2Policy(org.wildfly.iiop.openjdk.csiv2.CSIv2Policy) Policy(org.omg.CORBA.Policy) ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) ArrayList(java.util.ArrayList) InterfaceRepository(org.wildfly.iiop.openjdk.rmi.ir.InterfaceRepository) Any(org.omg.CORBA.Any) StatelessSessionComponent(org.jboss.as.ejb3.component.stateless.StatelessSessionComponent) MarshallingConfiguration(org.jboss.marshalling.MarshallingConfiguration) EJBMetaDataImplIIOP(org.jboss.ejb.iiop.EJBMetaDataImplIIOP) StartException(org.jboss.msc.service.StartException) IORTransportConfigMetaData(org.jboss.metadata.ejb.jboss.IORTransportConfigMetaData) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) InvalidClassException(java.io.InvalidClassException) StartException(org.jboss.msc.service.StartException) IOException(java.io.IOException) InterfaceDef(org.omg.CORBA.InterfaceDef) InterfaceRepository(org.wildfly.iiop.openjdk.rmi.ir.InterfaceRepository) Repository(org.omg.CORBA.Repository) IORSecurityConfigMetaData(org.jboss.metadata.ejb.jboss.IORSecurityConfigMetaData) ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) TransactionManager(javax.transaction.TransactionManager) RiverMarshallerFactory(org.jboss.marshalling.river.RiverMarshallerFactory) Current(org.omg.PortableServer.Current) ORB(org.omg.CORBA.ORB) HomeHandleImplIIOP(org.jboss.ejb.iiop.HomeHandleImplIIOP)

Example 8 with EJBComponent

use of org.jboss.as.ejb3.component.EJBComponent in project wildfly by wildfly.

the class RolesAllowedInterceptor method processInvocation.

public Object processInvocation(final InterceptorContext context) throws Exception {
    final Component component = context.getPrivateData(Component.class);
    if (!(component instanceof EJBComponent)) {
        throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, EJBComponent.class);
    }
    final Iterator<String> iterator = rolesAllowed.iterator();
    if (iterator.hasNext()) {
        final SecurityDomain securityDomain = context.getPrivateData(SecurityDomain.class);
        final SecurityIdentity identity = securityDomain.getCurrentSecurityIdentity();
        final Roles ejbRoles = identity.getRoles("ejb", true);
        do {
            final String role = iterator.next();
            if (ejbRoles.contains(role) || (role.equals("**") && !identity.isAnonymous())) {
                return context.proceed();
            }
        } while (iterator.hasNext());
    }
    throw EjbLogger.ROOT_LOGGER.invocationOfMethodNotAllowed(context.getMethod(), ((EJBComponent) component).getComponentName());
}
Also used : SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) Roles(org.wildfly.security.authz.Roles) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain)

Example 9 with EJBComponent

use of org.jboss.as.ejb3.component.EJBComponent in project wildfly by wildfly.

the class AbstractEJBComponentResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    final AbstractEJBComponentRuntimeHandler<?> handler = componentType.getRuntimeHandler();
    resourceRegistration.registerReadOnlyAttribute(COMPONENT_CLASS_NAME, handler);
    resourceRegistration.registerReadOnlyAttribute(SECURITY_DOMAIN, handler);
    resourceRegistration.registerReadOnlyAttribute(RUN_AS_ROLE, handler);
    resourceRegistration.registerReadOnlyAttribute(DECLARED_ROLES, handler);
    resourceRegistration.registerReadOnlyAttribute(TRANSACTION_TYPE, handler);
    if (!componentType.equals(EJBComponentType.MESSAGE_DRIVEN)) {
        resourceRegistration.registerReadOnlyAttribute(JNDI_NAMES, handler);
        resourceRegistration.registerReadOnlyAttribute(BUSINESS_LOCAL, handler);
        resourceRegistration.registerReadOnlyAttribute(BUSINESS_REMOTE, handler);
        resourceRegistration.registerReadOnlyAttribute(ASYNC_METHODS, handler);
    }
    if (componentType.hasTimer()) {
        resourceRegistration.registerReadOnlyAttribute(TimerAttributeDefinition.INSTANCE, handler);
        resourceRegistration.registerReadOnlyAttribute(TIMEOUT_METHOD, handler);
    }
    if (componentType.hasPool()) {
        resourceRegistration.registerReadOnlyAttribute(POOL_AVAILABLE_COUNT, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_CREATE_COUNT, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_NAME, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_REMOVE_COUNT, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_CURRENT_SIZE, handler);
        resourceRegistration.registerReadWriteAttribute(POOL_MAX_SIZE, handler, handler);
    }
    if (componentType.equals(EJBComponentType.STATEFUL)) {
        resourceRegistration.registerMetric(CACHE_SIZE, new AbstractRuntimeMetricsHandler() {

            @Override
            protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
                context.getResult().set(((StatefulSessionComponent) component).getCache().getCacheSize());
            }
        });
        resourceRegistration.registerMetric(PASSIVATED_SIZE, new AbstractRuntimeMetricsHandler() {

            @Override
            protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
                context.getResult().set(((StatefulSessionComponent) component).getCache().getPassivatedCount());
            }
        });
        resourceRegistration.registerMetric(TOTAL_SIZE, new AbstractRuntimeMetricsHandler() {

            @Override
            protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
                context.getResult().set(((StatefulSessionComponent) component).getCache().getTotalSize());
            }
        });
    }
    resourceRegistration.registerMetric(EXECUTION_TIME, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().set(component.getInvocationMetrics().getExecutionTime());
        }
    });
    resourceRegistration.registerMetric(INVOCATIONS, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().set(component.getInvocationMetrics().getInvocations());
        }
    });
    resourceRegistration.registerMetric(PEAK_CONCURRENT_INVOCATIONS, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().set(component.getInvocationMetrics().getPeakConcurrent());
        }
    });
    resourceRegistration.registerMetric(WAIT_TIME, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().set(component.getInvocationMetrics().getWaitTime());
        }
    });
    resourceRegistration.registerMetric(METHODS, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().setEmptyObject();
            for (final Map.Entry<String, InvocationMetrics.Values> entry : component.getInvocationMetrics().getMethods().entrySet()) {
                final InvocationMetrics.Values values = entry.getValue();
                final ModelNode result = new ModelNode();
                result.get("execution-time").set(values.getExecutionTime());
                result.get("invocations").set(values.getInvocations());
                result.get("wait-time").set(values.getWaitTime());
                context.getResult().get(entry.getKey()).set(result);
            }
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InvocationMetrics(org.jboss.as.ejb3.component.invocationmetrics.InvocationMetrics) ModelNode(org.jboss.dmr.ModelNode) EJBComponent(org.jboss.as.ejb3.component.EJBComponent)

Example 10 with EJBComponent

use of org.jboss.as.ejb3.component.EJBComponent in project wildfly by wildfly.

the class AbstractRuntimeMetricsHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    final ServiceName componentServiceName = componentServiceName(context, operation);
    final EJBComponent component = (EJBComponent) context.getServiceRegistry(false).getRequiredService(componentServiceName).getValue();
    executeReadMetricStep(context, operation, component);
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) EJBComponent(org.jboss.as.ejb3.component.EJBComponent)

Aggregations

EJBComponent (org.jboss.as.ejb3.component.EJBComponent)24 Component (org.jboss.as.ee.component.Component)7 ComponentView (org.jboss.as.ee.component.ComponentView)6 MethodIntf (org.jboss.as.ejb3.component.MethodIntf)5 SecurityDomain (org.wildfly.security.auth.server.SecurityDomain)5 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)5 Method (java.lang.reflect.Method)4 EjbDeploymentInformation (org.jboss.as.ejb3.deployment.EjbDeploymentInformation)4 PrivilegedActionException (java.security.PrivilegedActionException)3 IOException (java.io.IOException)2 InvalidClassException (java.io.InvalidClassException)2 RemoteException (java.rmi.RemoteException)2 PrivilegedAction (java.security.PrivilegedAction)2 ProtectionDomain (java.security.ProtectionDomain)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)2 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)2 TransactionAttributeType (javax.ejb.TransactionAttributeType)2