Search in sources :

Example 1 with ServicePool

use of org.apache.openejb.server.ServicePool in project tomee by apache.

the class KeepAliveServer method getQueue.

private BlockingQueue<Runnable> getQueue() {
    if (this.threadQueue == null) {
        // this can be null if timer fires before service is fully initialized
        final ServicePool incoming = Unwrappable.class.isInstance(service) ? Unwrappable.class.cast(service).unwrap(ServicePool.class) : null;
        if (incoming == null) {
            return null;
        }
        this.threadQueue = incoming.getThreadPool().getQueue();
    }
    return this.threadQueue;
}
Also used : Unwrappable(org.apache.openejb.server.Unwrappable) ServicePool(org.apache.openejb.server.ServicePool)

Example 2 with ServicePool

use of org.apache.openejb.server.ServicePool in project tomee by apache.

the class DynamicConnectionStrategyTest method test.

public void test() throws Exception {
    ConnectionManager.registerStrategy("test", new TestConnectionStrategy());
    EjbServer ejbServer = new EjbServer();
    Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    ServicePool pool = new ServicePool(ejbServer, 10);
    ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    ConfigurationFactory config = new ConfigurationFactory();
    EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    EjbJar ejbJar = ejbModule.getEjbJar();
    OpenejbJar openejbJar = ejbModule.getOpenejbJar();
    StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
    deployment.getProperties().put("openejb.client.connection.strategy", "test");
    assembler.createApplication(config.configureApplication(ejbModule));
    Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
    Context context = new InitialContext(props);
    Widget remote = (Widget) context.lookup("WidgetBeanRemote");
    assertFalse(TestConnectionStrategy.called.get());
    remote.echo("foo");
    assertTrue(TestConnectionStrategy.called.get());
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 3 with ServicePool

use of org.apache.openejb.server.ServicePool in project tomee by apache.

the class FailoverConnectionFactoryTest method test.

public void test() throws Exception {
    ConnectionManager.registerStrategy("test", new TestConnectionStrategy());
    EjbServer ejbServer = new EjbServer();
    Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    ServicePool pool = new ServicePool(ejbServer, 10);
    ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    ConfigurationFactory config = new ConfigurationFactory();
    EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    EjbJar ejbJar = ejbModule.getEjbJar();
    OpenejbJar openejbJar = ejbModule.getOpenejbJar();
    StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
    deployment.getProperties().put("openejb.client.connection.strategy", "test");
    assembler.createApplication(config.configureApplication(ejbModule));
    Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", "failover:sticky:ejbd://agwdt:9999,ejbd://127.0.0.1:" + port);
    Context context = new InitialContext(props);
    Widget remote = (Widget) context.lookup("WidgetBeanRemote");
    assertFalse(TestConnectionStrategy.called.get());
    remote.echo("foo");
    assertTrue(TestConnectionStrategy.called.get());
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 4 with ServicePool

use of org.apache.openejb.server.ServicePool in project tomee by apache.

the class KeepAilveTest method test.

public void test() throws Exception {
    final EjbServer ejbServer = new EjbServer();
    final KeepAliveServer keepAliveServer = new KeepAliveServer(ejbServer, false);
    final Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    final ServicePool pool = new ServicePool(keepAliveServer, 10, 5000, true);
    final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    try {
        final int port = serviceDaemon.getPort();
        final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
        final ConfigurationFactory config = new ConfigurationFactory();
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(EchoBean.class));
        assembler.createApplication(config.configureApplication(ejbJar));
        // good creds
        final int threads = 1;
        final CountDownLatch latch = new CountDownLatch(threads);
        final Collection<Thread> th = new ArrayList<>(threads);
        for (int i = 0; i < threads; i++) {
            final Client client = new Client(latch, i, port);
            th.add(thread(client, false));
        }
        final boolean await = latch.await(60, TimeUnit.SECONDS);
        assertTrue(await);
        for (final Thread t : th) {
            t.join(1000);
        }
    } finally {
        serviceDaemon.stop();
        OpenEJB.destroy();
    }
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) ArrayList(java.util.ArrayList) Properties(java.util.Properties) CountDownLatch(java.util.concurrent.CountDownLatch) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 5 with ServicePool

use of org.apache.openejb.server.ServicePool in project tomee by apache.

the class MultithreadTest method setUp.

@Before
public void setUp() throws Exception {
    final int poolSize = 10;
    System.setProperty("openejb.client.connectionpool.size", "" + (poolSize * 2));
    final EjbServer ejbServer = new EjbServer();
    final KeepAliveServer keepAliveServer = new KeepAliveServer(ejbServer, false);
    final Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    final ServicePool pool = new ServicePool(keepAliveServer, (poolSize * 2));
    this.serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    final int port = serviceDaemon.getPort();
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "100");
    statelessContainerInfo.properties.setProperty("PoolSize", "" + poolSize);
    statelessContainerInfo.properties.setProperty("MinSize", "2");
    statelessContainerInfo.properties.setProperty("StrictPooling", "true");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final StatelessBean bean = new StatelessBean(CounterBean.class);
    bean.addBusinessLocal(Counter.class.getName());
    bean.addBusinessRemote(RemoteCounter.class.getName());
    bean.addPostConstruct("init");
    bean.addPreDestroy("destroy");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);
    CounterBean.instances.set(0);
    assembler.createApplication(config.configureApplication(ejbJar));
    final Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
    final Context context = new InitialContext(props);
    counter = (Counter) context.lookup("CounterBeanRemote");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Aggregations

ServicePool (org.apache.openejb.server.ServicePool)11 ServiceDaemon (org.apache.openejb.server.ServiceDaemon)10 Properties (java.util.Properties)8 Assembler (org.apache.openejb.assembler.classic.Assembler)7 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)7 ServerFederation (org.apache.openejb.core.ServerFederation)7 EjbJar (org.apache.openejb.jee.EjbJar)7 StatelessBean (org.apache.openejb.jee.StatelessBean)7 Context (javax.naming.Context)6 InitialContext (javax.naming.InitialContext)6 EjbModule (org.apache.openejb.config.EjbModule)4 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)4 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)3 BeanContext (org.apache.openejb.BeanContext)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)2 ContainerSystem (org.apache.openejb.spi.ContainerSystem)2 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 EJBObject (javax.ejb.EJBObject)1