You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by jv...@apache.org on 2012/11/15 21:25:04 UTC
svn commit: r1409983 - in /mina/mina/trunk/core/src:
main/java/org/apache/mina/api/AbstractIoHandler.java
main/java/org/apache/mina/api/IoHandler.java
main/java/org/apache/mina/session/AbstractIoSession.java
test/resources/log4j2-test.xml
Author: jvermillard
Date: Thu Nov 15 20:25:02 2012
New Revision: 1409983
URL: http://svn.apache.org/viewvc?rev=1409983&view=rev
Log:
send caught exception to the IoHandler (if any)
Added:
mina/mina/trunk/core/src/test/resources/log4j2-test.xml
Modified:
mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoHandler.java
mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoHandler.java
mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoHandler.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoHandler.java?rev=1409983&r1=1409982&r2=1409983&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoHandler.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/api/AbstractIoHandler.java Thu Nov 15 20:25:02 2012
@@ -73,4 +73,11 @@ public abstract class AbstractIoHandler
@Override
public void serviceInactivated(final IoService service) {
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void exceptionCaught(final IoSession session, final Throwable cause) {
+ }
}
Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoHandler.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoHandler.java?rev=1409983&r1=1409982&r2=1409983&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoHandler.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/api/IoHandler.java Thu Nov 15 20:25:02 2012
@@ -72,4 +72,11 @@ public interface IoHandler {
*/
void serviceInactivated(IoService service);
+ /**
+ * Invoked when any runtime exception is thrown during session processing (filters, unexpected error, etc..).
+ *
+ * @param session the session related to the exception
+ * @param cause the caught exception
+ */
+ void exceptionCaught(IoSession session, Throwable cause);
}
Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java?rev=1409983&r1=1409982&r2=1409983&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/session/AbstractIoSession.java Thu Nov 15 20:25:02 2012
@@ -623,18 +623,33 @@ public abstract class AbstractIoSession
// Event processing using the filter chain
// ------------------------------------------------------------------------
+ /** send a caught exception to the {@link IoHandler} (if any) */
+ private void processException(final Throwable t) {
+ LOG.debug("caught session exception ", t);
+ final IoHandler handler = getService().getIoHandler();
+ if (handler != null) {
+ handler.exceptionCaught(this, t);
+ }
+ }
+
/**
* process session opened event using the filter chain. To be called by the session {@link SelectorProcessor} .
*/
public void processSessionOpened() {
LOG.debug("processing session open event");
- for (final IoFilter filter : chain) {
- filter.sessionOpened(this);
- }
- final IoHandler handler = getService().getIoHandler();
- if (handler != null) {
- handler.sessionOpened(this);
+ try {
+
+ for (final IoFilter filter : chain) {
+ filter.sessionOpened(this);
+ }
+ final IoHandler handler = getService().getIoHandler();
+
+ if (handler != null) {
+ handler.sessionOpened(this);
+ }
+ } catch (final RuntimeException e) {
+ processException(e);
}
}
@@ -643,14 +658,17 @@ public abstract class AbstractIoSession
*/
public void processSessionClosed() {
LOG.debug("processing session closed event");
+ try {
+ for (final IoFilter filter : chain) {
+ filter.sessionClosed(this);
+ }
- for (final IoFilter filter : chain) {
- filter.sessionClosed(this);
- }
-
- final IoHandler handler = getService().getIoHandler();
- if (handler != null) {
- handler.sessionClosed(this);
+ final IoHandler handler = getService().getIoHandler();
+ if (handler != null) {
+ handler.sessionClosed(this);
+ }
+ } catch (final RuntimeException e) {
+ processException(e);
}
}
@@ -660,13 +678,18 @@ public abstract class AbstractIoSession
public void processSessionIdle(final IdleStatus status) {
LOG.debug("processing session idle {} event for session {}", status, this);
- for (final IoFilter filter : chain) {
- filter.sessionIdle(this, status);
- }
- final IoHandler handler = getService().getIoHandler();
- if (handler != null) {
- handler.sessionIdle(this, status);
+ try {
+ for (final IoFilter filter : chain) {
+ filter.sessionIdle(this, status);
+ }
+ final IoHandler handler = getService().getIoHandler();
+ if (handler != null) {
+ handler.sessionIdle(this, status);
+ }
+ } catch (final RuntimeException e) {
+ processException(e);
}
+
}
/**
@@ -678,21 +701,26 @@ public abstract class AbstractIoSession
public void processMessageReceived(final ByteBuffer message) {
LOG.debug("processing message '{}' received event for session {}", message, this);
- // save basic statistics
- readBytes += message.remaining();
- lastReadTime = System.currentTimeMillis();
-
- if (chain.length < 1) {
- LOG.debug("Nothing to do, the chain is empty");
- } else {
- readChainPosition = 0;
- // we call the first filter, it's supposed to call the next ones using the filter chain controller
- chain[readChainPosition].messageReceived(this, message, this);
- }
- final IoHandler handler = getService().getIoHandler();
- if (handler != null) {
- handler.messageReceived(this, message);
+ try {
+ // save basic statistics
+ readBytes += message.remaining();
+ lastReadTime = System.currentTimeMillis();
+
+ if (chain.length < 1) {
+ LOG.debug("Nothing to do, the chain is empty");
+ } else {
+ readChainPosition = 0;
+ // we call the first filter, it's supposed to call the next ones using the filter chain controller
+ chain[readChainPosition].messageReceived(this, message, this);
+ }
+ final IoHandler handler = getService().getIoHandler();
+ if (handler != null) {
+ handler.messageReceived(this, message);
+ }
+ } catch (final RuntimeException e) {
+ processException(e);
}
+
}
/**
@@ -704,39 +732,50 @@ public abstract class AbstractIoSession
public void processMessageWriting(final Object message, final IoFuture<Void> future) {
LOG.debug("processing message '{}' writing event for session {}", message, this);
- lastWriteRequest = null;
+ try {
+ lastWriteRequest = null;
- if (chain.length < 1) {
- enqueueFinalWriteMessage(message);
- } else {
- writeChainPosition = chain.length - 1;
- // we call the first filter, it's supposed to call the next ones using the filter chain controller
- final int position = writeChainPosition;
- final IoFilter nextFilter = chain[position];
- nextFilter.messageWriting(this, message, this);
- }
+ if (chain.length < 1) {
+ enqueueFinalWriteMessage(message);
+ } else {
+ writeChainPosition = chain.length - 1;
+ // we call the first filter, it's supposed to call the next ones using the filter chain controller
+ final int position = writeChainPosition;
+ final IoFilter nextFilter = chain[position];
+ nextFilter.messageWriting(this, message, this);
+ }
- // put the future in the last write request
+ // put the future in the last write request
- final WriteRequest request = lastWriteRequest;
- if (request != null) {
- if (future != null) {
- ((DefaultWriteRequest) request).setFuture(future);
+ final WriteRequest request = lastWriteRequest;
+ if (request != null) {
+ if (future != null) {
+ ((DefaultWriteRequest) request).setFuture(future);
+ }
+ ((DefaultWriteRequest) request).setHighLevelMessage(message);
}
- ((DefaultWriteRequest) request).setHighLevelMessage(message);
+ } catch (final RuntimeException e) {
+ processException(e);
}
+
}
public void processMessageSent(final Object highLevelMessage) {
LOG.debug("processing message '{}' sent event for session {}", highLevelMessage, this);
- final int size = chain.length;
- for (int i = size - 1; i >= 0; i--) {
- chain[i].messageSent(this, highLevelMessage);
- }
- final IoHandler handler = getService().getIoHandler();
- if (handler != null) {
- handler.messageSent(this, highLevelMessage);
+
+ try {
+ final int size = chain.length;
+ for (int i = size - 1; i >= 0; i--) {
+ chain[i].messageSent(this, highLevelMessage);
+ }
+ final IoHandler handler = getService().getIoHandler();
+ if (handler != null) {
+ handler.messageSent(this, highLevelMessage);
+ }
+ } catch (final RuntimeException e) {
+ processException(e);
}
+
}
/**
@@ -784,5 +823,4 @@ public abstract class AbstractIoSession
readChainPosition--;
}
-
}
\ No newline at end of file
Added: mina/mina/trunk/core/src/test/resources/log4j2-test.xml
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/test/resources/log4j2-test.xml?rev=1409983&view=auto
==============================================================================
--- mina/mina/trunk/core/src/test/resources/log4j2-test.xml (added)
+++ mina/mina/trunk/core/src/test/resources/log4j2-test.xml Thu Nov 15 20:25:02 2012
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
+ </Console>
+ </appenders>
+ <loggers>
+ <logger name="org.apache.log4j.xml" level="info"/>
+ <root level="debug">
+ <appender-ref ref="STDOUT"/>
+ </root>
+ </loggers>
+</configuration>
\ No newline at end of file