Search in sources :

Example 6 with ServicePool

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

the class StaticFailoverTest method createServiceDaemon.

private ServiceDaemon createServiceDaemon(int poolSize, EjbServer ejbServer, URI uri) throws ServiceException {
    ServiceIdentifier serviceIdentifier = new ServiceIdentifier(ejbServer, uri);
    KeepAliveServer keepAliveServer = new KeepAliveServer(serviceIdentifier);
    ServicePool pool = new ServicePool(keepAliveServer, poolSize);
    ServiceDaemon daemon = new ServiceDaemon(pool, 0, "localhost");
    daemon.start();
    return daemon;
}
Also used : ServicePool(org.apache.openejb.server.ServicePool) ServiceDaemon(org.apache.openejb.server.ServiceDaemon)

Example 7 with ServicePool

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

the class UberInterfaceTest method test.

public void test() throws Exception {
    final EjbServer ejbServer = new EjbServer();
    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(ejbServer, 10);
    final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    final int port = serviceDaemon.getPort();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    assertEquals(asList(Everything.class.getName()), beanInfo.businessLocal);
    assertEquals(asList(Everything.class.getName()), beanInfo.businessRemote);
    assembler.createApplication(ejbJarInfo);
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext deployment = containerSystem.getBeanContext(beanInfo.ejbDeploymentId);
    assertEquals(asList(Everything.class), deployment.getBusinessLocalInterfaces());
    assertEquals(asList(Everything.class), deployment.getBusinessRemoteInterfaces());
    {
        // remote invoke
        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);
        final Everything remote = (Everything) context.lookup("SuperBeanRemote");
        final Reference reference = new Reference("test");
        assertEquals(reference, remote.echo(reference));
        // pass by value
        assertNotSame(reference, remote.echo(reference));
    }
    {
        // local invoke
        final Properties props = new Properties();
        props.put("java.naming.factory.initial", "org.apache.openejb.core.LocalInitialContextFactory");
        final Context context = new InitialContext(props);
        final Everything local = (Everything) context.lookup("SuperBeanLocal");
        final Reference reference = new Reference("test");
        assertEquals(reference, local.echo(reference));
        // pass by reference
        assertSame(reference, local.echo(reference));
    }
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitialContext(javax.naming.InitialContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) 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) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 8 with ServicePool

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

the class FullPoolFailoverTest method createServiceDaemon.

private ServiceDaemon createServiceDaemon(final int poolSize, final EjbServer ejbServer, URI uri) throws ServiceException {
    ServiceIdentifier serviceIdentifier = new ServiceIdentifier(ejbServer, uri);
    KeepAliveServer keepAliveServer = new KeepAliveServer(serviceIdentifier);
    ServicePool pool = new ServicePool(keepAliveServer, poolSize);
    final ServiceDaemon daemon = new ServiceDaemon(pool, 0, "localhost");
    daemon.start();
    return daemon;
}
Also used : ServicePool(org.apache.openejb.server.ServicePool) ServiceDaemon(org.apache.openejb.server.ServiceDaemon)

Example 9 with ServicePool

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

the class PropertiesPropogationTest method test.

public void test() throws Exception {
    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("color", "orange");
    deployment.getProperties().put("openejb.client.color", "red");
    EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
    EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    assertTrue(beanInfo.properties.containsKey("color"));
    assertTrue(beanInfo.properties.containsKey("openejb.client.color"));
    assertEquals("orange", beanInfo.properties.get("color"));
    assertEquals("red", beanInfo.properties.get("openejb.client.color"));
    assembler.createApplication(ejbJarInfo);
    ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
    BeanContext info = cs.getBeanContext("WidgetBean");
    assertNotNull(info);
    assertTrue(info.getProperties().containsKey("color"));
    assertTrue(info.getProperties().containsKey("openejb.client.color"));
    assertEquals("orange", info.getProperties().get("color"));
    assertEquals("red", info.getProperties().get("openejb.client.color"));
    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");
    InvocationHandler handler = ProxyManager.getInvocationHandler(remote);
    EJBObjectHandler objectHandler = EJBObjectHandler.class.cast(handler);
    Properties properties = objectHandler.getEjb().getProperties();
    // Should only contain "openejb.client.*" properties
    assertFalse(properties.containsKey("color"));
    // The openejb.client.color property should have been propogated
    assertTrue(properties.containsKey("openejb.client.color"));
    assertEquals("red", properties.getProperty("openejb.client.color"));
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitialContext(javax.naming.InitialContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) ServerFederation(org.apache.openejb.core.ServerFederation) EJBObjectHandler(org.apache.openejb.client.EJBObjectHandler) ServicePool(org.apache.openejb.server.ServicePool) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InvocationHandler(org.apache.openejb.client.proxy.InvocationHandler) InitialContext(javax.naming.InitialContext) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) 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) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 10 with ServicePool

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

the class Server2ServerEjbRefTest method server.

private ServiceDaemon server() throws Exception {
    final EjbServer ejbServer = new EjbServer();
    ejbServer.init(new Properties());
    final ServicePool pool = new ServicePool(ejbServer, 10, 5000, true);
    final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    return serviceDaemon;
}
Also used : ServicePool(org.apache.openejb.server.ServicePool) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) Properties(java.util.Properties)

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