Skip to content

Commit

Permalink
Use StaticException class in jetty-util for websocket flushers.
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Jun 10, 2022
1 parent 657222f commit 805c8ee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Expand Up @@ -11,22 +11,24 @@
// ========================================================================
//

package org.eclipse.jetty.websocket.core.exception;
package org.eclipse.jetty.util;

/**
* Suppressed exceptions are disabled for this implementation,
* This exception can safely be stored in a static variable as suppressed exceptions are disabled,
* meaning calling {@link #addSuppressed(Throwable)} has no effect.
* This means instances of {@link SentinelWebSocketCloseException} are suitable to be kept as static fields.
* This prevents potential memory leaks where a statically-stored exception would accumulate
* suppressed exceptions added to them.
*/
public class SentinelWebSocketCloseException extends Exception
public class StaticException extends Exception
{
public SentinelWebSocketCloseException()
public StaticException()
{
this(null);
}

public SentinelWebSocketCloseException(String message)
public StaticException(String message)
{
// Make sure to call the super constructor that disables suppressed exception.
super(message, null, false, true);
}
}
}
Expand Up @@ -20,10 +20,10 @@
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.CountingCallback;
import org.eclipse.jetty.util.IteratingCallback;
import org.eclipse.jetty.util.StaticException;
import org.eclipse.jetty.websocket.core.Extension;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.IncomingFrames;
import org.eclipse.jetty.websocket.core.exception.SentinelWebSocketCloseException;

/**
* <p>This flusher can be used to mutated and fragment {@link Frame}s and forwarded them on towards the application using the
Expand All @@ -39,7 +39,7 @@
*/
public abstract class DemandingFlusher extends IteratingCallback implements DemandChain
{
private static final Throwable SENTINEL_CLOSE_EXCEPTION = new SentinelWebSocketCloseException();
private static final Throwable SENTINEL_CLOSE_EXCEPTION = new StaticException("Closed");

private final IncomingFrames _emitFrame;
private final AtomicLong _demand = new AtomicLong();
Expand Down
Expand Up @@ -29,13 +29,13 @@
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IteratingCallback;
import org.eclipse.jetty.util.StaticException;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.thread.AutoLock;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.exception.SentinelWebSocketCloseException;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.core.exception.WebSocketWriteTimeoutException;
import org.slf4j.Logger;
Expand All @@ -45,7 +45,7 @@ public class FrameFlusher extends IteratingCallback
{
public static final Frame FLUSH_FRAME = new Frame(OpCode.BINARY);
private static final Logger LOG = LoggerFactory.getLogger(FrameFlusher.class);
private static final Throwable CLOSED_CHANNEL = new SentinelWebSocketCloseException();
private static final Throwable CLOSED_CHANNEL = new StaticException("Closed");

private final AutoLock lock = new AutoLock();
private final LongAdder messagesOut = new LongAdder();
Expand Down
Expand Up @@ -18,9 +18,9 @@

import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IteratingCallback;
import org.eclipse.jetty.util.StaticException;
import org.eclipse.jetty.util.thread.AutoLock;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.exception.SentinelWebSocketCloseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -34,7 +34,7 @@
public abstract class TransformingFlusher
{
private final Logger log = LoggerFactory.getLogger(this.getClass());
private static final Throwable SENTINEL_CLOSE_EXCEPTION = new SentinelWebSocketCloseException();
private static final Throwable SENTINEL_CLOSE_EXCEPTION = new StaticException("Closed");

private final AutoLock lock = new AutoLock();
private final Queue<FrameEntry> entries = new ArrayDeque<>();
Expand Down

0 comments on commit 805c8ee

Please sign in to comment.