Le 1/16/13 8:28 PM, Hugo Pereira a écrit : > Greetings, Hi, > > ** > > ** ** > > I am prototyping a custom framework using MINA. **** > > I am trying to have a multithreaded and independent modules. This means > that I have several clients connecting to my server that must do as follows: > **** > > **· **Limit the number of accepted connections**** > > **· **One thread pool in charge of the decoding**** > > **· **Other thread pool in charge handling business**** > > **· **Other thread pool in charge of the encoding****
First, I'd like to know if you have any reason to have the encoding and decoding running in separate threads ? Are they costly operations ? Also, why do you want to limit the number of accepted connections ? If you have a limited number of connected users, why do you want to process everything in separate threads ? > > ** ** > > To do so in my server I am doing:**** > > NioSocketAcceptor acceptor = *new* NioSocketAcceptor();**** > > **** > > // ///////////////////////**** > > *int* corePoolSize = 1;**** > > *int* maxPoolSize = 1;**** > > *int* *numSessions* = 2;// TO validate**** > > // ///////////////////////**** > > // acceptor.getSessionConfig().setMaxReadBufferSize(1024);**** > > ** ** > > acceptor.getFilterChain().addLast("executor1", > *new*ExecutorFilter(corePoolSize, maxPoolSize)); > **** > > acceptor.getFilterChain().addLast("payloadFilter", > *new*ProtocolCodecFilter( > *new* PayloadCodecFactory()));**** > > acceptor.getFilterChain().addLast("executor2", > *new*ExecutorFilter(Executors. > *newFixedThreadPool*(maxPoolSize)));**** > > // acceptor.getFilterChain().addLast("logger", new > LoggingFilter());**** > > ** ** > > acceptor.setHandler(*new* ServerSessionHandler());**** > > acceptor.bind(*new* InetSocketAddress("8181"));**** > > System.*out*.println("Listening on port " + ports);**** > > ** ** > > ** ** > > My debug output is as follows:**** > > Session 2 opened**** > > Session 3 opened**** > > Session 4 opened**** > > Session 5 opened**** > > Thread 13 DECODER session 2 sleep 10s**** > > Thread 13 DECODER session 3 sleep 10s**** > > Thread 14 session 2 with message qw sleep 5s**** > > Thread 14 ENCODER session 2 sleep 10s**** > > Thread 13 DECODER session 4 sleep 10s**** > > Thread 14 session 3 with message we sleep 5s**** > > Thread 13 DECODER session 5 sleep 10s**** > > Thread 14 ENCODER session 3 sleep 10s**** > > Thread 14 session 4 with message we sleep 5s**** > > Thread 14 ENCODER session 4 sleep 10s**** > > Thread 14 session 5 with message rt sleep 5s**** > > Thread 14 ENCODER session 5 sleep 10s**** > > ** ** > > ** ** > > What is happening is that the first thread pool is doing the decoding work > and the second pool is doing the handling business and the encoding. How > can I put the encoding in a separate thread pool?**** You should tell the executor which event it will process, like : | chain.addLast("executor2", new ExecutorFilter(IoEventType.WRITE)); This will be executed only for write messages, hence by the encoder. | > > ** ** > > ** ** > > And how can I limit the max number of active connections that can be > accepted by the server ?**** You can't really do that without managing the sessionConnected event and counting the number of sessions. -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com