public static int startAgent(SSOServerMonConfig monConfig){
  monHtmlPort=monConfig.htmlPort;
  monSnmpPort=monConfig.snmpPort;
  monRmiPort=monConfig.rmiPort;
  monitoringEnabled=monConfig.monitoringEnabled;
  monHtmlPortEnabled=monConfig.monHtmlPortEnabled;
  monSnmpPortEnabled=monConfig.monSnmpPortEnabled;
  monRmiPortEnabled=monConfig.monRmiPortEnabled;
  monAuthFilePath=monConfig.monAuthFilePath;
  policyWindow=monConfig.policyWindow;
  sessionWindow=monConfig.sessionWindow;
  String classMethod="Agent.startAgent:";
  String serverPort=agentSvrInfo.serverPort;
  if ((monAuthFilePath != null) && (monAuthFilePath.endsWith("opensso_mon_auth"))) {
    File monAuthFile=new File(monAuthFilePath);
    File newMonAuthFile=new File(monAuthFile.getParentFile() + "/" + "openam_mon_auth");
    if (monAuthFile.renameTo(newMonAuthFile)) {
      monAuthFilePath=newMonAuthFile.getAbsolutePath();
    }
  }
  if (debug.messageEnabled()) {
    debug.message(classMethod + "entry:\n" + "    htmlPort = "+ monHtmlPort+ "\n"+ "    authFilePath = "+ monAuthFilePath+ "\n"+ "    snmpPort = "+ monSnmpPort+ "\n"+ "    rmiPort = "+ monRmiPort+ "\n"+ "    monEna = "+ monitoringEnabled+ "\n"+ "    htmlEna = "+ monHtmlPortEnabled+ "\n"+ "    snmpEna = "+ monSnmpPortEnabled+ "\n"+ "    rmiEna = "+ monRmiPortEnabled+ "\n"+ "    policyWindow = "+ policyWindow+ "\n"+ "    sessionWindow = "+ sessionWindow+ "\n"+ "    serverPort = "+ serverPort+ "\n");
  }
  if (!monitoringEnabled) {
    debug.warning(classMethod + "Monitoring configured as disabled.");
    return MON_CONFIG_DISABLED;
  }
  try {
    int sport=Integer.parseInt(serverPort);
    if (monRmiPort == sport) {
      debug.error(classMethod + "RMI port conflicts with OpenSSO server port (" + sport+ "); Monitoring disabled.");
      return MON_RMICONNECTOR_PROBLEM;
    }
    if (monHtmlPort == sport) {
      monHtmlPortEnabled=false;
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "HTML port conflicts with OpenSSO server port (" + sport+ "); Monitoring HTML port disabled.");
      }
    }
    if (monSnmpPort == sport) {
      monSnmpPortEnabled=false;
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "SNMP port conflicts with OpenSSO server port (" + sport+ "); Monitoring SNMP port disabled.");
      }
    }
  }
 catch (  NumberFormatException nfe) {
    debug.error(classMethod + "Server port (" + serverPort+ " is invalid: "+ nfe.getMessage());
  }
  if (debug.messageEnabled()) {
    debug.message(classMethod + "config:\n" + "    monitoring Enabled = "+ monitoringEnabled+ "\n"+ "    HTML Port = "+ monHtmlPort+ ", enabled = "+ monHtmlPortEnabled+ "\n"+ "    SNMP Port = "+ monSnmpPort+ ", enabled = "+ monSnmpPortEnabled+ "\n"+ "    RMI Port = "+ monRmiPort+ ", enabled = "+ monRmiPortEnabled+ "\n"+ "    SessionWindow size = "+ sessionWindow+ "\n"+ "    PolicyWindow size = "+ policyWindow+ "\n");
  }
  List<MBeanServer> servers=null;
  try {
    servers=MBeanServerFactory.findMBeanServer(null);
  }
 catch (  SecurityException ex) {
    if (debug.warningEnabled()) {
      debug.warning(classMethod + "findMBeanServer permission error: " + ex.getMessage());
    }
  }
  if (debug.messageEnabled()) {
    debug.message(classMethod + "MBeanServer list is not empty: " + ((servers != null) && !servers.isEmpty()));
  }
  if ((servers != null) && !servers.isEmpty()) {
    server=servers.get(0);
  }
 else {
    try {
      server=MBeanServerFactory.createMBeanServer();
    }
 catch (    SecurityException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "createMBeanServer permission error: " + ex.getMessage());
      }
      return MON_MBEANSRVR_PROBLEM;
    }
catch (    JMRuntimeException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "createMBeanServer JMRuntime error: " + ex.getMessage());
      }
      return MON_MBEANSRVR_PROBLEM;
    }
catch (    ClassCastException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "createMBeanServer ClassCast error: " + ex.getMessage());
      }
      return MON_MBEANSRVR_PROBLEM;
    }
  }
  if (server == null) {
    if (debug.warningEnabled()) {
      debug.warning(classMethod + "no MBeanServer");
    }
    return MON_MBEANSRVR_PROBLEM;
  }
  String domain=server.getDefaultDomain();
  try {
    sunMibObjName=new ObjectName("snmp:class=SUN_OPENSSO_SERVER_MIB");
    forgerockCtsMibObjName=new ObjectName("snmp:class=FORGEROCK_OPENAM_CTS_MIB");
    forgerockPolicyMibObjName=new ObjectName("snmp:class=FORGEROCK_OPENAM_POLICY_MIB");
    forgerockSessionMibObjName=new ObjectName("snmp:class=FORGEROCK_OPENAM_SESSION_MIB");
    if (debug.messageEnabled()) {
      debug.message(classMethod + "Adding SUN_OPENSSO_SERVER_MIB to MBean server " + "with name '"+ sunMibObjName+ "'");
      debug.message(classMethod + "Adding FORGEROCK_OPENAM_CTS_MIB to MBean server " + "with name '"+ forgerockCtsMibObjName+ "'");
    }
  }
 catch (  MalformedObjectNameException ex) {
    if (debug.warningEnabled()) {
      debug.warning(classMethod + "Error getting ObjectName for the MIB: " + ex.getMessage());
    }
    return MON_CREATEMIB_PROBLEM;
  }
  try {
    sunMib=new SUN_OPENSSO_SERVER_MIBImpl();
    forgerockCtsMib=new FORGEROCK_OPENAM_CTS_MIBImpl();
    forgerockPolicyMib=new FORGEROCK_OPENAM_POLICY_MIBImpl();
    forgerockSessionMib=new FORGEROCK_OPENAM_SESSION_MIBImpl();
  }
 catch (  RuntimeException ex) {
    debug.error(classMethod + "Runtime error instantiating MIB",ex);
    return MON_CREATEMIB_PROBLEM;
  }
catch (  Exception ex) {
    debug.error(classMethod + "Error instantiating MIB",ex);
    return MON_CREATEMIB_PROBLEM;
  }
  try {
    server.registerMBean(sunMib,sunMibObjName);
    server.registerMBean(forgerockCtsMib,forgerockCtsMibObjName);
    server.registerMBean(forgerockPolicyMib,forgerockPolicyMibObjName);
    server.registerMBean(forgerockSessionMib,forgerockSessionMibObjName);
  }
 catch (  RuntimeOperationsException ex) {
    if (debug.warningEnabled()) {
      debug.warning(classMethod + "Null parameter or no object name for MIB specified: " + ex.getMessage());
    }
    return MON_CREATEMIB_PROBLEM;
  }
catch (  InstanceAlreadyExistsException ex) {
    if (debug.warningEnabled()) {
      debug.warning(classMethod + "Error registering MIB MBean: " + ex.getMessage());
    }
  }
catch (  MBeanRegistrationException ex) {
    if (debug.warningEnabled()) {
      debug.warning(classMethod + "Error registering MIB MBean: " + ex.getMessage());
    }
    return MON_CREATEMIB_PROBLEM;
  }
catch (  NotCompliantMBeanException ex) {
    if (debug.warningEnabled()) {
      debug.warning(classMethod + "Error registering MIB MBean: " + ex.getMessage());
    }
    return MON_CREATEMIB_PROBLEM;
  }
  boolean monHTMLStarted=false;
  boolean monSNMPStarted=false;
  boolean monRMIStarted=false;
  if (monHtmlPortEnabled) {
    try {
      htmlObjName=new ObjectName(domain + ":class=HtmlAdaptorServer,protocol=html,port=" + monHtmlPort);
      if (debug.messageEnabled()) {
        debug.message(classMethod + "Adding HTML adaptor to MBean server with name '" + htmlObjName+ "'\n    "+ "HTML adaptor is bound on TCP port "+ monHtmlPort);
      }
      Map<String,String> users=MonitoringUtil.getMonAuthList(monAuthFilePath);
      if (users != null) {
        AuthInfo authInfo[]=new AuthInfo[users.size()];
        int i=0;
        for (        Map.Entry<String,String> entry : users.entrySet()) {
          authInfo[i]=new AuthInfo(entry.getKey(),entry.getValue());
          i++;
        }
        htmlAdaptor=new HtmlAdaptorServer(monHtmlPort,authInfo);
      }
 else {
        if (debug.warningEnabled()) {
          debug.warning(classMethod + "HTML monitoring interface disabled; no " + "authentication file found");
        }
        htmlAdaptor=null;
      }
      if (htmlAdaptor == null) {
        if (debug.warningEnabled()) {
          debug.warning(classMethod + "HTTP port " + monHtmlPort+ " unavailable or invalid. "+ "Monitoring HTML adaptor not started.");
        }
      }
 else {
        server.registerMBean(htmlAdaptor,htmlObjName);
        htmlAdaptor.start();
        monHTMLStarted=true;
      }
    }
 catch (    MalformedObjectNameException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "Error getting ObjectName for HTML adaptor: " + ex.getMessage());
      }
    }
catch (    NullPointerException ex) {
      debug.error(classMethod + "NPE getting ObjectName for HTML adaptor",ex);
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "NPE getting ObjectName for HTML adaptor: " + ex.getMessage());
      }
    }
catch (    InstanceAlreadyExistsException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "Error registering HTML adaptor MBean: " + ex.getMessage());
      }
    }
catch (    MBeanRegistrationException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "Error registering HTML adaptor MBean: " + ex.getMessage());
      }
    }
catch (    NotCompliantMBeanException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "Error registering HTML adaptor MBean: " + ex.getMessage());
      }
    }
  }
 else {
    debug.warning(classMethod + "Monitoring HTML port not enabled in configuration.");
  }
  if (monSnmpPortEnabled) {
    try {
      snmpObjName=new ObjectName(domain + ":class=SnmpAdaptorServer,protocol=snmp,port=" + monSnmpPort);
      if (debug.messageEnabled()) {
        debug.message(classMethod + "Adding SNMP adaptor to MBean server with name '" + snmpObjName+ "'\n    "+ "SNMP Adaptor is bound on UDP port "+ monSnmpPort);
      }
      snmpAdaptor=new SnmpAdaptorServer(monSnmpPort);
      if (snmpAdaptor == null) {
        if (debug.warningEnabled()) {
          debug.warning(classMethod + "Unable to get SNMP adaptor.");
        }
      }
 else {
        server.registerMBean(snmpAdaptor,snmpObjName);
        snmpAdaptor.start();
        if (debug.messageEnabled()) {
          debug.message(classMethod + "Sending a coldStart SNMP trap to each " + "destination defined in the ACL file...");
        }
        snmpAdaptor.setTrapPort(new Integer(monSnmpPort + 1));
        snmpAdaptor.snmpV1Trap(0,0,null);
        if (debug.messageEnabled()) {
          debug.message(classMethod + "Done sending coldStart.");
        }
        sunMib.setSnmpAdaptor(snmpAdaptor);
        forgerockCtsMib.setSnmpAdaptor(snmpAdaptor);
        forgerockPolicyMib.setSnmpAdaptor(snmpAdaptor);
        forgerockSessionMib.setSnmpAdaptor(snmpAdaptor);
        monSNMPStarted=true;
      }
    }
 catch (    Exception ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "Error while setting up SNMP adaptor " + ex.getMessage());
      }
      if (ex instanceof IOException || ex instanceof SnmpStatusException) {
        monSNMPStarted=true;
      }
    }
  }
 else {
    debug.warning(classMethod + "Monitoring SNMP port not enabled.");
  }
  if (monRmiPortEnabled) {
    try {
      registry=LocateRegistry.createRegistry(monRmiPort);
      JMXServiceURL url=new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + monRmiPort + "/server");
      cs=JMXConnectorServerFactory.newJMXConnectorServer(url,null,server);
      cs.start();
      monRMIStarted=true;
    }
 catch (    MalformedURLException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "Error getting JMXServiceURL or JMXConnectorServer " + "for RMI adaptor: "+ ex.getMessage());
      }
    }
catch (    NullPointerException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "Error getting JMXServiceURL or JMXConnectorServer " + "for RMI adaptor: "+ ex.getMessage());
      }
    }
catch (    IOException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "Error getting JMXConnectorServer for, or starting " + "RMI adaptor: "+ ex.getMessage());
      }
    }
catch (    IllegalStateException ex) {
      if (debug.warningEnabled()) {
        debug.warning(classMethod + "Illegal State Error from JMXConnectorServer for " + "RMI adaptor: "+ ex.getMessage());
      }
    }
catch (    Exception ex) {
      debug.error(classMethod + "Error starting RMI: executing rmiregistry " + monRmiPort+ ".",ex);
    }
  }
 else {
    debug.warning(classMethod + "Monitoring RMI port not enabled.");
  }
  if (!monRMIStarted && !monSNMPStarted && !monHTMLStarted) {
    debug.warning(classMethod + "No Monitoring interfaces started; monitoring disabled.");
    return MON_RMICONNECTOR_PROBLEM;
  }
 else {
    agentStarted=true;
    startMonitoringAgent(agentSvrInfo);
    return 0;
  }
}

public static int startAgent ( SSOServerMonConfig monConfig ) { monHtmlPort = monConfig . htmlPort ; monSnmpPort = monConfig . snmpPort ; monRmiPort = monConfig . rmiPort ; monitoringEnabled = monConfig . monitoringEnabled ; monHtmlPortEnabled = monConfig . monHtmlPortEnabled ; monSnmpPortEnabled = monConfig . monSnmpPortEnabled ; monRmiPortEnabled = monConfig . monRmiPortEnabled ; monAuthFilePath = monConfig . monAuthFilePath ; policyWindow = monConfig . policyWindow ; sessionWindow = monConfig . sessionWindow ; String classMethod = "Agent.startAgent:" ; String serverPort = agentSvrInfo . serverPort ; if ( ( monAuthFilePath != null ) && ( monAuthFilePath . endsWith ( "opensso_mon_auth" ) ) ) { File monAuthFile = new File ( monAuthFilePath ) ; File newMonAuthFile = new File ( monAuthFile . getParentFile ( ) + "/" + "openam_mon_auth" ) ; if ( monAuthFile . renameTo ( newMonAuthFile ) ) { monAuthFilePath = newMonAuthFile . getAbsolutePath ( ) ; } } if ( debug . messageEnabled ( ) ) { debug . message ( classMethod + "entry:\n" + "    htmlPort = " + monHtmlPort + "\n" + "    authFilePath = " + monAuthFilePath + "\n" + "    snmpPort = " + monSnmpPort + "\n" + "    rmiPort = " + monRmiPort + "\n" + "    monEna = " + monitoringEnabled + "\n" + "    htmlEna = " + monHtmlPortEnabled + "\n" + "    snmpEna = " + monSnmpPortEnabled + "\n" + "    rmiEna = " + monRmiPortEnabled + "\n" + "    policyWindow = " + policyWindow + "\n" + "    sessionWindow = " + sessionWindow + "\n" + "    serverPort = " + serverPort + "\n" ) ; } if ( ! monitoringEnabled ) { debug . warning ( classMethod + "Monitoring configured as disabled." ) ; return MON_CONFIG_DISABLED ; } try { int sport = Integer . parseInt ( serverPort ) ; if ( monRmiPort == sport ) { debug . error ( classMethod + "RMI port conflicts with OpenSSO server port (" + sport + "); Monitoring disabled." ) ; return MON_RMICONNECTOR_PROBLEM ; } if ( monHtmlPort == sport ) { monHtmlPortEnabled = false ; if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "HTML port conflicts with OpenSSO server port (" + sport + "); Monitoring HTML port disabled." ) ; } } if ( monSnmpPort == sport ) { monSnmpPortEnabled = false ; if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "SNMP port conflicts with OpenSSO server port (" + sport + "); Monitoring SNMP port disabled." ) ; } } } catch ( NumberFormatException nfe ) { debug . error ( classMethod + "Server port (" + serverPort + " is invalid: " + nfe . getMessage ( ) ) ; } if ( debug . messageEnabled ( ) ) { debug . message ( classMethod + "config:\n" + "    monitoring Enabled = " + monitoringEnabled + "\n" + "    HTML Port = " + monHtmlPort + ", enabled = " + monHtmlPortEnabled + "\n" + "    SNMP Port = " + monSnmpPort + ", enabled = " + monSnmpPortEnabled + "\n" + "    RMI Port = " + monRmiPort + ", enabled = " + monRmiPortEnabled + "\n" + "    SessionWindow size = " + sessionWindow + "\n" + "    PolicyWindow size = " + policyWindow + "\n" ) ; } List < MBeanServer > servers = null ; try { servers = MBeanServerFactory . findMBeanServer ( null ) ; } catch ( SecurityException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "findMBeanServer permission error: " + ex . getMessage ( ) ) ; } } if ( debug . messageEnabled ( ) ) { debug . message ( classMethod + "MBeanServer list is not empty: " + ( ( servers != null ) && ! servers . isEmpty ( ) ) ) ; } if ( ( servers != null ) && ! servers . isEmpty ( ) ) { server = servers . get ( 0 ) ; } else { try { server = MBeanServerFactory . createMBeanServer ( ) ; } catch ( SecurityException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "createMBeanServer permission error: " + ex . getMessage ( ) ) ; } return MON_MBEANSRVR_PROBLEM ; } catch ( JMRuntimeException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "createMBeanServer JMRuntime error: " + ex . getMessage ( ) ) ; } return MON_MBEANSRVR_PROBLEM ; } catch ( ClassCastException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "createMBeanServer ClassCast error: " + ex . getMessage ( ) ) ; } return MON_MBEANSRVR_PROBLEM ; } } if ( server == null ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "no MBeanServer" ) ; } return MON_MBEANSRVR_PROBLEM ; } String domain = server . getDefaultDomain ( ) ; try { sunMibObjName = new ObjectName ( "snmp:class=SUN_OPENSSO_SERVER_MIB" ) ; forgerockCtsMibObjName = new ObjectName ( "snmp:class=FORGEROCK_OPENAM_CTS_MIB" ) ; forgerockPolicyMibObjName = new ObjectName ( "snmp:class=FORGEROCK_OPENAM_POLICY_MIB" ) ; forgerockSessionMibObjName = new ObjectName ( "snmp:class=FORGEROCK_OPENAM_SESSION_MIB" ) ; if ( debug . messageEnabled ( ) ) { debug . message ( classMethod + "Adding SUN_OPENSSO_SERVER_MIB to MBean server " + "with name '" + sunMibObjName + "'" ) ; debug . message ( classMethod + "Adding FORGEROCK_OPENAM_CTS_MIB to MBean server " + "with name '" + forgerockCtsMibObjName + "'" ) ; } } catch ( MalformedObjectNameException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error getting ObjectName for the MIB: " + ex . getMessage ( ) ) ; } return MON_CREATEMIB_PROBLEM ; } try { sunMib = new SUN_OPENSSO_SERVER_MIBImpl ( ) ; forgerockCtsMib = new FORGEROCK_OPENAM_CTS_MIBImpl ( ) ; forgerockPolicyMib = new FORGEROCK_OPENAM_POLICY_MIBImpl ( ) ; forgerockSessionMib = new FORGEROCK_OPENAM_SESSION_MIBImpl ( ) ; } catch ( RuntimeException ex ) { debug . error ( classMethod + "Runtime error instantiating MIB" , ex ) ; return MON_CREATEMIB_PROBLEM ; } catch ( Exception ex ) { debug . error ( classMethod + "Error instantiating MIB" , ex ) ; return MON_CREATEMIB_PROBLEM ; } try { server . registerMBean ( sunMib , sunMibObjName ) ; server . registerMBean ( forgerockCtsMib , forgerockCtsMibObjName ) ; server . registerMBean ( forgerockPolicyMib , forgerockPolicyMibObjName ) ; server . registerMBean ( forgerockSessionMib , forgerockSessionMibObjName ) ; } catch ( RuntimeOperationsException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Null parameter or no object name for MIB specified: " + ex . getMessage ( ) ) ; } return MON_CREATEMIB_PROBLEM ; } catch ( InstanceAlreadyExistsException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error registering MIB MBean: " + ex . getMessage ( ) ) ; } } catch ( MBeanRegistrationException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error registering MIB MBean: " + ex . getMessage ( ) ) ; } return MON_CREATEMIB_PROBLEM ; } catch ( NotCompliantMBeanException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error registering MIB MBean: " + ex . getMessage ( ) ) ; } return MON_CREATEMIB_PROBLEM ; } boolean monHTMLStarted = false ; boolean monSNMPStarted = false ; boolean monRMIStarted = false ; if ( monHtmlPortEnabled ) { try { htmlObjName = new ObjectName ( domain + ":class=HtmlAdaptorServer,protocol=html,port=" + monHtmlPort ) ; if ( debug . messageEnabled ( ) ) { debug . message ( classMethod + "Adding HTML adaptor to MBean server with name '" + htmlObjName + "'\n    " + "HTML adaptor is bound on TCP port " + monHtmlPort ) ; } Map < String , String > users = MonitoringUtil . getMonAuthList ( monAuthFilePath ) ; if ( users != null ) { AuthInfo authInfo [ ] = new AuthInfo [ users . size ( ) ] ; int i = 0 ; for ( Map . Entry < String , String > entry : users . entrySet ( ) ) { authInfo [ i ] = new AuthInfo ( entry . getKey ( ) , entry . getValue ( ) ) ; i ++ ; } htmlAdaptor = new HtmlAdaptorServer ( monHtmlPort , authInfo ) ; } else { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "HTML monitoring interface disabled; no " + "authentication file found" ) ; } htmlAdaptor = null ; } if ( htmlAdaptor == null ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "HTTP port " + monHtmlPort + " unavailable or invalid. " + "Monitoring HTML adaptor not started." ) ; } } else { server . registerMBean ( htmlAdaptor , htmlObjName ) ; htmlAdaptor . start ( ) ; monHTMLStarted = true ; } } catch ( MalformedObjectNameException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error getting ObjectName for HTML adaptor: " + ex . getMessage ( ) ) ; } } catch ( NullPointerException ex ) { debug . error ( classMethod + "NPE getting ObjectName for HTML adaptor" , ex ) ; if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "NPE getting ObjectName for HTML adaptor: " + ex . getMessage ( ) ) ; } } catch ( InstanceAlreadyExistsException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error registering HTML adaptor MBean: " + ex . getMessage ( ) ) ; } } catch ( MBeanRegistrationException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error registering HTML adaptor MBean: " + ex . getMessage ( ) ) ; } } catch ( NotCompliantMBeanException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error registering HTML adaptor MBean: " + ex . getMessage ( ) ) ; } } } else { debug . warning ( classMethod + "Monitoring HTML port not enabled in configuration." ) ; } if ( monSnmpPortEnabled ) { try { snmpObjName = new ObjectName ( domain + ":class=SnmpAdaptorServer,protocol=snmp,port=" + monSnmpPort ) ; if ( debug . messageEnabled ( ) ) { debug . message ( classMethod + "Adding SNMP adaptor to MBean server with name '" + snmpObjName + "'\n    " + "SNMP Adaptor is bound on UDP port " + monSnmpPort ) ; } snmpAdaptor = new SnmpAdaptorServer ( monSnmpPort ) ; if ( snmpAdaptor == null ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Unable to get SNMP adaptor." ) ; } } else { server . registerMBean ( snmpAdaptor , snmpObjName ) ; snmpAdaptor . start ( ) ; if ( debug . messageEnabled ( ) ) { debug . message ( classMethod + "Sending a coldStart SNMP trap to each " + "destination defined in the ACL file..." ) ; } snmpAdaptor . setTrapPort ( new Integer ( monSnmpPort + 1 ) ) ; snmpAdaptor . snmpV1Trap ( 0 , 0 , null ) ; if ( debug . messageEnabled ( ) ) { debug . message ( classMethod + "Done sending coldStart." ) ; } sunMib . setSnmpAdaptor ( snmpAdaptor ) ; forgerockCtsMib . setSnmpAdaptor ( snmpAdaptor ) ; forgerockPolicyMib . setSnmpAdaptor ( snmpAdaptor ) ; forgerockSessionMib . setSnmpAdaptor ( snmpAdaptor ) ; monSNMPStarted = true ; } } catch ( Exception ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error while setting up SNMP adaptor " + ex . getMessage ( ) ) ; } if ( ex instanceof IOException || ex instanceof SnmpStatusException ) { monSNMPStarted = true ; } } } else { debug . warning ( classMethod + "Monitoring SNMP port not enabled." ) ; } if ( monRmiPortEnabled ) { try { registry = LocateRegistry . createRegistry ( monRmiPort ) ; JMXServiceURL url = new JMXServiceURL ( "service:jmx:rmi:///jndi/rmi://localhost:" + monRmiPort + "/server" ) ; cs = JMXConnectorServerFactory . newJMXConnectorServer ( url , null , server ) ; cs . start ( ) ; monRMIStarted = true ; } catch ( MalformedURLException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error getting JMXServiceURL or JMXConnectorServer " + "for RMI adaptor: " + ex . getMessage ( ) ) ; } } catch ( NullPointerException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error getting JMXServiceURL or JMXConnectorServer " + "for RMI adaptor: " + ex . getMessage ( ) ) ; } } catch ( IOException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Error getting JMXConnectorServer for, or starting " + "RMI adaptor: " + ex . getMessage ( ) ) ; } } catch ( IllegalStateException ex ) { if ( debug . warningEnabled ( ) ) { debug . warning ( classMethod + "Illegal State Error from JMXConnectorServer for " + "RMI adaptor: " + ex . getMessage ( ) ) ; } } catch ( Exception ex ) { debug . error ( classMethod + "Error starting RMI: executing rmiregistry " + monRmiPort + "." , ex ) ; } } else { debug . warning ( classMethod + "Monitoring RMI port not enabled." ) ; } if ( ! monRMIStarted && ! monSNMPStarted && ! monHTMLStarted ) { debug . warning ( classMethod + "No Monitoring interfaces started; monitoring disabled." ) ; return MON_RMICONNECTOR_PROBLEM ; } else { agentStarted = true ; startMonitoringAgent ( agentSvrInfo ) ; return 0 ; } }
this method starts up the monitoring agent from the common / configmonitoring module ( load - on - startup or at the end of amsetupservlet / configuration ) . since web - app startup is sensitive to exceptions in load - on - startup stuff , this has quite a few try / catch blocks . if any of html , snmp , or rmi adaptors has a problem getting created or started , attempts to create / start the others will be made ; if at least one adaptor is started , monitoring will be " active " ( agent . isrunning ( ) will return true ) .
