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);
}
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();
}
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();
}
}
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 {
}
});
}
}
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();
}
Aggregations