Restart of embedded OpenEJB

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Restart of embedded OpenEJB

Marcin_K
Hello,

I created a simply GUI manager to start/stop/restart the embedded OpenEJB server.
The GUI allows me to change the interface (ejbd.bind) and port number (ejbd.port) for ejbd service.
The problem is that I can not perform a full restart of the embedded OpenEJB (bind to another interface or port number) without closing my application completely. After restarting the OpenjEJB, it still uses the same port number.

During the first start I can see the following console output:

INFO - Deployed Application(path=classpath.ear)
INFO - Initializing network services
INFO - Creating ServerService(id=cxf)
INFO - Creating ServerService(id=ejbd)
INFO - Initializing network services
  ** Starting Services **
  NAME                 IP              PORT  
  ejbd                 10.100.90.9     4000  

During the restart, the network and server services are stopped:

INFO - Stopping network services
INFO - Stopping server services
INFO - Destroying container system
INFO - Undeploying app: classpath.ear

but there is no info about initializing network services. Is there any way to perform a full restart of the ejbd service without a complete application restart?

Code to start Ejb server:

public boolean startEjbServer()
{
        try
        {
                Properties properties = new Properties();
                        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,                                                             "org.apache.openejb.client.LocalInitialContextFactory");
                properties.setProperty("openejb.embedded.remotable", "true");
        properties.setProperty("openejb.embedded.initialcontext.close",  "destroy");
           
                    properties.setProperty("ejbd.threads", "200");
                    properties.setProperty("ejbd.port", ""+port);
                    properties.setProperty("ejbd.bind", ""+interfaceAddress);
                    properties.setProperty("ejbd.disabled", "false");
                    //properties.setProperty("ejbd.only_from", "127.0.0.1,192.168.1.1");
       
             properties.setProperty("ejbds.disabled", "true");
                    properties.setProperty("httpejbd.disabled", "true");
                    properties.setProperty("telnet.disabled", "true");
                    properties.setProperty("hsql.disabled", "true");
                    properties.setProperty("admin.disabled", "true");
                       
                    System.setProperty("Default Stateless Container.PoolSize", "200");
                    System.setProperty("Default Stateless Container.StrictPooling", "true");
                    System.setProperty("Default Stateless Container.TimeOut", "10");
                   
                    context = new InitialContext(properties);
               
            return true;
        }
        catch (Exception e)
        {
                e.printStackTrace();
                return false;
        }
}

Code to stop EJB:

public void stopEjbServer()
{
        try
        {
                context.close();
                context = null;
        }
        catch (Exception e)
        {
                e.printStackTrace();
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: Restart of embedded OpenEJB

Romain Manni-Bucau
i think you should be able to do it using the ServiceManager.

- Romain

2011/9/14 szikke <[hidden email]>

> Hello,
>
> I created a simply GUI manager to start/stop/restart the embedded OpenEJB
> server.
> The GUI allows me to change the interface (ejbd.bind) and port number
> (ejbd.port) for ejbd service.
> The problem is that I can not perform a full restart of the embedded
> OpenEJB
> (bind to another interface or port number) without closing my application
> completely. After restarting the OpenjEJB, it still uses the same port
> number.
>
> During the first start I can see the following console output:
>
> INFO - Deployed Application(path=classpath.ear)
> INFO - Initializing network services
> INFO - Creating ServerService(id=cxf)
> INFO - Creating ServerService(id=ejbd)
> INFO - Initializing network services
>  ** Starting Services **
>  NAME                 IP              PORT
>  ejbd                 10.100.90.9     4000
>
> During the restart, the network and server services are stopped:
>
> INFO - Stopping network services
> INFO - Stopping server services
> INFO - Destroying container system
> INFO - Undeploying app: classpath.ear
>
> but there is no info about initializing network services. Is there any way
> to perform a full restart of the ejbd service without a complete
> application
> restart?
>
> Code to start Ejb server:
>
> public boolean startEjbServer()
> {
>        try
>        {
>                Properties properties = new Properties();
>
>  properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>                properties.setProperty("openejb.embedded.remotable",
> "true");
>
>  properties.setProperty("openejb.embedded.initialcontext.close",
> "destroy");
>
>                    properties.setProperty("ejbd.threads", "200");
>                    properties.setProperty("ejbd.port", ""+port);
>                    properties.setProperty("ejbd.bind",
> ""+interfaceAddress);
>                    properties.setProperty("ejbd.disabled", "false");
>                    //properties.setProperty("ejbd.only_from",
> "127.0.0.1,192.168.1.1");
>
>                    properties.setProperty("ejbds.disabled", "true");
>                    properties.setProperty("httpejbd.disabled", "true");
>                    properties.setProperty("telnet.disabled", "true");
>                    properties.setProperty("hsql.disabled", "true");
>                    properties.setProperty("admin.disabled", "true");
>
>                    System.setProperty("Default Stateless
> Container.PoolSize", "200");
>                    System.setProperty("Default Stateless
> Container.StrictPooling",
> "true");
>                    System.setProperty("Default Stateless
> Container.TimeOut", "10");
>
>                    context = new InitialContext(properties);
>
>            return true;
>        }
>        catch (Exception e)
>        {
>                e.printStackTrace();
>                return false;
>        }
> }
>
> Code to stop EJB:
>
> public void stopEjbServer()
> {
>        try
>        {
>                context.close();
>                context = null;
>        }
>        catch (Exception e)
>        {
>                e.printStackTrace();
>        }
> }
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Restart-of-embedded-OpenEJB-tp3812630p3812630.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Restart of embedded OpenEJB

AndyG
You just need to add the 'DESTROY' property to the InitialContext

public static final String OPENEJB_EMBEDDED_INITIALCONTEXT_CLOSE = "openejb.embedded.initialcontext.close";

....
properties.setProperty(OPENEJB_EMBEDDED_INITIALCONTEXT_CLOSE, "DESTROY");

...
context.close(); //Will destroy the embedded context

Reply | Threaded
Open this post in threaded view
|

Re: Restart of embedded OpenEJB

Marcin_K
Hi,

thank You for your fast response.
Regarding the "destroy" property - it does not work. As You can see at my code to start the EJB server, I've already done it.
The embedded context is destroyed properly, but the network services are not reinitialized correctly after restarting the EJB server.

I tried to use the ServiceManager. I added the following code after creating the new context:

if(serviceManager == null) //if service manager == null -> first startup
{
    serviceManager = ServiceManager.getManager();
}
else //server restart -> re-init ejbd service
{
    serviceManager.init();
    serviceManager.start();
}

It seems that it woks. After changing the port number for ejbd service, the service is working on new port number. There is also correct INFO message:

INFO - Creating ServerService(id=cxf)
INFO - Creating ServerService(id=ejbd)
  ** Starting Services **
  NAME                 IP              PORT  
  ejbd                 10.100.90.9     4000  
-------

But, there is also some error message:

ERROR - Unable to register MBean
javax.management.InstanceAlreadyExistsException: openejb:type=Server,name=DiscoveryRegistry
        at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:453)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(DefaultMBeanServerInterceptor.java:1484)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:963)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:917)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:312)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:482)
        at org.apache.openejb.server.SimpleServiceManager.init(SimpleServiceManager.java:126)
        at com.microsens.client_server.server.launcher.EjbServer.startEjbContainer(EjbServer.java:66)
        at com.microsens.client_server.server.launcher.Launcher.startServer(Launcher.java:1912)
        at com.microsens.client_server.server.launcher.Launcher$38$1.run(Launcher.java:1481)
        at java.lang.Thread.run(Thread.java:662)

Additionally, after starting the services I can see additional info message -> INFO - Stopping Remote Server.
It is strange, because I can connect with my server using remote client. So, it seems that the Remote Server is not stopped.

Is my code for ServiceManager reinitialization correct? Maybe I should change something? I could not find any example or documentation for ServiceManager.

Thank You in advance!

Best regards
Marcin
Reply | Threaded
Open this post in threaded view
|

Re: Restart of embedded OpenEJB

AndyG
Sorry, I should have said DESTROY is case sensitive. Internally the LocalInitialContext.Close.DESTROY enum is evaluated , and so needs to be identical.
Reply | Threaded
Open this post in threaded view
|

Re: Restart of embedded OpenEJB

Marcin_K
Dear AndyG,

the "destroy" and "DESTROY" cause exactly the same. The context is destroyed and the network services are stopped:

INFO - Stopping network services
INFO - Stopping server services
INFO - Destroying container system
INFO - Undeploying app: classpath.ear

The problem is, that after starting everything once again (at the same JVM), the network services are not started. I need to restart the network services (ejbd) on demand with different port number.

Best regards
Marcin
Reply | Threaded
Open this post in threaded view
|

Re: Restart of embedded OpenEJB

AndyG
Sorry Marcin,

You are right - later in the code options does a "valueOf(enumType, value.toUpperCase())" on the parameter, so case is NOT important.

I'll have another look. I have tests that cycle start-deploy-test-undeploy-destroy on an embedded OpenEJB many times, which works for me and is why I made the initial suggestion as it is the only difference I could see to my code. I am working off the trunk, so maybe it has been fixed.

I will create a test to see if I can reproduce the issue and maybe get a little further on this.

Andy.