Hi, Li

You write a wrong connection recovery handling block. Refer the following code 
snippet if you want to make the application can work well in all cases:

        /**
         * connect to specified MC identified by incoming internet address
         * 
         * @param addr
         *            IP address for MC
         */
        public void connectToMC(final InetSocketAddress addr) {
                final ExecutorService executor = 
Executors.newFixedThreadPool(1);
                executor.execute(new Runnable() {
                        public void run() {
                                ConnectFuture connectFuture;
                                try {
                                        for (;;) {
                                                connectFuture = 
connector.connect(addr);
                                                System.out.println("tring to 
connect to MC: " + addr);
                                                
connectFuture.await(connectTimeout, TimeUnit.SECONDS);
                                                if 
(connectFuture.isConnected()) {
                                                        
System.out.println("successfully connected to MC: "
                                                                        + addr);
                                                        // ...
                                                        executor.shutdown();
                                                        return;
                                                }

                                                // sleep for 5 seconds and retry
                                                Thread.sleep(5000);
                                        }
                                } catch (InterruptedException e) {
                                        e.printStackTrace();
                                }
                        }
                });
        } 

Here, because my app works for multiple server cluster, please throw away the 
ExecutorService, just extract source code lines inside run() methods.

BR
anderson
-----Original Message-----
From: li [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 11, 2008 4:31 PM
To: [email protected]
Subject: RE: About the time limit of connection keeps valid from standby mode


Hi,

Now my program logic likes this:
1)the client creates a connection to a server and exchanges data with server 
continuously.
2)the computer enters standby mode.
3)bring the computer out of standby mode in about 30 minutes.
4)the client send data to server as soon as wake up.
5)the client receive IOException from IoHandler.exceptionCaught method.
6)the client reconnect to server this way:
connector = new SocketConnector();
connector.getFilterChain().addLast(.....
future = connector.connect(add,handler); 

In most cases, step 6 can recover the connection, but occasionally get the 
following exception when trying to execute future.getSession().
org.apache.mina.common.RuntimeIoException: Failed to get the session.
at 
org.apache.mina.common.DefaultConnectFuture.getSession(DefaultConnectFuture.java:58)

This problem is difficult to reproduce.
If anyone has any advice, please tell me.
Li

_________________________________________________________________
秋本番!�B休たくさんのこの秋、みんなのオススメ�L末旅行をチェックしよう
http://clk.atdmt.com/GBL/go/112813570/direct/01/

Reply via email to