You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Ersin Er <er...@gmail.com> on 2006/12/20 23:50:56 UTC
Fwd: sessionCreated event doesn't fire
Forwarding to the correct list..
---------- Forwarded message ----------
From: Luis Neves <lu...@co.sapo.pt>
Date: Dec 20, 2006 9:16 PM
Subject: sessionCreated event doesn't fire
To: dev@directory.apache.org
Hi all,
Using the latest code from trunk I'm experiencing a somewhat strange behaviour.
Running the code provided below and opening several telnet connections to the
socket doesn't always print "sessionCreated()", this behaviour is more evident
on windows but happens on linux also... can anyone confirm?
Did something change in the way we must setup an SocketAcceptor?
--
Luis Neves
Code below (beware wrapping):
********************************************************************************
import java.net.InetSocketAddress;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.executor.ExecutorFilter;
import org.apache.mina.transport.socket.nio.SocketAcceptor;
public class TestAcceptor
{
static final int PORT = 10007;
static final int NCPU = Runtime.getRuntime().availableProcessors();
static final int IO_THREADS = NCPU + 1;
static final int EVENT_THREADS = 10;
static final IoHandlerAdapter testHandler = new IoHandlerAdapter()
{
@Override
public void sessionCreated(IoSession iosession)
throws Exception
{
System.out.println("sessionCreated()");
}
@Override
public void sessionClosed(IoSession iosession)
{
System.out.println("sessionClosed()");
}
@Override
public void exceptionCaught(IoSession iosession,
Throwable cause)
{
System.out.println("exceptionCaught()");
}
};
public static void main(String[] args) throws Exception
{
ThreadPoolExecutor ioExecutor = new ThreadPoolExecutor(
IO_THREADS, IO_THREADS, 60, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>());
SocketAcceptor acceptor = new SocketAcceptor(IO_THREADS,
ioExecutor);
ThreadPoolExecutor eventExecutor = new ThreadPoolExecutor(
EVENT_THREADS, EVENT_THREADS * NCPU, 60,
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
acceptor.getFilterChain().addLast("threadPool",
new ExecutorFilter(eventExecutor));
acceptor.setReuseAddress(true);
acceptor.setLocalAddress(new InetSocketAddress(PORT));
acceptor.setHandler(testHandler);
acceptor.bind();
System.out.println("listening...");
}
}
--
Ersin