Search in sources :

Example 1 with ServiceDaemon

use of org.opennms.netmgt.model.ServiceDaemon in project opennms by OpenNMS.

the class JmxDaemonStatusDao method buildProxy.

private ServiceDaemon buildProxy(ObjectName mBeanName) {
    MBeanProxyFactoryBean mBeanProxyFactoryBean = new MBeanProxyFactoryBean();
    try {
        mBeanProxyFactoryBean.setObjectName(mBeanName.getCanonicalName());
    } catch (MalformedObjectNameException e) {
        throw new JmxObjectNameException("Object name '" + mBeanName.getCanonicalName() + "' was malformed!", e);
    }
    mBeanProxyFactoryBean.setProxyInterface(ServiceDaemon.class);
    mBeanProxyFactoryBean.afterPropertiesSet();
    return (ServiceDaemon) mBeanProxyFactoryBean.getObject();
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanProxyFactoryBean(org.springframework.jmx.access.MBeanProxyFactoryBean) ServiceDaemon(org.opennms.netmgt.model.ServiceDaemon)

Example 2 with ServiceDaemon

use of org.opennms.netmgt.model.ServiceDaemon in project opennms by OpenNMS.

the class JmxDaemonStatusDao method getCurrentDaemonStatus.

/**
	 * <p>getCurrentDaemonStatus</p>
	 *
	 * @return a {@link java.util.Map} object.
	 */
@Override
public Map<String, ServiceInfo> getCurrentDaemonStatus() {
    // TODO Auto-generated method stub
    Map<String, ServiceInfo> serviceInfo = new HashMap<String, ServiceInfo>();
    // go to the JMX Server and ask for all the MBeans...
    // ArrayList<MBeanServer> mbeans =
    // MBeanServerFactory.findMBeanServer(null);
    // get their names and corresponding status and plugit into Service Info
    Set<ObjectName> mBeanNames;
    try {
        mBeanNames = queryMbeanServerForNames(new ObjectName("opennms:*"), null);
    } catch (MalformedObjectNameException e) {
        throw new JmxObjectNameException("Object name 'opennms:*' was malformed!", e);
    } catch (NullPointerException e) {
        throw new JmxObjectNameException("Object name param is null.", e);
    }
    for (ObjectName mBeanName : mBeanNames) {
        ServiceDaemon serviceDaemon = buildProxy(mBeanName);
        String name = serviceDaemon.getName();
        String status = serviceDaemon.getStatusText();
        serviceInfo.put(name, new ServiceInfo(name, status));
    }
    // Map the name of the service to ServiceInfo...
    // for testing adding a dummy service info node...
    serviceInfo.put("test", new ServiceInfo("test", "started"));
    return Collections.unmodifiableMap(serviceInfo);
}
Also used : ServiceInfo(org.opennms.netmgt.model.ServiceInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException) HashMap(java.util.HashMap) ServiceDaemon(org.opennms.netmgt.model.ServiceDaemon) ObjectName(javax.management.ObjectName)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)2 ServiceDaemon (org.opennms.netmgt.model.ServiceDaemon)2 HashMap (java.util.HashMap)1 ObjectName (javax.management.ObjectName)1 ServiceInfo (org.opennms.netmgt.model.ServiceInfo)1 MBeanProxyFactoryBean (org.springframework.jmx.access.MBeanProxyFactoryBean)1