Deyan Pandulev created DIRMINA-924:
--------------------------------------

             Summary: Custom executor for mina acceptor
                 Key: DIRMINA-924
                 URL: https://issues.apache.org/jira/browse/DIRMINA-924
             Project: MINA
          Issue Type: Improvement
          Components: Core
    Affects Versions: 2.0.7
         Environment: Debian squeeze 2.6.32-5-amd64 jdk1.6.0_32
            Reporter: Deyan Pandulev


The problem is when using custom executor with the acceptor. In that case the 
opened processes are not cleaned properly. So if my custom executor use 
SimpleIoProcessorPool with 5 processors when activate and deactive they remain 
open.

Step 1:
Activate and lsof -java_pid will produce:

java    13796 deyan    4r   REG                8,9   644783 47039005 
/home/deyan/install/apache mina/apache-mina-2.0.7/dist/mina-core-2.0.7.jar
java    13796 deyan    5r   REG                8,9    26176 47039015 
/home/deyan/install/apache mina/apache-mina-2.0.7/lib/slf4j-api-1.6.6.jar
java    13796 deyan    6r  FIFO                0,8      0t0   143881 pipe
java    13796 deyan    7r  FIFO                0,8      0t0   143881 pipe
java    13796 deyan    8u  0000                0,9        0      618 anon_inode
java    13796 deyan    9u  FIFO                0,8      0t0   143882 pipe
java    13796 deyan   10r  FIFO                0,8      0t0   143882 pipe
java    13796 deyan   11w  0000                0,9        0      618 anon_inode
java    13796 deyan   12u  FIFO                0,8      0t0   143883 pipe
java    13796 deyan   13u  FIFO                0,8      0t0   143883 pipe
java    13796 deyan   14r  0000                0,9        0      618 anon_inode
java    13796 deyan   15r  FIFO                0,8      0t0   143884 pipe
java    13796 deyan   16r  FIFO                0,8      0t0   143884 pipe
java    13796 deyan   17r  0000                0,9        0      618 anon_inode
java    13796 deyan   18r  FIFO                0,8      0t0   143885 pipe
java    13796 deyan   19r  FIFO                0,8      0t0   143885 pipe
java    13796 deyan   20r  0000                0,9        0      618 anon_inode

Step 2:
On deactivate and the same command:

java    13796 deyan    4r   REG                8,9   644783 47039005 
/home/deyan/install/apache mina/apache-mina-2.0.7/dist/mina-core-2.0.7.jar
java    13796 deyan    5r   REG                8,9    26176 47039015 
/home/deyan/install/apache mina/apache-mina-2.0.7/lib/slf4j-api-1.6.6.jar
java    13796 deyan    6r  FIFO                0,8      0t0   143881 pipe
java    13796 deyan    7r  FIFO                0,8      0t0   143881 pipe
java    13796 deyan    8u  0000                0,9        0      618 anon_inode
java    13796 deyan    9u  FIFO                0,8      0t0   143882 pipe
java    13796 deyan   10r  FIFO                0,8      0t0   143882 pipe
java    13796 deyan   11w  0000                0,9        0      618 anon_inode
java    13796 deyan   12u  FIFO                0,8      0t0   143883 pipe
java    13796 deyan   13u  FIFO                0,8      0t0   143883 pipe
java    13796 deyan   14r  0000                0,9        0      618 anon_inode
java    13796 deyan   15r  FIFO                0,8      0t0   143884 pipe
java    13796 deyan   16r  FIFO                0,8      0t0   143884 pipe
java    13796 deyan   17r  0000                0,9        0      618 anon_inode
java    13796 deyan   18r  FIFO                0,8      0t0   143885 pipe
java    13796 deyan   19r  FIFO                0,8      0t0   143885 pipe
java    13796 deyan   20r  0000                0,9        0      618 anon_inode

So there is no cleanup. If i don't use custom executor the server behaves 
properly.

Step 2:
If i activate again:

java    13796 deyan    4r   REG                8,9   644783 47039005 
/home/deyan/install/apache mina/apache-mina-2.0.7/dist/mina-core-2.0.7.jar
java    13796 deyan    5r   REG                8,9    26176 47039015 
/home/deyan/install/apache mina/apache-mina-2.0.7/lib/slf4j-api-1.6.6.jar
java    13796 deyan    6r  FIFO                0,8      0t0   143881 pipe
java    13796 deyan    7r  FIFO                0,8      0t0   143881 pipe
java    13796 deyan    8u  0000                0,9        0      618 anon_inode
java    13796 deyan    9u  FIFO                0,8      0t0   143882 pipe
java    13796 deyan   10r  FIFO                0,8      0t0   143882 pipe
java    13796 deyan   11w  0000                0,9        0      618 anon_inode
java    13796 deyan   12u  FIFO                0,8      0t0   143883 pipe
java    13796 deyan   13u  FIFO                0,8      0t0   143883 pipe
java    13796 deyan   14r  0000                0,9        0      618 anon_inode
java    13796 deyan   15r  FIFO                0,8      0t0   143884 pipe
java    13796 deyan   16r  FIFO                0,8      0t0   143884 pipe
java    13796 deyan   17r  0000                0,9        0      618 anon_inode
java    13796 deyan   18r  FIFO                0,8      0t0   143885 pipe
java    13796 deyan   19r  FIFO                0,8      0t0   143885 pipe
java    13796 deyan   20r  0000                0,9        0      618 anon_inode
java    13796 deyan   21r  FIFO                0,8      0t0   143996 pipe
java    13796 deyan   22r  FIFO                0,8      0t0   143996 pipe
java    13796 deyan   23r  0000                0,9        0      618 anon_inode
java    13796 deyan   24r  FIFO                0,8      0t0   143997 pipe
java    13796 deyan   25r  unix 0xffff88011e2fa700      0t0   143977 socket
java    13796 deyan   26r  sock                0,6      0t0   143890 can't 
identify protocol
java    13796 deyan   27r  FIFO                0,8      0t0   143997 pipe
java    13796 deyan   28u  0000                0,9        0      618 anon_inode
java    13796 deyan   29u  FIFO                0,8      0t0   143998 pipe
java    13796 deyan   30r  FIFO                0,8      0t0   143998 pipe
java    13796 deyan   31r  0000                0,9        0      618 anon_inode
java    13796 deyan   32r  FIFO                0,8      0t0   143999 pipe
java    13796 deyan   33r  FIFO                0,8      0t0   143999 pipe
java    13796 deyan   34r  0000                0,9        0      618 anon_inode
java    13796 deyan   35r  FIFO                0,8      0t0   144000 pipe
java    13796 deyan   36r  FIFO                0,8      0t0   144000 pipe
java    13796 deyan   37r  0000                0,9        0      618 anon_inode
java    13796 deyan   38r  FIFO                0,8      0t0   144001 pipe
java    13796 deyan   39r  FIFO                0,8      0t0   144001 pipe
java    13796 deyan   40r  0000                0,9        0      618 anon_inode

You can see that the anon_inode are doubled.

I want to ask what am I doing wrong and to point me out how to use custom 
executor because I want to integrate Mina in Application Server.

The test code: 
public class SimpleMinaServer {
    private NioSocketAcceptor acceptor;

    private final IoHandler ioHandler;
    private final InetSocketAddress inetSocketAddress;
    private final int threads;

    public SimpleMinaServer(IoHandler ioHandler, InetSocketAddress 
inetSocketAddress, int threads) {

        this.ioHandler = ioHandler;
        this.inetSocketAddress = inetSocketAddress;
        this.threads = threads;
    }

    public synchronized void activate() throws Exception {
        try {

            Executor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 
60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
            ((ThreadPoolExecutor) executor).setRejectedExecutionHandler(new 
ThreadPoolExecutor.CallerRunsPolicy());

            IoProcessor<NioSession> processor = new 
SimpleIoProcessorPool<NioSession>(NioProcessor.class, executor, threads);
            acceptor = new NioSocketAcceptor(processor);

            // If you comment the code above and uncomment the code below it
            // behaves properly
            // acceptor = new NioSocketAcceptor(this.threads);

            acceptor.setReuseAddress(true);
            acceptor.setCloseOnDeactivation(true);
            acceptor.getSessionConfig().setIdleTime(IdleStatus.READER_IDLE, 12);

            DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();

            LoggingFilter loggingFilter = new LoggingFilter();
            loggingFilter.setMessageReceivedLogLevel(LogLevel.NONE);
            loggingFilter.setMessageSentLogLevel(LogLevel.NONE);
            loggingFilter.setMessageSentLogLevel(LogLevel.NONE);
            loggingFilter.setSessionClosedLogLevel(LogLevel.NONE);
            loggingFilter.setSessionCreatedLogLevel(LogLevel.NONE);
            loggingFilter.setSessionIdleLogLevel(LogLevel.NONE);
            loggingFilter.setSessionOpenedLogLevel(LogLevel.NONE);
            loggingFilter.setExceptionCaughtLogLevel(LogLevel.DEBUG);

            filterChain.addLast("logging", loggingFilter);

            TextLineCodecFactory customTextLineCodecFactory = new 
TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.NUL,
                    LineDelimiter.NUL);
            customTextLineCodecFactory.setDecoderMaxLineLength(16000);
            customTextLineCodecFactory.setEncoderMaxLineLength(16000);

            ProtocolCodecFilter protocolCodecFilter = new 
ProtocolCodecFilter(customTextLineCodecFactory);
            filterChain.addLast("codec", protocolCodecFilter);

            acceptor.setHandler(ioHandler);
            acceptor.bind(inetSocketAddress);

            System.err.println("Apache Mina Server started on port " + 
inetSocketAddress.getPort());

        } catch (Exception e) {
            System.err.println("Exception while starting resource adapter");
            throw e;
        }
    }

    public synchronized void deactivate() {
        if (this.acceptor != null) {
            this.acceptor.unbind();
            this.acceptor.dispose();
            this.acceptor = null;
        }
    }

    public static void main(String[] args) throws Exception {
        final SimpleIoHandler ioHandler = new SimpleIoHandler();

        SimpleMinaServer s = new SimpleMinaServer(ioHandler, new 
InetSocketAddress(9090), 5);

        s.activate();
        final Scanner sc = new Scanner(System.in);

        while (true) {

            sc.nextLine();

            if (s.acceptor != null) {
                s.deactivate();
                System.out.println("Deactivating");
            } else {
                s.activate();
                System.out.println("Activating");
            }
        }

    }

}



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to