Permalink
Browse files

fixed retry reconnect. added logging messages

  • Loading branch information...
1 parent 514f8b7 commit 81a3112c9ea5d84c08db0ba486f464a454873aa5 @odbol committed Sep 12, 2011
@@ -35,6 +35,7 @@
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
+import org.apache.mina.core.write.WriteToClosedSessionException;
import org.apache.mina.transport.socket.nio.NioDatagramConnector;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.slf4j.Logger;
@@ -68,7 +69,7 @@
final Logger logger = LoggerFactory.getLogger(OscClient.class);
private IoConnector connector;
- private IoSession session;
+ private volatile IoSession session;
private List<OscPacket> packetQueue;
private OscDataEncoder encoder;
@@ -123,7 +124,7 @@ public void operationComplete(IoFuture future) {
}
}
} else {
- System.out.println("Not connected...exiting");
+ logger.debug("Not connected...exiting");
}
}
@@ -169,13 +170,24 @@ public void exceptionCaught(IoSession arg0, Throwable arg1)
+ " : " + address.getPort());
attemptReconnect();
- } else {
+ }
+ else if (arg1 instanceof WriteToClosedSessionException) {
+ logger.warn("Tried to write to closed sessson " + arg1.toString());
+
+ //don't reconnect if the session has ended after being started correctly!
+ //attemptReconnect();
+ }
+ else {
arg1.printStackTrace();
}
}
private void attemptReconnect() {
- if (++curConnectionAttempt < CONNECTION_ATTEMPTS) {
+ //TODO: disable session until we get a new one
+ //does this need to be synchronized????
+ //session = null;
+
+ if (++curConnectionAttempt < CONNECTION_ATTEMPTS) {
logger.warn("Attempting to reconnect in " + (CONNECTION_RETRY_DELAY / 1000) + " seconds.");
//TODO: unregister future listener!
@@ -26,12 +26,18 @@
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.relivethefuture.osc.data.OscBundle;
import com.relivethefuture.osc.data.OscListener;
import com.relivethefuture.osc.data.OscMessage;
+
public class OscServerIoHandler extends IoHandlerAdapter {
+
+ final Logger logger = LoggerFactory.getLogger(OscServerIoHandler.class);
+
public static final String INDEX_KEY = OscServerIoHandler.class.getName()
+ ".INDEX";
private ArrayList<OscListener> listeners;
@@ -57,6 +63,9 @@ public void sessionOpened(IoSession session) throws Exception {
public void exceptionCaught(IoSession session, Throwable cause)
throws Exception {
// SessionLog.warn(session, cause.getMessage(), cause);
+ //Log.e(TAG, "Error handling OSC server IO.", cause);
+
+ logger.error("Error handling OSC server IO.", cause);
}
public void messageReceived(IoSession session, Object message)

0 comments on commit 81a3112

Please sign in to comment.