JMX - addConnectionNotificationListener not handling connection close -


i trying detect shutdown of remote server using jmx connection.

the approach using to

  • create jmx connection weblogic server, and
  • add "addconnectionnotificationlistener" connector

now if server goes down, expecting notification of type "jmxconnectionnotification".

this not happen. figuring out connection not valid anymore, have access (by small means) , when connection object accessed notification listener gets notification. if done way, not real-time.

can point me can done solve issue?


my code reference -

public class printserverstate {     private static mbeanserverconnection connection;    private static jmxconnector connector;    private static final objectname service;    private jmxconnectornotificationlistener connectionlistener = null;     static {       try {         service =           new objectname(             "com.bea:name=domainruntimeservice,type=weblogic.management.mbeanservers.domainruntime.domainruntimeservicembean");       } catch (malformedobjectnameexception e) {          throw new assertionerror(e.getmessage());       }    }     public void initconnection       (string hostname, string portstring,            string username, string password) throws ioexception,       malformedurlexception    {        string protocol = "t3";       integer portinteger = integer.valueof(portstring);       int port = portinteger.intvalue();        string jndiroot = "/jndi/";       string mserver = "weblogic.management.mbeanservers.domainruntime";       //string mserver = "weblogic.management.mbeanservers.runtime";       jmxserviceurl serviceurl = new jmxserviceurl(protocol, hostname,          port, jndiroot + mserver);       hashtable h = new hashtable();       h.put(context.security_principal, username);       h.put(context.security_credentials, password);       h.put(jmxconnectorfactory.protocol_provider_packages,          "weblogic.management.remote");       system.out.println(serviceurl);       connector = jmxconnectorfactory.connect(serviceurl,h);        if (connector != null)        {            connectionlistener = new jmxconnectornotificationlistener();            system.out.println("created 1 listener connector ");        }        /* try{             connector.addconnectionnotificationlistener(connectionlistener,null,null);        }catch(exception e){            system.out.println("connector not support notfication listener");        } */       connection = connector.getmbeanserverconnection();    }     public static void main(string[] args) throws exception {        string hostname = "example.domain.com";       string portstring = "7001";       string username = "weblogic";       string password = "password";        printserverstate s = new printserverstate();        s.initconnection(hostname, portstring, username, password);       string test = connection.getdefaultdomain();         system.out.println(test);         for(int =0 ; i<=20;i++){           thread.sleep(1000);           system.out.println(i);       }        string test1 = connection.getdefaultdomain();         system.out.println(test1);     }      //inner class    private class jmxconnectornotificationlistener implements notificationlistener{         public jmxconnectornotificationlistener() {             connector.addconnectionnotificationlistener(this,null,null);          }          public void handlenotification(notification notification,                                        object handback) {             system.out.println("notification");             string type = notification.gettype();             if (jmxconnectionnotification.closed.equals(type) ||                 jmxconnectionnotification.failed.equals(type))             {                system.out.println("jmx connection failed!!!");             } else if (jmxconnectionnotification.opened.equals(type)) {                 system.out.println("jmx connection opened!!!");             } else {                system.out.println("recvd jmxconnectionnotification status " + type);             }         }     } } 

due nature of underlying implementation, can't notified connection severed. think of client socket - way know when server has shut end try reading socket , seeing -1 or getting ioexception.

you have 2 options:

  1. leave , notified when attempt access bean/connection , reconnect on spot.

  2. periodically attempt access connection (maybe try read jvm runtime attribute or not taxing) scheduled executor notified sooner.

which use:

if scheduled service polling data on jmx in background, option 1 should suffice.

if operations executed upon user request, option 2 preferred can attempt reconnect before user ever notices.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -