Search in sources :

Example 6 with IoSession

use of org.apache.mina.core.session.IoSession in project streamsx.topology by IBMStreams.

the class TupleCollection method addTCPServerAndSink.

/**
     * Add a TCP server that will list for tuples to be directed to handlers.
     * Adds a sink to the topology to capture those tuples and deliver them to
     * the current jvm to run Junit type tests.
     */
private void addTCPServerAndSink() throws Exception {
    tcpServer = new TCPTestServer(0, new IoHandlerAdapter() {

        @Override
        public void messageReceived(IoSession session, Object message) throws Exception {
            TestTuple tuple = (TestTuple) message;
            TestTupleInjector injector = injectors.get(tuple.getTesterId());
            injector.tuple(tuple.getTupleData());
        }
    });
    InetSocketAddress testAddr = tcpServer.start();
    addTesterSink(testAddr);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IoHandlerAdapter(org.apache.mina.core.service.IoHandlerAdapter) IoSession(org.apache.mina.core.session.IoSession)

Example 7 with IoSession

use of org.apache.mina.core.session.IoSession in project vert.x by eclipse.

the class FakeDNSServer method start.

@Override
public void start() throws IOException {
    UdpTransport transport = new UdpTransport("127.0.0.1", port);
    setTransports(transport);
    acceptor = transport.getAcceptor();
    acceptor.setHandler(new DnsProtocolHandler(this, store) {

        @Override
        public void sessionCreated(IoSession session) throws Exception {
            // Use our own codec to support AAAA testing
            session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory()));
        }
    });
    // Allow the port to be reused even if the socket is in TIME_WAIT state
    ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true);
    // Start the listener
    acceptor.bind();
}
Also used : UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) DatagramSessionConfig(org.apache.mina.transport.socket.DatagramSessionConfig) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) DnsProtocolHandler(org.apache.directory.server.dns.protocol.DnsProtocolHandler) IOException(java.io.IOException) IoSession(org.apache.mina.core.session.IoSession)

Example 8 with IoSession

use of org.apache.mina.core.session.IoSession in project Openfire by igniterealtime.

the class MINAStatCollector method stop.

/**
     * Stop collecting stats. all the {@link org.apache.mina.management.IoSessionStat} object will be removed of the
     * polled session attachements.
     */
public void stop() {
    synchronized (this) {
        service.removeListener(serviceListener);
        // stop worker
        worker.stop = true;
        worker.interrupt();
        while (worker.isAlive()) {
            try {
                worker.join();
            } catch (InterruptedException e) {
            //ignore since this is shutdown time
            }
        }
        for (IoSession session : polledSessions) {
            session.removeAttribute(KEY);
        }
        polledSessions.clear();
    }
}
Also used : IoSession(org.apache.mina.core.session.IoSession)

Example 9 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(':', '/'));
            }

            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)

Example 10 with IoSession

use of org.apache.mina.core.session.IoSession in project netty by netty.

the class TestDnsServer method start.

@Override
public void start() throws IOException {
    InetSocketAddress address = new InetSocketAddress(NetUtil.LOCALHOST4, 0);
    UdpTransport transport = new UdpTransport(address.getHostName(), address.getPort());
    setTransports(transport);
    DatagramAcceptor acceptor = transport.getAcceptor();
    acceptor.setHandler(new DnsProtocolHandler(this, store) {

        @Override
        public void sessionCreated(IoSession session) throws Exception {
            // USe our own codec to support AAAA testing
            session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory()));
        }
    });
    ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true);
    // Start the listener
    acceptor.bind();
}
Also used : UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) DatagramAcceptor(org.apache.mina.transport.socket.DatagramAcceptor) InetSocketAddress(java.net.InetSocketAddress) DatagramSessionConfig(org.apache.mina.transport.socket.DatagramSessionConfig) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) DnsProtocolHandler(org.apache.directory.server.dns.protocol.DnsProtocolHandler) DnsException(org.apache.directory.server.dns.DnsException) IOException(java.io.IOException) IoSession(org.apache.mina.core.session.IoSession)

Aggregations

IoSession (org.apache.mina.core.session.IoSession)11 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 DnsProtocolHandler (org.apache.directory.server.dns.protocol.DnsProtocolHandler)2 UdpTransport (org.apache.directory.server.protocol.shared.transport.UdpTransport)2 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)2 DatagramSessionConfig (org.apache.mina.transport.socket.DatagramSessionConfig)2 Field (java.lang.reflect.Field)1 SocketAddress (java.net.SocketAddress)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 JMException (javax.management.JMException)1 MBeanServer (javax.management.MBeanServer)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 SSLContext (javax.net.ssl.SSLContext)1 Exchange (org.apache.camel.Exchange)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1