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(ipAddress, port);
setTransports(transport);
acceptor = transport.getAcceptor();
acceptor.setHandler(new DnsProtocolHandler(this, new RecordStore() {
@Override
public Set<ResourceRecord> getRecords(QuestionRecord question) throws DnsException {
RecordStore actual = store;
if (actual == null) {
return Collections.emptySet();
} else {
return actual.getRecords(question);
}
}
}) {
@Override
public void sessionCreated(IoSession session) throws Exception {
// Use our own codec to support AAAA testing
session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory()));
}
@Override
public void messageReceived(IoSession session, Object message) {
if (message instanceof DnsMessage) {
synchronized (FakeDNSServer.this) {
currentMessage.add((DnsMessage) message);
}
}
super.messageReceived(session, message);
}
});
// 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 pancm_project by xuwujing.
the class ClientTestServer method getIOSession.
/**
* Get io session io session.
*
* @param connector the connector
* @return the io session
*/
public IoSession getIOSession(IoConnector connector) {
ConnectFuture future = connector.connect(new InetSocketAddress("192.168.2.55", 1255));
// 等待是否连接成功,相当于是转异步执行为同步执行。
future.awaitUninterruptibly();
// 连接成功后获取会话对象。 如果没有上面的等待, 由于connect()方法是异步的, session可能会无法获取。
IoSession session = null;
try {
session = future.getSession();
} catch (Exception e) {
e.printStackTrace();
}
return session;
}
use of org.apache.mina.core.session.IoSession in project pancm_project by xuwujing.
the class ClientTestServer method main.
/**
* The entry point of application.
*
* @param args the input arguments
*/
public static void main(String[] args) {
for (int i = 0; i < 4000; i++) {
ClientTestServer client = new ClientTestServer();
IoConnector connector = client.creatClient();
IoSession session = client.getIOSession(connector);
client.sendMsg(session, Arrays.toString(new byte[1000]) + ":" + System.currentTimeMillis());
}
}
use of org.apache.mina.core.session.IoSession in project netty by netty.
the class TestDnsServer method start.
/**
* Start the {@link TestDnsServer} but drop all {@code AAAA} queries and not send any response to these at all.
*/
public void start(final boolean dropAAAAQueries) 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) {
// USe our own codec to support AAAA testing
session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory(dropAAAAQueries)));
}
});
((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 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();
}
}
Aggregations