You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by peter ellis <pe...@googlemail.com> on 2007/01/24 15:25:53 UTC

RuntimeIOException

Hi Guys I get the following message

Exception in thread "Heartbeat"
org.apache.mina.common.RuntimeIOException: Failed to get the session.
        at org.apache.mina.common.support.DefaultConnectFuture.getSession(DefaultConnectFuture.java:69)

The application we have developed connects to our xml server which is
built on top of mina... when a disconnect occurs... i.e. the xml
server (mina) fails or shutdown for whatever reason then out
application needs to handle this gracefully i.e. "attempting to
reconnect...". How should/can i correctly manage this?

is there a way for me to ping the mina framework to see if its still
there!? or do i need to implement something myself???

thanks guys!


-- 
Peter Ellis
Java Developer

Re: RuntimeIOException

Posted by Niklas Therning <ni...@trillian.se>.
peter ellis wrote:
> Hi Guys I get the following message
>
> Exception in thread "Heartbeat"
> org.apache.mina.common.RuntimeIOException: Failed to get the session.
>        at
> org.apache.mina.common.support.DefaultConnectFuture.getSession(DefaultConnectFuture.java:69)
>
>
> The application we have developed connects to our xml server which is
> built on top of mina... when a disconnect occurs... i.e. the xml
> server (mina) fails or shutdown for whatever reason then out
> application needs to handle this gracefully i.e. "attempting to
> reconnect...". How should/can i correctly manage this?
>
> is there a way for me to ping the mina framework to see if its still
> there!? or do i need to implement something myself???
>

If you want to try to connect several times you could try something like:

Session session = null;
for (int i = 0; i < 5; i++) {
  try {
    ConnectFuture future = connector.connect(...);
    future.join();
    session = future.getSession();
    if (session != null) {
      break;
    }
  } catch (Exception e) {
  }
}

if (session == null) {
  // All connect attempts failed
  throw new SomeException();
}

// If your code gets to this point you have connected successfully
...

Please note that the above is synchronous which means that it will block
the thread. You can do the above asynchronously as well using
future.addIoFutureListener(...) but that's a bit more complicated.

The above only solves the issue of trying to establish a connection. If
you want to automatically reestablish a connection if it dies in the
middle of a transmission of data you could have a look at
http://issues.apache.org/jira/browse/DIRMINA-68 which tries to solve
this problem using a filter. I have no idea of the status of that code
though.

HTH

-- 
Niklas Therning
www.spamdrain.net