Skip to content

Commit

Permalink
Redo Handler renaming (#9318)
Browse files Browse the repository at this point in the history
* Redo Handler renaming

Wrapper to Singleton
BaseWrapper to Wrapper

* Updates from review
  • Loading branch information
gregw authored Feb 7, 2023
1 parent d901237 commit f565122
Show file tree
Hide file tree
Showing 45 changed files with 127 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public boolean process(Request request, Response response, Callback callback)
}

// tag::handlerFilter[]
class FilterHandler extends Handler.BaseWrapper
class FilterHandler extends Handler.Wrapper
{
@Override
public boolean process(Request request, Response response, Callback callback) throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public boolean process(Request request, Response response, Callback callback)
fcgiHandler.setOriginalQueryAttribute(queryAttribute);

proxyContext.stop();
proxyContext.insertHandler(new Handler.BaseWrapper()
proxyContext.insertHandler(new Handler.Wrapper()
{
@Override
public boolean process(Request request, Response response, Callback callback) throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* {@link PatternRule} subclasses), via regular expression matching (using
* {@link RegexRule} subclasses), or by a custom implementation of {@code Rule}.</p>
*/
public class RewriteHandler extends Handler.BaseWrapper
public class RewriteHandler extends Handler.Wrapper
{
private final RuleContainer _rules;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static void setAsParent(Container parent, Handler handler)
{
if (parent instanceof Collection collection)
collection.addHandler(handler);
else if (parent instanceof Wrapper wrapper)
else if (parent instanceof Singleton wrapper)
wrapper.setHandler(handler);
else if (parent != null)
throw new IllegalArgumentException("Unknown parent type: " + parent);
Expand Down Expand Up @@ -256,16 +256,18 @@ default void setHandlers(Handler... handlers)

/**
* <p>A {@link Handler.Container} that can contain a single other {@code Handler}.</p>
* @see BaseWrapper for an implementation of {@link Wrapper}.
* <p>This is "singleton" in the sense of {@link Collections#singleton(Object)} and not
* in the sense of the singleton pattern of a single instance per JVM.</p>
* @see Wrapper for an implementation of {@link Singleton}.
*/
interface Wrapper extends Container
interface Singleton extends Container
{
Handler getHandler();

/**
* Set the nested handler.
* Implementations should check for loops, set the server and update any {@link ContainerLifeCycle} beans, all
* of which can be done by using the utility method {@link #updateHandler(Wrapper, Handler)}
* of which can be done by using the utility method {@link #updateHandler(Singleton, Handler)}
* @param handler The handler to set.
*/
void setHandler(Handler handler);
Expand All @@ -286,12 +288,12 @@ default List<Handler> getHandlers()
return (next == null) ? Collections.emptyList() : Collections.singletonList(next);
}

default void insertHandler(Wrapper handler)
default void insertHandler(Singleton handler)
{
Wrapper tail = handler;
while (tail.getHandler() instanceof BaseWrapper)
Singleton tail = handler;
while (tail.getHandler() instanceof Wrapper)
{
tail = (BaseWrapper)tail.getHandler();
tail = (Wrapper)tail.getHandler();
}
if (tail.getHandler() != null)
throw new IllegalArgumentException("bad tail of inserted wrapper chain");
Expand All @@ -301,12 +303,12 @@ default void insertHandler(Wrapper handler)
}

/**
* @return The tail {@link Wrapper} of a chain of {@link Wrapper}s
* @return The tail {@link Singleton} of a chain of {@link Singleton}s
*/
default Wrapper getTail()
default Singleton getTail()
{
Wrapper tail = this;
while (tail.getHandler() instanceof Wrapper wrapped)
Singleton tail = this;
while (tail.getHandler() instanceof Singleton wrapped)
tail = wrapped;
return tail;
}
Expand All @@ -322,7 +324,7 @@ default Wrapper getTail()
* @param handler The handle to set
* @return The set handler.
*/
static Handler updateHandler(Wrapper wrapper, Handler handler)
static Handler updateHandler(Singleton wrapper, Handler handler)
{
// check state
Server server = wrapper.getServer();
Expand Down Expand Up @@ -561,31 +563,31 @@ public static <T extends Handler.Container> T findContainerOf(Handler.Container
}

/**
* An implementation of {@link Wrapper}, which is a {@link Handler.Container} that wraps a single other {@link Handler}.
* An implementation of {@link Singleton}, which is a {@link Handler.Container} that wraps a single other {@link Handler}.
*/
class BaseWrapper extends AbstractContainer implements Wrapper
class Wrapper extends AbstractContainer implements Singleton
{
private Handler _handler;

public BaseWrapper()
public Wrapper()
{
this(null);
}

public BaseWrapper(boolean dynamic)
public Wrapper(boolean dynamic)
{
this(dynamic, null);
}

public BaseWrapper(Handler handler)
public Wrapper(Handler handler)
{
this(false, handler);
}

public BaseWrapper(boolean dynamic, Handler handler)
public Wrapper(boolean dynamic, Handler handler)
{
super(dynamic);
_handler = handler == null ? null : Wrapper.updateHandler(this, handler);
_handler = handler == null ? null : Singleton.updateHandler(this, handler);
}

@Override
Expand All @@ -599,7 +601,7 @@ public void setHandler(Handler handler)
{
if (!isDynamic() && isStarted())
throw new IllegalStateException(getState());
_handler = Wrapper.updateHandler(this, handler);
_handler = Singleton.updateHandler(this, handler);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Server extends Handler.BaseWrapper implements Attributes
public class Server extends Handler.Wrapper implements Attributes
{
private static final Logger LOG = LoggerFactory.getLogger(Server.class);
private static final String __serverInfo = "jetty/" + Server.getVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* (obtained from {@link HttpStream#getNanoTime()}) until the stream completion event has been handled by
* {@link HttpStream#succeeded()} or {@link HttpStream#failed(Throwable)}.</p>
*/
public abstract class AbstractLatencyRecordingHandler extends Handler.BaseWrapper
public abstract class AbstractLatencyRecordingHandler extends Handler.Wrapper
{
private static final Logger LOG = LoggerFactory.getLogger(AbstractLatencyRecordingHandler.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* generated can also be unbounded.
* </p>
*/
public class BufferedResponseHandler extends Handler.BaseWrapper
public class BufferedResponseHandler extends Handler.Wrapper
{
public static final String BUFFER_SIZE_ATTRIBUTE_NAME = BufferedResponseHandler.class.getName() + ".buffer-size";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
/**
* <p>Implementation of a {@link Handler} that supports HTTP CONNECT.</p>
*/
public class ConnectHandler extends Handler.BaseWrapper
public class ConnectHandler extends Handler.Wrapper
{
private static final Logger LOG = LoggerFactory.getLogger(ConnectHandler.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ContextHandler extends Handler.BaseWrapper implements Attributes, Graceful, AliasCheck
public class ContextHandler extends Handler.Wrapper implements Attributes, Graceful, AliasCheck
{
// TODO where should the alias checking go?
// TODO add protected paths to ServletContextHandler?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* and the current thread name is updated with information that will link
* to the details in that output.
*/
public class DebugHandler extends Handler.BaseWrapper implements Connection.Listener
public class DebugHandler extends Handler.Wrapper implements Connection.Listener
{
private final DateCache _date = new DateCache("HH:mm:ss", Locale.US);
private OutputStream _out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.StringUtil;

public class DelayedHandler extends Handler.BaseWrapper
public class DelayedHandler extends Handler.Wrapper
{
@Override
public boolean process(Request request, Response response, Callback callback) throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Handler to track active requests and allow them to gracefully complete.
*/
public class GracefulHandler extends Handler.BaseWrapper implements Graceful
public class GracefulHandler extends Handler.Wrapper implements Graceful
{
private static final Logger LOG = LoggerFactory.getLogger(GracefulHandler.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* A <code>HandlerContainer</code> that allows a hot swap of a wrapped handler.
*/
public class HotSwapHandler extends Handler.AbstractContainer implements Handler.Wrapper
public class HotSwapHandler extends Handler.AbstractContainer implements Handler.Singleton
{
// TODO unit tests

Expand Down Expand Up @@ -51,7 +51,7 @@ public Handler getHandler()
public void setHandler(Handler handler)
{
// check state
Server server1 = ((Wrapper)this).getServer();
Server server1 = ((Singleton)this).getServer();
if (server1 != null && server1.isStarted() && handler != null &&
server1.getInvocationType() != Invocable.combine(server1.getInvocationType(), handler.getInvocationType()))
throw new IllegalArgumentException("Cannot change invocation type of started server");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* &lt;/Set&gt;
* </pre>
*/
public class IdleTimeoutHandler extends Handler.BaseWrapper
public class IdleTimeoutHandler extends Handler.Wrapper
{
private long _idleTimeoutMs = 1000;
private boolean _applyToAsync = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* the forwarded for headers, as this cannot be as easily forged.
* </p>
*/
public class InetAccessHandler extends Handler.BaseWrapper
public class InetAccessHandler extends Handler.Wrapper
{
// TODO replace this handler with a general conditional handler wrapper.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.HostPort;

public class ProxiedRequestHandler extends Handler.BaseWrapper
public class ProxiedRequestHandler extends Handler.Wrapper
{
@Override
public boolean process(Request request, Response response, Callback callback) throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* - request ranges
* - a way to configure caching or not
*/
public class ResourceHandler extends Handler.BaseWrapper
public class ResourceHandler extends Handler.Wrapper
{
private final ResourceService _resourceService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* {@link HttpConfiguration#getSecurePort()}
* </p>
*/
public class SecuredRedirectHandler extends Handler.BaseWrapper
public class SecuredRedirectHandler extends Handler.Wrapper
{
/**
* The redirect code to send in response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* }
* }</pre>
*/
public class ShutdownHandler extends Handler.BaseWrapper
public class ShutdownHandler extends Handler.Wrapper
{
private static final Logger LOG = LoggerFactory.getLogger(ShutdownHandler.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.eclipse.jetty.util.statistic.CounterStatistic;
import org.eclipse.jetty.util.statistic.SampleStatistic;

public class StatisticsHandler extends Handler.BaseWrapper
public class StatisticsHandler extends Handler.Wrapper
{
private final Set<String> _connectionStats = ConcurrentHashMap.newKeySet();
private final CounterStatistic _requestStats = new CounterStatistic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* a thread is available.
* <p>This is a simpler alternative to DosFilter</p>
*/
public class ThreadLimitHandler extends Handler.BaseWrapper
public class ThreadLimitHandler extends Handler.Wrapper
{
private static final Logger LOG = LoggerFactory.getLogger(ThreadLimitHandler.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* under the names specified by {@link #setOriginalPathAttribute(String)}
* and {@link #setOriginalQueryAttribute(String)}.</p>
*/
public class TryPathsHandler extends Handler.BaseWrapper
public class TryPathsHandler extends Handler.Wrapper
{
private String originalPathAttribute;
private String originalQueryAttribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GzipHandler extends Handler.BaseWrapper implements GzipFactory
public class GzipHandler extends Handler.Wrapper implements GzipFactory
{
public static final String GZIP_HANDLER_ETAGS = "o.e.j.s.h.gzip.GzipHandler.etag";
public static final String GZIP = "gzip";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ public Content.Chunk read()
public void testProcessingAfterCompletion() throws Exception
{
AtomicReference<String> result = new AtomicReference<>();
Handler.Wrapper wrapper = new Handler.BaseWrapper()
Handler.Singleton wrapper = new Handler.Wrapper()
{
@Override
public boolean process(Request request, Response response, Callback callback) throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void testFindContainer()

ContextHandler contextB = new ContextHandler("/b");
IsHandledHandler handlerB = new IsHandledHandler("B");
Handler.Wrapper wrapperB = new Handler.BaseWrapper();
Handler.Singleton wrapperB = new Handler.Wrapper();
wrapperB.setHandler(handlerB);
contextB.setHandler(wrapperB);

Expand All @@ -334,16 +334,16 @@ public void testFindContainer()
collection.addHandler(contextB);
collection.addHandler(contextC);

Handler.Wrapper wrapper = new Handler.BaseWrapper();
Handler.Singleton wrapper = new Handler.Wrapper();
wrapper.setHandler(collection);
server.setHandler(wrapper);

assertEquals(wrapper, Handler.AbstractContainer.findContainerOf(server, Handler.BaseWrapper.class, handlerA));
assertEquals(wrapper, Handler.AbstractContainer.findContainerOf(server, Handler.Wrapper.class, handlerA));
assertEquals(contextA, Handler.AbstractContainer.findContainerOf(server, ContextHandler.class, handlerA));
assertEquals(contextB, Handler.AbstractContainer.findContainerOf(server, ContextHandler.class, handlerB));
assertEquals(wrapper, Handler.AbstractContainer.findContainerOf(server, Handler.BaseWrapper.class, handlerB));
assertEquals(contextB, Handler.AbstractContainer.findContainerOf(collection, Handler.BaseWrapper.class, handlerB));
assertEquals(wrapperB, Handler.AbstractContainer.findContainerOf(contextB, Handler.BaseWrapper.class, handlerB));
assertEquals(wrapper, Handler.AbstractContainer.findContainerOf(server, Handler.Wrapper.class, handlerB));
assertEquals(contextB, Handler.AbstractContainer.findContainerOf(collection, Handler.Wrapper.class, handlerB));
assertEquals(wrapperB, Handler.AbstractContainer.findContainerOf(contextB, Handler.Wrapper.class, handlerB));
}

@Test
Expand Down Expand Up @@ -407,7 +407,7 @@ public void testWrappedContext() throws Exception
assertThat(response, containsString("Wrapped: right"));
}

private static final class WrappedHandler extends Handler.BaseWrapper
private static final class WrappedHandler extends Handler.Wrapper
{
private final String tag;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public void testSetHandlerLoopSelf()
public void testSetHandlerLoopDeepWrapper()
{
ContextHandler contextHandlerA = new ContextHandler();
Handler.Wrapper handlerWrapper = new Handler.BaseWrapper();
Handler.Singleton handlerWrapper = new Handler.Wrapper();
contextHandlerA.setHandler(handlerWrapper);
assertThrows(IllegalStateException.class, () -> handlerWrapper.setHandler(contextHandlerA));
}
Expand Down
Loading

0 comments on commit f565122

Please sign in to comment.