Search in sources :

Example 21 with IoSession

use of org.apache.mina.core.session.IoSession 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(':', '/'));
            }

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

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

            @Override
            public void serviceActivated(final IoService service) {
            }

            @Override
            public void serviceDeactivated(final IoService service) {
            }

            @Override
            public void serviceIdle(final IoService service, final IdleStatus idleStatus) {
            }

            @Override
            public void sessionClosed(final IoSession ioSession) {
            }
        });
    }
}
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) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) IoSession(org.apache.mina.core.session.IoSession)

Aggregations

IoSession (org.apache.mina.core.session.IoSession)21 InetSocketAddress (java.net.InetSocketAddress)7 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)4 IOException (java.io.IOException)3 DnsProtocolHandler (org.apache.directory.server.dns.protocol.DnsProtocolHandler)3 UdpTransport (org.apache.directory.server.protocol.shared.transport.UdpTransport)3 ConnectFuture (org.apache.mina.core.future.ConnectFuture)3 DatagramSessionConfig (org.apache.mina.transport.socket.DatagramSessionConfig)3 ArrayList (java.util.ArrayList)2 DnsException (org.apache.directory.server.dns.DnsException)2 IoConnector (org.apache.mina.core.service.IoConnector)2 IoHandlerAdapter (org.apache.mina.core.service.IoHandlerAdapter)2 ProtocolEncoder (org.apache.mina.filter.codec.ProtocolEncoder)2 DatagramAcceptor (org.apache.mina.transport.socket.DatagramAcceptor)2 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 SocketAddress (java.net.SocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1