geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Deepak Srinivasa" <deepu.sriniv...@gmail.com>
Subject Re: When has the server started?
Date Sun, 03 Sep 2006 04:38:04 GMT
Hi Jason,

I was interested too, in finding out this piece of information from my
server...

In Geronimo 1.0, the code below 'ServerWhenStart.java' works. It basically
gets hold of the Kernel, then gets a KernelManagementHelper object, and then
queries for the JVM, to find out its boot time (I am assuming that JVM start
time is close to what you are looking for).

However, in Geronimo 1.1, this fails. I am able to get the
KernelManagementHelper object, and also able to look up the domains. But I
cannot get the servers from the first domain.

In jconsole, I wish that the VM tab was active. The VM tab gives info about
the uptime of VM (I have seen that when I ran jconsole to see JMX info for
other software). Then, we could have done currentTime-upTime to get the boot
time.

If you are successful in getting server configuration information from JMX,
please let me know how you did that. Thanks!

-Deepu.

------------- ServerWhenStart.java -----------------
import java.util.Date;

import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import org.apache.geronimo.console.util.KernelManagementHelper;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.KernelDelegate;
import org.apache.geronimo.management.J2EEDomain;
import org.apache.geronimo.management.geronimo.J2EEServer;
import org.apache.geronimo.management.geronimo.JVM;

public class ServerWhenStart {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception{
        // TODO Auto-generated method stub

        java.util.Map environment = new java.util.HashMap();
        String[] credentials = new String[]{"system", "manager"};
        environment.put(JMXConnector.CREDENTIALS, credentials);
        JMXServiceURL address = new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/JMXConnector");
        JMXConnector jmxConnector = JMXConnectorFactory.connect(address,
environment);
        MBeanServerConnection mbServerConnection =
jmxConnector.getMBeanServerConnection();
        Kernel kernel = new KernelDelegate(mbServerConnection);

        KernelManagementHelper mgr = new KernelManagementHelper(kernel);
        J2EEDomain domain = mgr.getDomains()[0];

        //This is where it fails
        J2EEServer[] server = mgr.getServers(domain)[0];
        JVM[] jvms = mgr.getJavaVMs(server);

        //I am thinking that the first VM is what we are interested in...
(is that right??)
        JVM jvm = jvms[0];
        Date bootTime = jvm.getKernelBootTime();
        System.out.println(bootTime);

    }

}



On 9/2/06, Jason Dillon <jason@planet57.com> wrote:
>
> What is the best way to detect when the server has started using JMX?
>
> The ServerBehavior class in the deployment plugin has some code that
> connects to JMX, then lists the configurations, and then takes he
> first configuration and get the "kernelFulltStarted" attribute from
> it... but it assumes that ConfigurationManager.listConfigurations()
> returns an array of ObjectNames, which it does not.
>
> I also peeked at the server's JMX tree via jconsole and I don't see
> any attribute or operation that matches up to "kernelFullyStarted".
> There is also a strange "null" element of the tree, but I will leave
> that for another day.
>
> So, how can I easily check of the server has started by polling a JMX
> attribute?
>
> --jason
>

Mime
View raw message