Search in sources :

Example 11 with ServiceDaemon

use of org.apache.openejb.server.ServiceDaemon 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 12 with ServiceDaemon

use of org.apache.openejb.server.ServiceDaemon 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 13 with ServiceDaemon

use of org.apache.openejb.server.ServiceDaemon 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)

Example 14 with ServiceDaemon

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

the class Server2ServerEjbRefTest method test.

public void test() throws Exception {
    final Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    final ServiceDaemon blue = server();
    final ServiceDaemon orange = server();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final JndiProvider jndiProvider = new JndiProvider("orange");
    final Properties p = jndiProvider.getProperties();
    p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
    p.setProperty(Context.PROVIDER_URL, "ejbd://localhost:" + orange.getPort());
    final JndiContextInfo contextInfo = config.configureService(jndiProvider, JndiContextInfo.class);
    assembler.createExternalContext(contextInfo);
    {
        // Create the "Orange" bean
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(OrangeBean.class));
        assembler.createApplication(config.configureApplication(ejbJar));
        // Lets look it up the normal way to be sure it can work
        final InitialContext initialContext = new InitialContext(jndiProvider.getProperties());
        final OrangeRemote orangeBeanRemote = (OrangeRemote) initialContext.lookup("OrangeBeanRemote");
        assertNotNull(orangeBeanRemote);
    }
    {
        // Create the "Blue" bean
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(BlueBean.class));
        assembler.createApplication(config.configureApplication(ejbJar));
        // Lets look it up the normal way to be sure it can work
        final Properties properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
        properties.setProperty(Context.PROVIDER_URL, "ejbd://localhost:" + blue.getPort());
        final InitialContext initialContext = new InitialContext(properties);
        final BlueRemote blueBeanRemote = (BlueRemote) initialContext.lookup("BlueBeanRemote");
        assertNotNull(blueBeanRemote);
        blueBeanRemote.hasOrangeRemote();
    }
    blue.stop();
    orange.stop();
    OpenEJB.destroy();
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) JndiProvider(org.apache.openejb.config.sys.JndiProvider) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) JndiContextInfo(org.apache.openejb.assembler.classic.JndiContextInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) RemoteInitialContextFactory(org.apache.openejb.client.RemoteInitialContextFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 15 with ServiceDaemon

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

the class FailoverTest method server.

private ServerService server(final Host host) throws Exception {
    ServerService server = new EjbServer();
    server = new HostFilter(server, host);
    server = new ServiceDaemon(server, 0, "localhost");
    server = new AgentFilter(server, agent, host);
    server.init(new Properties());
    return server;
}
Also used : ServerService(org.apache.openejb.server.ServerService) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) Properties(java.util.Properties)

Aggregations

ServiceDaemon (org.apache.openejb.server.ServiceDaemon)19 Properties (java.util.Properties)15 ServerFederation (org.apache.openejb.core.ServerFederation)12 InitialContext (javax.naming.InitialContext)11 Assembler (org.apache.openejb.assembler.classic.Assembler)11 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)11 EjbJar (org.apache.openejb.jee.EjbJar)11 StatelessBean (org.apache.openejb.jee.StatelessBean)11 ServicePool (org.apache.openejb.server.ServicePool)10 Context (javax.naming.Context)9 EjbModule (org.apache.openejb.config.EjbModule)4 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)4 EjbServer (org.apache.openejb.server.ejbd.EjbServer)4 RemoteInitialContextFactory (org.apache.openejb.client.RemoteInitialContextFactory)3 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 JNDIContext (org.apache.openejb.client.JNDIContext)2 ServerService (org.apache.openejb.server.ServerService)2