diff options
author | Simone Bordet | 2015-02-13 12:13:54 +0000 |
---|---|---|
committer | Simone Bordet | 2015-02-13 13:18:08 +0000 |
commit | ff7e0e626ac5c9bfc85cd3ff12404f513a543866 (patch) | |
tree | 83f1d73dbcc07a59dcca7a4e3c0d3f1aca947170 /jetty-http2/http2-common | |
parent | 9677988960c5b897a02c02190273ff8e6d0706c2 (diff) | |
download | org.eclipse.jetty.project-ff7e0e626ac5c9bfc85cd3ff12404f513a543866.tar.gz org.eclipse.jetty.project-ff7e0e626ac5c9bfc85cd3ff12404f513a543866.tar.xz org.eclipse.jetty.project-ff7e0e626ac5c9bfc85cd3ff12404f513a543866.zip |
Implemented notification of session failure events.
Diffstat (limited to 'jetty-http2/http2-common')
3 files changed, 37 insertions, 8 deletions
diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Flusher.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Flusher.java index c9aa988f74..44031c20e8 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Flusher.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Flusher.java @@ -231,7 +231,7 @@ public class HTTP2Flusher extends IteratingCallback if (actives.isEmpty()) { if (isClosed()) - terminate(new ClosedChannelException()); + abort(new ClosedChannelException()); if (LOG.isDebugEnabled()) LOG.debug("Flushed {}", session); @@ -291,7 +291,7 @@ public class HTTP2Flusher extends IteratingCallback protected void onCompleteFailure(Throwable x) { if (LOG.isDebugEnabled()) - LOG.debug(x); + LOG.debug("Failed", x); lease.recycle(); @@ -307,10 +307,10 @@ public class HTTP2Flusher extends IteratingCallback entry.failed(x); } - terminate(x); + abort(x); } - private void terminate(Throwable x) + private void abort(Throwable x) { Queue<Entry> queued; synchronized (this) @@ -320,10 +320,12 @@ public class HTTP2Flusher extends IteratingCallback } if (LOG.isDebugEnabled()) - LOG.debug("Terminating, queued={}", queued.size()); + LOG.debug("Aborting, queued={}", queued.size()); for (Entry entry : queued) closed(entry, x); + + session.abort(x); } private void closed(Entry entry, Throwable failure) diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java index 07bd2afd08..2e210105c2 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.http2; +import java.io.IOException; +import java.nio.channels.ClosedChannelException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; @@ -26,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -394,6 +397,7 @@ public abstract class HTTP2Session implements ISession, Parser.Listener public void onConnectionFailure(int error, String reason) { close(error, reason, Callback.Adapter.INSTANCE); + notifyFailure(this, new IOException(String.format("%d/%s", error, reason))); } @Override @@ -754,7 +758,7 @@ public abstract class HTTP2Session implements ISession, Parser.Listener // The other peer did not send a GO_AWAY, no need to be gentle. if (LOG.isDebugEnabled()) LOG.debug("Abrupt close for {}", this); - terminate(); + abort(new ClosedChannelException()); break; } case LOCALLY_CLOSED: @@ -811,7 +815,7 @@ public abstract class HTTP2Session implements ISession, Parser.Listener case LOCALLY_CLOSED: case REMOTELY_CLOSED: { - terminate(); + abort(new TimeoutException()); break; } default: @@ -856,6 +860,12 @@ public abstract class HTTP2Session implements ISession, Parser.Listener } } + protected void abort(Throwable failure) + { + terminate(); + notifyFailure(this, failure); + } + public boolean isDisconnected() { return !endPoint.isOpen(); @@ -927,6 +937,18 @@ public abstract class HTTP2Session implements ISession, Parser.Listener } } + protected void notifyFailure(Session session, Throwable failure) + { + try + { + listener.onFailure(session, failure); + } + catch (Throwable x) + { + LOG.info("Failure while notifying listener " + listener, x); + } + } + @Override public String toString() { diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/api/Session.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/api/Session.java index 056cc128c5..ce2ee9ef10 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/api/Session.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/api/Session.java @@ -179,7 +179,12 @@ public interface Session */ public void onClose(Session session, GoAwayFrame frame); - // TODO: how come this is not called ??? + /** + * <p>Callback method invoked when a failure has been detected for this session.</p> + * + * @param session the session + * @param failure the failure + */ public void onFailure(Session session, Throwable failure); /** |