Search in sources :

Example 1 with IoSessionMBean

use of org.apache.mina.integration.jmx.IoSessionMBean in project Openfire by igniterealtime.

the class MINAConnectionAcceptor method configureJMX.

private void configureJMX(NioSocketAcceptor acceptor, String suffix) {
    final String prefix = IoServiceMBean.class.getPackage().getName();
    // monitor the IoService
    try {
        final IoServiceMBean mbean = new IoServiceMBean(acceptor);
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        final ObjectName name = new ObjectName(prefix + ":type=SocketAcceptor,name=" + suffix);
        mbs.registerMBean(mbean, name);
    // mbean.startCollectingStats(JiveGlobals.getIntProperty("xmpp.socket.jmx.interval", 60000));
    } catch (JMException ex) {
        Log.warn("Failed to register MINA acceptor mbean (JMX): " + ex);
    }
    // optionally register IoSession mbeans (one per session)
    if (JiveGlobals.getBooleanProperty("xmpp.socket.jmx.sessions", false)) {
        acceptor.addListener(new IoServiceListener() {

            private ObjectName getObjectNameForSession(IoSession session) throws MalformedObjectNameException {
                return new ObjectName(prefix + ":type=IoSession,name=" + session.getRemoteAddress().toString().replace(':', '/'));
            }

            public void sessionCreated(IoSession session) {
                try {
                    ManagementFactory.getPlatformMBeanServer().registerMBean(new IoSessionMBean(session), getObjectNameForSession(session));
                } catch (JMException ex) {
                    Log.warn("Failed to register MINA session mbean (JMX): " + ex);
                }
            }

            public void sessionDestroyed(IoSession session) {
                try {
                    ManagementFactory.getPlatformMBeanServer().unregisterMBean(getObjectNameForSession(session));
                } catch (JMException ex) {
                    Log.warn("Failed to unregister MINA session mbean (JMX): " + ex);
                }
            }

            public void serviceActivated(IoService service) throws Exception {
            }

            public void serviceDeactivated(IoService service) throws Exception {
            }

            public void serviceIdle(IoService service, IdleStatus idleStatus) throws Exception {
            }
        });
    }
}
Also used : IoSessionMBean(org.apache.mina.integration.jmx.IoSessionMBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) IoServiceMBean(org.apache.mina.integration.jmx.IoServiceMBean) IdleStatus(org.apache.mina.core.session.IdleStatus) JMException(javax.management.JMException) IoServiceListener(org.apache.mina.core.service.IoServiceListener) IoService(org.apache.mina.core.service.IoService) MalformedObjectNameException(javax.management.MalformedObjectNameException) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) IoSession(org.apache.mina.core.session.IoSession)

Aggregations

JMException (javax.management.JMException)1 MBeanServer (javax.management.MBeanServer)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 IoService (org.apache.mina.core.service.IoService)1 IoServiceListener (org.apache.mina.core.service.IoServiceListener)1 IdleStatus (org.apache.mina.core.session.IdleStatus)1 IoSession (org.apache.mina.core.session.IoSession)1 IoServiceMBean (org.apache.mina.integration.jmx.IoServiceMBean)1 IoSessionMBean (org.apache.mina.integration.jmx.IoSessionMBean)1