Search in sources :

Example 6 with Pool

use of org.jboss.as.ejb3.pool.Pool in project wildfly by wildfly.

the class StrictMaxUnitTestCase method testMultiThread.

/**
 * More threads than the pool size.
 */
@Test
public void testMultiThread() throws Exception {
    MockBean.reset();
    StatelessObjectFactory<MockBean> factory = new MockFactory();
    final Pool<MockBean> pool = new StrictMaxPool<MockBean>(factory, 10, 60, TimeUnit.SECONDS);
    pool.start();
    final CountDownLatch in = new CountDownLatch(1);
    final CountDownLatch ready = new CountDownLatch(10);
    Callable<Void> task = new Callable<Void>() {

        public Void call() throws Exception {
            MockBean bean = pool.get();
            ready.countDown();
            in.await();
            pool.release(bean);
            bean = null;
            used.incrementAndGet();
            return null;
        }
    };
    ExecutorService service = Executors.newFixedThreadPool(20);
    Future<?>[] results = new Future<?>[20];
    for (int i = 0; i < results.length; i++) {
        results[i] = service.submit(task);
    }
    ready.await(120, TimeUnit.SECONDS);
    in.countDown();
    for (Future<?> result : results) {
        result.get(5, TimeUnit.SECONDS);
    }
    service.shutdown();
    pool.stop();
    assertEquals(20, used.intValue());
    assertEquals(10, MockBean.getPostConstructs());
    assertEquals(10, MockBean.getPreDestroys());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) MockFactory(org.jboss.as.ejb3.pool.common.MockFactory) MockBean(org.jboss.as.ejb3.pool.common.MockBean) Test(org.junit.Test)

Example 7 with Pool

use of org.jboss.as.ejb3.pool.Pool in project wildfly by wildfly.

the class MessageDrivenComponentDescription method createConfiguration.

@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
    final ComponentConfiguration mdbComponentConfiguration = new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
    // setup the component create service
    final Class<?> messageListenerInterface;
    try {
        messageListenerInterface = Class.forName(getMessageListenerInterfaceName(), true, moduleClassLoader);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    mdbComponentConfiguration.setComponentCreateServiceFactory(new MessageDrivenComponentCreateServiceFactory(messageListenerInterface));
    final MessageDrivenComponentDescription mdbComponentDescription = (MessageDrivenComponentDescription) mdbComponentConfiguration.getComponentDescription();
    // setup a configurator to inject the PoolConfig in the MessageDrivenComponentCreateService
    getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            // get CapabilitySupport to resolve service names
            final CapabilityServiceSupport support = context.getDeploymentUnit().getAttachment(CAPABILITY_SERVICE_SUPPORT);
            MessageDrivenComponentDescription mdbDescription = (MessageDrivenComponentDescription) description;
            configuration.getCreateDependencies().add(new DependencyConfigurator<Service<Component>>() {

                @Override
                public void configureDependency(ServiceBuilder<?> serviceBuilder, Service<Component> service) throws DeploymentUnitProcessingException {
                    // add any dependencies here
                    final MessageDrivenComponentCreateService mdbComponentCreateService = (MessageDrivenComponentCreateService) service;
                    final String poolName = mdbComponentDescription.getPoolConfigName();
                    // If the default mdb pool config itself is not configured, then pooling is disabled for the bean
                    if (poolName == null) {
                        if (mdbComponentDescription.isDefaultMdbPoolAvailable()) {
                            ServiceName defaultPoolConfigServiceName = support.getCapabilityServiceName(DEFAULT_MDB_POOL_CONFIG_CAPABILITY_NAME);
                            serviceBuilder.addDependency(defaultPoolConfigServiceName, PoolConfig.class, mdbComponentCreateService.getPoolConfigInjector());
                        }
                    } else {
                        // pool name has been explicitly set so the pool config is a required dependency
                        ServiceName poolConfigServiceName = support.getCapabilityServiceName(STRICT_MAX_POOL_CONFIG_CAPABILITY_NAME, poolName);
                        serviceBuilder.addDependency(poolConfigServiceName, PoolConfig.class, mdbComponentCreateService.getPoolConfigInjector());
                    }
                }
            });
        }
    });
    // set up a configurator to inject ResourceAdapterService dependencies into the MessageDrivenComponentCreateService
    getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            // get CapabilitySupport to resolve service names
            final CapabilityServiceSupport support = context.getDeploymentUnit().getAttachment(CAPABILITY_SERVICE_SUPPORT);
            configuration.getCreateDependencies().add(new DependencyConfigurator<MessageDrivenComponentCreateService>() {

                @Override
                public void configureDependency(ServiceBuilder<?> serviceBuilder, MessageDrivenComponentCreateService service) throws DeploymentUnitProcessingException {
                    final ServiceName raServiceName = ConnectorServices.getResourceAdapterServiceName(MessageDrivenComponentDescription.this.resourceAdapterName);
                    // add the dependency on the RA service
                    serviceBuilder.addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, service.getResourceAdapterRepositoryInjector());
                    serviceBuilder.addDependency(raServiceName, ResourceAdapter.class, service.getResourceAdapterInjector());
                }
            });
        }
    });
    getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            final ServiceName suspendControllerName = context.getDeploymentUnit().getAttachment(CAPABILITY_SERVICE_SUPPORT).getCapabilityServiceName("org.wildfly.server.suspend-controller");
            configuration.getCreateDependencies().add(new DependencyConfigurator<MessageDrivenComponentCreateService>() {

                @Override
                public void configureDependency(final ServiceBuilder<?> serviceBuilder, final MessageDrivenComponentCreateService mdbComponentCreateService) throws DeploymentUnitProcessingException {
                    serviceBuilder.addDependency(suspendControllerName, SuspendController.class, mdbComponentCreateService.getSuspendControllerInjectedValue());
                }
            });
        }
    });
    // add the BMT interceptor
    if (TransactionManagementType.BEAN.equals(this.getTransactionManagementType())) {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                // add the bmt interceptor factory
                configuration.addComponentInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.Component.BMT_TRANSACTION_INTERCEPTOR, false);
            }
        });
    } else {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final EEApplicationClasses applicationClasses = context.getDeploymentUnit().getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
                InterceptorClassDescription interceptorConfig = ComponentDescription.mergeInterceptorConfig(configuration.getComponentClass(), applicationClasses.getClassByName(description.getComponentClassName()), description, MetadataCompleteMarker.isMetadataComplete(context.getDeploymentUnit()));
                configuration.addPostConstructInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostConstruct(), true), InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
                configuration.addPreDestroyInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPreDestroy(), true), InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
                configuration.addTimeoutViewInterceptor(TimerCMTTxInterceptor.FACTORY, InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
            }
        });
    }
    return mdbComponentConfiguration;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Service(org.jboss.msc.service.Service) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) ServiceName(org.jboss.msc.service.ServiceName) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) Component(org.jboss.as.ee.component.Component)

Aggregations

ServiceName (org.jboss.msc.service.ServiceName)3 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)2 Component (org.jboss.as.ee.component.Component)2 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)2 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)2 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)2 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)2 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)2 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)2 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 ModelNode (org.jboss.dmr.ModelNode)2 AssemblyDescriptorMetaData (org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData)2 EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)2 Service (org.jboss.msc.service.Service)2 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)2 Method (java.lang.reflect.Method)1 Set (java.util.Set)1