diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-15 00:26:00 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-15 00:26:00 +0000 |
commit | d5f1d093fe6fa491cdec392dca7137639e98d149 (patch) | |
tree | b98c79d8231a2617ee1dce43b1782d30d93686bc /branches/sca-android/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java | |
parent | f4e3e383071b6947d56794d9af5e9e6438aa3235 (diff) |
Pulled a recent revision of trunk into the sca-android branch, to apply the android patches from JIRA TUSCANY-2440 to it.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@695318 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-android/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java')
-rw-r--r-- | branches/sca-android/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/branches/sca-android/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java b/branches/sca-android/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java new file mode 100644 index 0000000000..0da02c284d --- /dev/null +++ b/branches/sca-android/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java @@ -0,0 +1,127 @@ +package org.apache.tuscany.sca.host.openejb; + +import java.io.IOException; +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.NamingException; + +import org.apache.openejb.OpenEJB; +import org.apache.openejb.OpenEJBException; +import org.apache.openejb.assembler.classic.Assembler; +import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo; +import org.apache.openejb.config.ConfigurationFactory; +import org.apache.openejb.core.ServerFederation; +import org.apache.openejb.jee.EjbJar; +import org.apache.openejb.jee.StatelessBean; +import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.server.ServiceDaemon; +import org.apache.openejb.server.ServiceException; +import org.apache.openejb.server.ejbd.EjbServer; +import org.apache.tuscany.sca.host.ejb.EJBHost; +import org.apache.tuscany.sca.host.ejb.EJBRegistrationException; +import org.apache.tuscany.sca.host.ejb.EJBSessionBean; + +/** + * OpenEJB-based EJB host implementation. + * + * @version $Rev: $ $Date: $ + */ +public class OpenEJBServer implements EJBHost { + + private boolean started; + private EjbServer ejbServer; + private ServiceDaemon serviceDaemon; + private ConfigurationFactory config; + private Assembler assembler; + + public void addSessionBean(String ejbName, EJBSessionBean sessionBean) throws EJBRegistrationException { + if (!started) { + start(); + } + + try { + StatelessBean bean = new StatelessBean(ejbName, sessionBean.getImplementationClass()); + bean.addBusinessRemote(sessionBean.getRemoteInterface().getName()); + bean.addPostConstruct("init"); + bean.addPreDestroy("destroy"); + + EjbJar ejbJar = new EjbJar(); + ejbJar.addEnterpriseBean(bean); + + assembler.createApplication(config.configureApplication(ejbJar)); + + } catch (NamingException e) { + throw new EJBRegistrationException(e); + } catch (IOException e) { + throw new EJBRegistrationException(e); + } catch (OpenEJBException e) { + throw new EJBRegistrationException(e); + } + } + + public EJBSessionBean getSessionBean(String ejbName) throws EJBRegistrationException { + // TODO Auto-generated method stub + return null; + } + + public EJBSessionBean removeSessionBean(String ejbName) throws EJBRegistrationException { + // TODO Auto-generated method stub + return null; + } + + /** + * Start the OpenEJB server. + * + * @throws EJBRegistrationException + */ + private void start() throws EJBRegistrationException { + try { + Properties properties = new Properties(); + properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); + properties.put(Context.PROVIDER_URL, "ejbd://localhost:2888"); + SystemInstance.init(properties); + + ejbServer = new EjbServer(); + SystemInstance.get().setComponent(EjbServer.class, ejbServer); + OpenEJB.init(properties, new ServerFederation()); + ejbServer.init(properties); + + serviceDaemon = new ServiceDaemon(ejbServer, 2888, "localhost"); + serviceDaemon.start(); + + config = new ConfigurationFactory(); + assembler = (Assembler)SystemInstance.get().getComponent(org.apache.openejb.spi.Assembler.class); + + // containers + StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class); + statelessContainerInfo.properties.setProperty("TimeOut", "10"); + statelessContainerInfo.properties.setProperty("PoolSize", "0"); + statelessContainerInfo.properties.setProperty("StrictPooling", "false"); + assembler.createContainer(statelessContainerInfo); + + } catch (OpenEJBException e) { + throw new EJBRegistrationException(e); + } catch (Exception e) { + throw new EJBRegistrationException(e); + } + + started = true; + } + + /** + * Stop the OpenEJB server. + */ + void stop() { + if (started) { + try { + serviceDaemon.stop(); + } catch (ServiceException e) { + throw new EJBRegistrationException(e); + } + } + SystemInstance.get().removeComponent(EjbServer.class); + OpenEJB.destroy(); + } + +} |