You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Luis Neves <lu...@co.sapo.pt> on 2006/12/20 20:16:28 UTC
sessionCreated event doesn't fire
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...");
}
}
Fwd: sessionCreated event doesn't fire
Posted by Ersin Er <er...@gmail.com>.
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
Re: sessionCreated event doesn't fire
Posted by Trustin Lee <tr...@gmail.com>.
Please try to increase the number of the threads in the I/O thread pool. If
you specified IO_THREADS in the constructor, the executor specified along
with that number should be able to allocate one more threads than it (i.e.
IO_THREADS + 1).
HTH,
Trustin
On 12/21/06, Luis Neves <lu...@co.sapo.pt> wrote:
>
> 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...");
>
> }
> }
>
>
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41 4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4 455E 1C62 A7DC 0255 ECA6
Re: sessionCreated event doesn't fire
Posted by Trustin Lee <tr...@gmail.com>.
Please try to increase the number of the threads in the I/O thread pool. If
you specified IO_THREADS in the constructor, the executor specified along
with that number should be able to allocate one more threads than it (i.e.
IO_THREADS + 1).
HTH,
Trustin
On 12/21/06, Luis Neves <lu...@co.sapo.pt> wrote:
>
> 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...");
>
> }
> }
>
>
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41 4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4 455E 1C62 A7DC 0255 ECA6