import java.util.ArrayList; import org.apache.log4j.Logger; import Ice.*; import com.hp.halo.HaloICE.*; import com.hp.halo.util.factory.IceProxyFactory; /** */ public class RMXUtil { private final static Logger logger = Logger.getLogger(RMXUtil.class.getName()); private Communicator communicator = null; private Communicator mCommunicator=null; private static String[] cmdLineArgs = null; private DatabaseServicesPrx mDbs = null; private boolean mStop = false; private DatabaseServicesPrx databaseServicesProxy; /** */ public RMXUtil() { logger.debug("constructor entered."); startCommunicator(); } public RMXUtil(String[] cmdLineArgs) { logger.debug("constructor entered."); this.cmdLineArgs= cmdLineArgs; startCommunicator(); } public ArrayList getEndpointStatus() { final ArrayList nodeList = new ArrayList(); logger.debug("getEndpointStatus method entered"); try { final ArrayList nodeList = new ArrayList(); logger.debug("getEndpointStatus method entered"); try { java.util.Map m = communicator.getProperties().getPropertiesForPrefix(""); Ice.Logger l = communicator.getLogger(); java.util.Iterator i = m.entrySet().iterator(); while(i.hasNext()) { java.util.Map.Entry e = (java.util.Map.Entry)i.next(); l.print(e.getKey().toString() + " = " + e.getValue().toString()); } databaseServicesProxy = IceProxyFactory.getDatabaseServicesProxy(communicator); logger.debug(" databaseServicesProxy " + databaseServicesProxy); if (databaseServicesProxy == null) { logger.error("Unable to obtain DatabaseServices Proxy. Exiting."); shutdown(); // shutdown does an exit } } catch (Ice.LocalException ex) { logger.error("Exception caught starting commuicator: " + ex.getMessage()); ex.printStackTrace(); shutdown(); databaseServicesProxy = IceProxyFactory.getDatabaseServicesProxy(communicator); logger.debug(" databaseServicesProxy " + databaseServicesProxy); if (databaseServicesProxy == null) { logger.error("Unable to obtain DatabaseServices Proxy. Exiting."); shutdown(); // shutdown does an exit } } catch (Ice.LocalException ex) { logger.error("Exception caught starting commuicator: " + ex.getMessage()); ex.printStackTrace(); shutdown(); } final ArrayList configNodeList = new ArrayList(); try { nodeList.addAll(databaseServicesProxy.getAllConfigNodes()); } catch (Exception ex) { logger.error("Unable to obtain studio information. Exiting."); } return nodeList; } public boolean isStopped() { return mStop; } /** * Shuts down this application and the contained application */ public void shutdown() { databaseServicesProxy = null; int status = 0; if (communicator != null) { try { logger.info("Shutting down ICE communicator"); communicator.destroy(); } catch (Ice.LocalException ex) { logger.error(ex.getMessage()); status = 1; } } System.exit(status); } private DatabaseServicesPrx getDatabaseProxy() { final DatabaseServicesPrx dbs = IceProxyFactory.getDatabaseServicesProxy(mCommunicator); if (null == dbs) { logger.error("Unable to obtain DatabaseServices Proxy. Exiting."); } else { logger.info("Successfully initialized a DatabaseServices instance."); } return dbs; } private void startCommunicator() throws Ice.LocalException, Ice.FileException { try { logger.info("Starting ICE communicator"); StringSeqHolder stringSeqHolder = new StringSeqHolder(); stringSeqHolder.value = cmdLineArgs; Ice.Properties properties = Ice.Util.createProperties(); properties.load(System.getProperty("ConfigFile", "config")); InitializationData initData = new InitializationData(); initData.properties = properties; logger.info("About to initialize the communicator."); communicator = Ice.Util.initialize(stringSeqHolder, initData); mCommunicator= communicator; if (true == isStopped() || null == mCommunicator) return; mDbs = getDatabaseProxy(); if (true == isStopped() || null == mDbs) return; logger.info("Successfully initialized a communicator instance."); databaseServicesProxy = IceProxyFactory.getDatabaseServicesProxy(communicator); if (databaseServicesProxy == null) { logger.error("Unable to obtain DatabaseServices Proxy. Exiting."); shutdown(); // shutdown does an exit } } catch (Ice.LocalException ex) { logger.error("Exception caught starting commuicator: " + ex.getMessage()); ex.printStackTrace(); shutdown(); } } private static RMXUtil objUtil = null; synchronized /** * @param args */ public static void main(String[] args) { private static String[] cmdLineArgs = new String[4]; // cmdLineArgs = args; String computerName=null; try { computerName= InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } cmdLineArgs[0]="--IceSSL.Keystore="+computerName+".ADS.POLYCOMRP.NET.P12"; System.out.println("Entering Commad NodeStatus"+cmdLineArgs[0]); cmdLineArgs[1]="--IceSSL.KeystorePassword=HP:-)H8L01!"; cmdLineArgs[2]="--IceSSL.Password=HP:-)H8L01!"; cmdLineArgs[3]="10.251.128.2"; System.out.println(cmdLineArgs[3]); RMXUtil objUtil= new RMXUtil(cmdLineArgs); nodeRmxList=objUtil.getEndpointStatus(); for(int m=0;m