This discussion is archived
0 Replies Latest reply: Jul 5, 2013 2:21 AM by user11828612 RSS

Random response from clusterruntime.getServerNames()

user11828612 Newbie
Currently Being Moderated

Hello Experts,

 

I am using below code to fetch running managed servers names.

Issue is that I'm getting random response i.e. if executed 20 times, i get correct result for maybe 10-12 times but no result for remaining.

Kindly suggest, if i'm missing anything here.

 

try

{

            final InitialContext ctx = getInitialContext(url, username, password);

            StringBuffer result = new StringBuffer();

            MBeanHome home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);

            Set mbeanSet = home.getMBeansByType("ServerRuntime");

            result.append("List of Managed Servers:"+"\n");

            Iterator mbeanIterator = mbeanSet.iterator();

            while(mbeanIterator.hasNext())

            {

            ServerRuntimeMBean serverRuntime = (ServerRuntimeMBean)mbeanIterator.next();

            if(cls==1)

            {

                        if(serverRuntime.getState().equals(ServerStates.RUNNING))

                        {

                        try

                        {

                                   ClusterRuntimeMBean clusterruntime = serverRuntime.getClusterRuntime();

                                    for(int j=0;j<clusterruntime.getServerNames().length;j++)

                                    {

                                    result.append("  Managed Server: "+(clusterruntime.getServerNames())[j] + "\n");

                                    }

                        }

                        catch(Exception e)

                        {e.printStackTrace();}

                        }

            }

            cls++;

            }

            return result.toString();

}

  catch(Exception e)

  {

  throw new RuntimeException(e);

  }

 

Regards.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points