By default, MINA preserves the order of all events for a particular
IoSession.

When a client first sends msgA and then msgB, the corresponding
IoHandler.messageReceived events will be called in the same order on the
server.
And the second messageReceived will not be called before the first one
returned

Note that this is only true for one particular IoSession, messageReceived
can be called simultaneously for different IoSessions.

If you want more parallel processing, have a look at
http://issues.apache.org/jira/browse/DIRMINA-334

Maarten


On 10/22/07, mat <[EMAIL PROTECTED]> wrote:
>
> Try client sends more than 100. Make it 100000 and see.
>
> On 10/22/07, tiandike <[EMAIL PROTECTED]> wrote:
> >
> >
> > thougth my client  send some requests in one connector , the server
> handle
> > these request in mutithread.
> > if the client send request b after request a ,but the server handle b
> > faster than a  and in this condition can my client receive the response
> b
> > first?
> >
> >
> >
> > mat-29 wrote:
> > >
> > > I didn't see why NOT if in your client side only single thread sending
> > the
> > > message.
> > >
> > > On 10/22/07, tiandike <[EMAIL PROTECTED]> wrote:
> > >>
> > >>
> > >> I modified the example of echoserver
> > >>
> > >> in my code I disable the default ThreadModel setting and configure
> the
> > >> number of  I/O processor thread.
> > >>
> > >>
> > >> I don't understand why my client can receive the results in order?
> > >> Thanks!
> > >>
> > >> the code and the result is below:
> > >>
> > >> /////////////////////////////////
> > >> the main class is :
> > >> public class Main {
> > >>    /** Choose your favorite port number. */
> > >>    private static final int PORT = 8080;
> > >>
> > >>    public static void main(String[] args) throws Exception {
> > >>        int num = Runtime.getRuntime().availableProcessors() * 3;
> > >>        IoAcceptor acceptor = new SocketAcceptor(num,
> > >> Executors.newCachedThreadPool());
> > >>        IoAcceptorConfig config = new SocketAcceptorConfig();
> > >>        config.setThreadModel(ThreadModel.MANUAL);
> > >>        DefaultIoFilterChainBuilder chain = config.getFilterChain();
> > >>        chain.addLast("threadPool", new
> > >> ExecutorFilter(Executors.newCachedThreadPool()));
> > >>
> > >>        acceptor.bind(new InetSocketAddress(PORT), new
> > >> EchoProtocolHandler1(),
> > >>                config);
> > >>        System.out.println("Listening on port " + PORT);
> > >>    }
> > >>
> > >> }
> > >>
> > >>
> > >> /////////////////////////////////
> > >> EchoProtocolHandler1.java
> > >>
> > >> public class EchoProtocolHandler1 extends IoHandlerAdapter {
> > >>        private static Random r=new Random();
> > >>        private static final Logger log = LoggerFactory
> > >>                        .getLogger(EchoProtocolHandler.class);
> > >>
> > >>
> > >>
> > >>        public void exceptionCaught(IoSession session, Throwable
> cause)
> > {
> > >>                cause.printStackTrace();
> > >>                session.close();
> > >>        }
> > >>
> > >>        public void messageReceived(IoSession session, Object message)
> > >>                        throws Exception {
> > >>                if (!(message instanceof ByteBuffer)) {
> > >>                        return;
> > >>                }
> > >>                Thread.currentThread().sleep(r.nextInt(1000));
> > >>
> > >>                ByteBuffer rb = (ByteBuffer) message;
> > >>                // Write the received data back to remote peer
> > >>                ByteBuffer wb = ByteBuffer.allocate(rb.remaining());
> > >>                wb.put(rb);
> > >>                wb.flip();
> > >>
> > >>
> > >>                session.write(wb);
> > >>        }
> > >>
> > >> }
> > >>
> > >> ////////////////////////////////////////////
> > >> and my client handler:
> > >>
> > >> public class ClientHandler extends IoHandlerAdapter {
> > >>
> > >>        private int num=0;
> > >>
> > >>        public ClientHandler(int num){
> > >>                this.num=num;
> > >>        }
> > >>
> > >>
> > >>        @Override
> > >>        public void sessionOpened(IoSession session) throws Exception
> {
> > >>
> > >>                for (int i = 0; i < num; i++) {
> > >>                        session.write(String.valueOf(i));
> > >>
> > >>                }
> > >>        }
> > >>        @Override
> > >>        public void messageReceived(IoSession session, Object message)
> > >>                        throws Exception {
> > >>
> > >>                System.out.println("messageReceived:"+message);
> > >>        }
> > >>
> > >>
> > >> }
> > >>
> > >>
> > >> //////////////////////////////////////////////
> > >> and ClientMain :
> > >>
> > >> public class ClientMain {
> > >>
> > >>        private static final String HOSTNAME = "localhost";
> > >>        private static final int PORT = 8080;
> > >>
> > >>        /**
> > >>         * @param args
> > >>         */
> > >>        public static void main(String[] args) {
> > >>                InetSocketAddress socketAddress = new
> > >> InetSocketAddress(HOSTNAME, PORT);
> > >>                IoServiceConfig config = new SocketConnectorConfig();
> > >>                config.setThreadModel(ThreadModel.MANUAL);
> > >>                DefaultIoFilterChainBuilder chain =
> > config.getFilterChain
> > >> ();
> > >>
> > >>        chain.addLast("threadPool", new
> > >> ExecutorFilter(Executors.newCachedThreadPool()));
> > >>
> > >>        int num=100;
> > >>
> > >>        SocketConnector connector=new SocketConnector();
> > >>
> > >>        ConnectFuture future = connector.connect(new
> InetSocketAddress(
> > >>                HOSTNAME, PORT), new ClientHandler(num), config);
> > >>
> > >>        future.join();
> > >>
> > >>
> > >>        }
> > >>
> > >> }
> > >> ///////////////////////////////////////////////////////////////
> > >> in eclipse console:
> > >>
> > >> messageReceived:0
> > >> messageReceived:1
> > >> messageReceived:2
> > >> messageReceived:3
> > >> messageReceived:4
> > >> messageReceived:5
> > >> messageReceived:6
> > >> messageReceived:7
> > >> messageReceived:8
> > >> messageReceived:9
> > >> messageReceived:10
> > >> messageReceived:11
> > >> messageReceived:12
> > >> messageReceived:13
> > >> messageReceived:14
> > >> messageReceived:15
> > >> messageReceived:16
> > >> messageReceived:17
> > >> messageReceived:18
> > >> messageReceived:19
> > >> messageReceived:20
> > >> messageReceived:21
> > >> messageReceived:22
> > >> messageReceived:23
> > >> messageReceived:24
> > >> ........
> > >> messageReceived:99
> > >>
> > >> --
> > >> View this message in context:
> > >>
> >
> http://www.nabble.com/why-client-received-message-in-order--tf4668688s16868.html#a13336726
> > >> Sent from the Apache MINA Support Forum mailing list archive at
> > >> Nabble.com
> > >> .
> > >>
> > >>
> > >
> > >
> >
> > --
> > View this message in context:
> >
> http://www.nabble.com/why-client-received-message-in-order--tf4668688s16868.html#a13338571
> > Sent from the Apache MINA Support Forum mailing list archive at
> Nabble.com
> > .
> >
> >
>

Reply via email to