Top Description Inners Fields Constructors Methods
org.eclipse.jetty.server.handler

public Class ContextHandlerCollection

extends Sequence
Class Inheritance
Annotations
@ManagedObject:Context Handler Collection
Imports
java.util.ArrayList, .Collections, .HashMap, .HashSet, .LinkedHashMap, .List, .Map, .Set, .TreeSet, java.util.stream.Collectors, .Stream, org.eclipse.jetty.server.Handler, .Request, .Response, org.eclipse.jetty.util.ArrayUtil, .Callback, .Index, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, .ManagedOperation, org.eclipse.jetty.util.thread.SerializedExecutor, org.slf4j.Logger, .LoggerFactory

Creates a Map of contexts to it's contained handlers based on the context path and virtual hosts of any contained ContextHandlers. The contexts do not need to be directly contained, only children of the contained handlers. Multiple contexts may have the same context path and they are called in order until one handles the request.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final SerializedExecutor
private static final Logger

Constructor Summary

AccessConstructor and Description
public
public
ContextHandlerCollection(boolean
If true, then contexts may be added dynamically once started, so the InvocationType is assumed to be BLOCKING, otherwise the InvocationType is fixed once started and handlers cannot be subsequently added.
dynamic
,
ContextHandler...
The contexts to add.
contexts
)

Method Summary

Modifier and TypeMethod and Description
public void
deployHandler(Handler
the handler to deploy
handler
,
Callback
Called after handler has been added
callback
)

Thread safe deploy of a Handler.

public Set<String>
public boolean
handle(Request
the HTTP request to handle
request
,
Response
the HTTP response to handle
response
,
Callback
the callback to complete when the handling is complete
callback
)

Overrides org.eclipse.jetty.server.Handler.Sequence.handle.

Implements org.eclipse.jetty.server.Request.Handler.handle.

Invoked to handle the passed HTTP request and response.

public void
mapContexts()

Remap the contexts.

protected List<Handler>
public void
undeployHandler(Handler
The handler to undeploy
handler
,
Callback
Called after handler has been removed
callback
)

Thread safe undeploy of a Handler.

Inherited from org.eclipse.jetty.server.Handler.Sequence:
getHandlersgetInvocationTypesetHandlers

Field Detail

_serializedExecutorback to summary
private final SerializedExecutor _serializedExecutor
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.server.Handler.Abstract.LOG.

Constructor Detail

ContextHandlerCollectionback to summary
public ContextHandlerCollection(ContextHandler... contexts)
ContextHandlerCollectionback to summary
public ContextHandlerCollection(boolean dynamic, ContextHandler... contexts)
Parameters
dynamic:boolean

If true, then contexts may be added dynamically once started, so the InvocationType is assumed to be BLOCKING, otherwise the InvocationType is fixed once started and handlers cannot be subsequently added.

contexts:ContextHandler[]

The contexts to add.

Method Detail

deployHandlerback to summary
public void deployHandler(Handler handler, Callback callback)

Thread safe deploy of a Handler.

This method is the equivalent of addHandler(Handler), but its execution is non-blocking and mutually excluded from all other callers to itself and undeployHandler(Handler, Callback). The handler may be added after this call returns.

Parameters
handler:Handler

the handler to deploy

callback:Callback

Called after handler has been added

getContextPathsback to summary
public Set<String> getContextPaths()
Annotations
@ManagedAttribute:The paths of the contexts in this collection
handleback to summary
public boolean handle(Request request, Response response, Callback callback) throws Exception

Overrides org.eclipse.jetty.server.Handler.Sequence.handle.

Implements org.eclipse.jetty.server.Request.Handler.handle.

Doc from org.eclipse.jetty.server.Request.Handler.handle.

Invoked to handle the passed HTTP request and response.

The request is accepted by returning true, then handling must be concluded by completing the passed callback. The handling may be asynchronous, i.e. this method may return true and complete the given callback later, possibly from a different thread. If this method returns false, then the callback must not be invoked and any mutation on the response reversed.

Exceptions thrown by this method may be subsequently handled by an error Request.Handler, if present, otherwise a default HTTP 500 error is generated and the callback completed while writing the error response.

The simplest implementation is:

public boolean handle(Request request, Response response, Callback callback)
{
    callback.succeeded();
    return true;
}

A HelloWorld implementation is:

public boolean handle(Request request, Response response, Callback callback)
{
    response.write(true, ByteBuffer.wrap("Hello World\n".getBytes(StandardCharsets.UTF_8)), callback);
    return true;
}
Parameters
request:Request

the HTTP request to handle

response:Response

the HTTP response to handle

callback:Callback

the callback to complete when the handling is complete

Returns:boolean

True if and only if the request will be handled, a response generated and the callback eventually called. This may occur within the scope of the call to this method, or asynchronously some time later. If false is returned, then this method must not generate a response, nor complete the callback.

Annotations
@Override
Exceptions
Exception:
if there is a failure during the handling. Catchers cannot assume that the callback will be called and thus should attempt to complete the request as if a false had been returned.
mapContextsback to summary
public void mapContexts()

Remap the contexts. Normally this is not required as context mapping is maintained as a side effect of setHandlers(Handler[]) However, if configuration changes in the deep handler structure (eg contextpath is changed), then this call will trigger a remapping. This method is mutually excluded from deployHandler(Handler, Callback) and undeployHandler(Handler, Callback)

Annotations
@ManagedOperation:Update the mapping of context path to context
impact:ACTION
newHandlersback to summary
protected List<Handler> newHandlers(List<Handler> handlers)

Overrides org.eclipse.jetty.server.Handler.Sequence.newHandlers.

Annotations
@Override
undeployHandlerback to summary
public void undeployHandler(Handler handler, Callback callback)

Thread safe undeploy of a Handler.

This method is the equivalent of removeHandler(Handler), but its execution is non-block and mutually excluded from all other calls to deployHandler(Handler, Callback) and itself. The handler may be removed after this call returns.

Parameters
handler:Handler

The handler to undeploy

callback:Callback

Called after handler has been removed

org.eclipse.jetty.server.handler back to summary

private final Class ContextHandlerCollection.Branch

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jetty.server.handler.ContextHandlerCollection.Branch

Field Summary

Modifier and TypeField and Description
private final List<ContextHandler>
private final Handler

Constructor Summary

AccessConstructor and Description
pack-priv
Branch(Handler handler)

Method Summary

Modifier and TypeMethod and Description
pack-priv Set<String>
pack-priv Handler
pack-priv boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_contextsback to summary
private final List<ContextHandler> _contexts
_handlerback to summary
private final Handler _handler

Constructor Detail

Branchback to summary
pack-priv Branch(Handler handler)

Method Detail

getContextPathsback to summary
pack-priv Set<String> getContextPaths()
getHandlerback to summary
pack-priv Handler getHandler()
hasVirtualHostback to summary
pack-priv boolean hasVirtualHost()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.eclipse.jetty.server.handler back to summary

private Class ContextHandlerCollection.Mapping

extends ArrayList<Handler>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Index<Map.Entry<String, ContextHandlerCollection.Branch[]>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.util.ArrayList:
addaddaddAlladdAlladdFirstaddLastclearclonecontainsensureCapacityequalsforEachgetgetFirstgetLasthashCodeindexOfisEmptyiteratorlastIndexOflistIteratorlistIteratorremoveremoveremoveAllremoveFirstremoveIfremoveLastremoveRangereplaceAllretainAllsetsizesortspliteratorsubListtoArraytoArraytrimToSize

Field Detail

_pathBranchesback to summary
private final Index<Map.Entry<String, ContextHandlerCollection.Branch[]>> _pathBranches

Constructor Detail

Mappingback to summary
private Mapping(List<Handler> handlers, Map<String, ContextHandlerCollection.Branch[]> path2Branches)