You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Eric LeVin <ej...@hotmail.com> on 2008/06/06 08:10:19 UTC

Issues with client reconnection

Thanks in advance to anyone that has any input on this.  I might be doing something very simple wrong as I am a NOOB to Mina.  I am using the following mina version:


    	org.apache.mina
    	mina-core
    	2.0.0-M1
	

I have been testing things with getting filters setup appropriately, and really like the way Mina is setup.  The problem I have discovered in my configuration is when I pull the network out from under my client connection (i.e. un-plug my network connection) I don't get any disconnection exceptions in the HandlerAdapter or a SessionClosed event (or anything for that matter).  Here are my major adapter methods-as you will see I implement the reconnection logic as stated in the FAQ; however, I am still seeing the issue.

@Override
    public void exceptionCaught(IoSession session, Throwable t) throws Exception
    {
	log.error("Session:" + session + " :: Exception:" + t);
    }

...
    @Override
    public void sessionClosed(IoSession session) throws Exception
    {
	// Wait for five seconds before reconnecting.
	Thread.sleep( 5000 );

	if(session.getService() instanceof IoConnector)
	{
	    ((IoConnector)session.getService()).connect( session.getRemoteAddress() );
	}
    }

Here is my client connection code:

SocketAddress address = new InetSocketAddress("X.X.X.X",2000);
	
	NioSocketConnector ioConnector = new NioSocketConnector();

	//Add the price stream filter that will separate out the messages...
	
	ioConnector.getFilterChain().addLast( "binary-logger", new LoggingFilter() );
	ioConnector.getFilterChain().addLast( "protocolCodecFilter", (IoFilter)getBean("protocolCodecFilter") );
	ioConnector.getFilterChain().addLast( "authenticationFilter", (IoFilter)getBean("authenticationFilter") );

	ioConnector.setHandler( (IoHandler)getBean("ioHandler") );
        
	ConnectFuture cf = ioConnector.connect(address);
	cf.join();

ioHandler, the codec filter, and the authentication are all filters defined in my spring context.  The protocol filter is a custom implementation based off of the filters in source.  I am hoping this is a simple configuration thing I am going wrong, if not I will try to make a full example and replicate it.  Thanks so much for any help you may have!

-Eric

Re: Issues with client reconnection

Posted by Maarten Bosteels <mb...@gmail.com>.
As long as your not using the connection, TCP will not notify about an
unplugged network cable (this seems strange to most people at first
but it can have advantages too).
If you want early detection of a broken link, you should use some kind
of heartbeat.

I think there is a HeartbeatFilter somewhere.
Search the mailing list archive or JIRA for this.

Hope that helps,
Maarten


On Fri, Jun 6, 2008 at 8:10 AM, Eric LeVin <ej...@hotmail.com> wrote:
>
> Thanks in advance to anyone that has any input on this.  I might be doing something very simple wrong as I am a NOOB to Mina.  I am using the following mina version:
>
>
>        org.apache.mina
>        mina-core
>        2.0.0-M1
>
>
> I have been testing things with getting filters setup appropriately, and really like the way Mina is setup.  The problem I have discovered in my configuration is when I pull the network out from under my client connection (i.e. un-plug my network connection) I don't get any disconnection exceptions in the HandlerAdapter or a SessionClosed event (or anything for that matter).  Here are my major adapter methods-as you will see I implement the reconnection logic as stated in the FAQ; however, I am still seeing the issue.
>
> @Override
>    public void exceptionCaught(IoSession session, Throwable t) throws Exception
>    {
>        log.error("Session:" + session + " :: Exception:" + t);
>    }
>
> ...
>    @Override
>    public void sessionClosed(IoSession session) throws Exception
>    {
>        // Wait for five seconds before reconnecting.
>        Thread.sleep( 5000 );
>
>        if(session.getService() instanceof IoConnector)
>        {
>            ((IoConnector)session.getService()).connect( session.getRemoteAddress() );
>        }
>    }
>
> Here is my client connection code:
>
> SocketAddress address = new InetSocketAddress("X.X.X.X",2000);
>
>        NioSocketConnector ioConnector = new NioSocketConnector();
>
>        //Add the price stream filter that will separate out the messages...
>
>        ioConnector.getFilterChain().addLast( "binary-logger", new LoggingFilter() );
>        ioConnector.getFilterChain().addLast( "protocolCodecFilter", (IoFilter)getBean("protocolCodecFilter") );
>        ioConnector.getFilterChain().addLast( "authenticationFilter", (IoFilter)getBean("authenticationFilter") );
>
>        ioConnector.setHandler( (IoHandler)getBean("ioHandler") );
>
>        ConnectFuture cf = ioConnector.connect(address);
>        cf.join();
>
> ioHandler, the codec filter, and the authentication are all filters defined in my spring context.  The protocol filter is a custom implementation based off of the filters in source.  I am hoping this is a simple configuration thing I am going wrong, if not I will try to make a full example and replicate it.  Thanks so much for any help you may have!
>
> -Eric