Changes from review

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2022-06-08 10:44:17 +10:00
parent 5a24f90064
commit e578791518
5 changed files with 30 additions and 5 deletions

View File

@ -13,12 +13,15 @@
package org.eclipse.jetty.websocket.core; package org.eclipse.jetty.websocket.core;
import java.io.Closeable;
import java.io.IOException;
/** /**
* Interface for WebSocket Extensions. * Interface for WebSocket Extensions.
* <p> * <p>
* That {@link Frame}s are passed through the Extension via the {@link IncomingFrames} and {@link OutgoingFrames} interfaces * That {@link Frame}s are passed through the Extension via the {@link IncomingFrames} and {@link OutgoingFrames} interfaces
*/ */
public interface Extension extends IncomingFrames, OutgoingFrames public interface Extension extends IncomingFrames, OutgoingFrames, Closeable
{ {
void init(ExtensionConfig config, WebSocketComponents components); void init(ExtensionConfig config, WebSocketComponents components);
@ -26,7 +29,7 @@ public interface Extension extends IncomingFrames, OutgoingFrames
/** /**
* Used to clean up any resources after connection close. * Used to clean up any resources after connection close.
*/ */
default void close() default void close() throws IOException
{ {
} }

View File

@ -62,9 +62,17 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable
public void close() public void close()
{ {
for (Extension e : extensions) for (Extension ext : extensions)
{ {
e.close(); try
{
ext.close();
}
catch (Throwable t)
{
if (LOG.isDebugEnabled())
LOG.debug("Extension Error During Close", t);
}
} }
} }

View File

@ -184,6 +184,7 @@ public class FrameFlusher extends IteratingCallback
{ {
try (AutoLock l = lock.lock()) try (AutoLock l = lock.lock())
{ {
// TODO: find a way to not create exception if cause is null.
closedCause = cause == null ? new ClosedChannelException() closedCause = cause == null ? new ClosedChannelException()
{ {
@Override @Override

View File

@ -151,7 +151,15 @@ public class PerMessageDeflateExtension extends AbstractExtension implements Dem
public void close() public void close()
{ {
// TODO: use IteratingCallback.close() instead of creating exception with failFlusher methods. // TODO: use IteratingCallback.close() instead of creating exception with failFlusher methods.
ClosedChannelException exception = new ClosedChannelException(); ClosedChannelException exception = new ClosedChannelException()
{
@Override
public Throwable fillInStackTrace()
{
return this;
}
};
incomingFlusher.close();
incomingFlusher.failFlusher(exception); incomingFlusher.failFlusher(exception);
outgoingFlusher.failFlusher(exception); outgoingFlusher.failFlusher(exception);
releaseInflater(); releaseInflater();

View File

@ -83,6 +83,7 @@ public abstract class TransformingFlusher
*/ */
public void failFlusher(Throwable t) public void failFlusher(Throwable t)
{ {
// TODO: find a way to close the flusher in non error case without exception.
boolean failed = false; boolean failed = false;
try (AutoLock l = lock.lock()) try (AutoLock l = lock.lock())
{ {
@ -91,6 +92,10 @@ public abstract class TransformingFlusher
failure = t; failure = t;
failed = true; failed = true;
} }
else
{
failure.addSuppressed(t);
}
} }
if (failed) if (failed)