Class Server
- All Implemented Interfaces:
Handler, HandlerContainer, Attributes, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
@ManagedObject("Jetty HTTP Servlet server")
public class Server
extends HandlerWrapper
implements Attributes
Jetty HTTP Servlet Server.
This class is the main class for the Jetty HTTP Servlet server.
It aggregates Connectors (HTTP request receivers) and request Handlers.
The server is itself a handler and a ThreadPool. Connectors use the ThreadPool methods
to run jobs that will eventually call the handle method.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class AbstractHandler
AbstractHandler.ErrorDispatchHandlerNested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListenerNested classes/interfaces inherited from interface Attributes
Attributes.WrapperNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AttributeContainerMapprivate Server.DateFieldprivate final Lockerprivate booleanprivate booleanprivate ErrorHandlerprivate RequestLogprivate SessionIdManagerprivate booleanprivate final ThreadPoolprivate static final LoggerFields inherited from class HandlerWrapper
_handler -
Constructor Summary
ConstructorsConstructorDescriptionServer()Server(int port) Convenience constructor Creates server and aServerConnectorat the passed port.Server(InetSocketAddress addr) Convenience constructorServer(ThreadPool pool) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBeanToAllConnectors(Object bean) Add a bean to all connectors on the server.voidaddConnector(Connector connector) voidprotected voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.getAttribute(String name) booleangetURI()static Stringvoidhandle(HttpChannel channel) voidhandleAsync(HttpChannel channel) protected voidhandleOptions(Request request, Response response) booleanbooleanvoidjoin()static voidvoidremoveAttribute(String name) voidremoveConnector(Connector connector) Convenience method which callsgetConnectors()andsetConnectors(Connector[])to remove a connector.voidsetAttribute(String name, Object attribute) voidsetConnectors(Connector[] connectors) Set the connectors for this server.voidsetDumpAfterStart(boolean dumpAfterStart) voidsetDumpBeforeStop(boolean dumpBeforeStop) voidsetErrorHandler(ErrorHandler errorHandler) voidsetRequestLog(RequestLog requestLog) voidsetSessionIdManager(SessionIdManager sessionIdManager) voidsetStopAtShutdown(boolean stop) Set stop server at shutdown behaviour.voidsetStopTimeout(long stopTimeout) Set a graceful stop time.protected voidStarts the given lifecycle.toString()Methods inherited from class HandlerWrapper
destroy, expandChildren, getHandler, getHandlers, handle, insertHandler, setHandlerMethods inherited from class AbstractHandlerContainer
doShutdown, expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServerMethods inherited from class AbstractHandler
doError, getServerMethods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, stop, unmanage, updateBean, updateBean, updateBeansMethods inherited from class AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Dumpable.DumpableContainer
isDumpableMethods inherited from interface LifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Field Details
-
LOG
-
_attributes
-
_threadPool
-
_connectors
-
_sessionIdManager
-
_stopAtShutdown
private boolean _stopAtShutdown -
_dumpAfterStart
private boolean _dumpAfterStart -
_dumpBeforeStop
private boolean _dumpBeforeStop -
_errorHandler
-
_requestLog
-
_dateLocker
-
_dateField
-
-
Constructor Details
-
Server
public Server() -
Server
Convenience constructor Creates server and aServerConnectorat the passed port.- Parameters:
port- The port of a network HTTP connector (or 0 for a randomly allocated port).- See Also:
-
Server
Convenience constructorCreates server and a
ServerConnectorat the passed address.- Parameters:
addr- the inet socket address to create the connector from
-
Server
-
-
Method Details
-
getRequestLog
-
getErrorHandler
-
setRequestLog
-
setErrorHandler
-
getVersion
-
getStopAtShutdown
public boolean getStopAtShutdown() -
setStopTimeout
public void setStopTimeout(long stopTimeout) Set a graceful stop time. TheStatisticsHandlermust be configured so that open connections can be tracked for a graceful shutdown.- Overrides:
setStopTimeoutin classContainerLifeCycle- See Also:
-
setStopAtShutdown
public void setStopAtShutdown(boolean stop) Set stop server at shutdown behaviour.- Parameters:
stop- If true, this server instance will be explicitly stopped when the JVM is shutdown. Otherwise the JVM is stopped with the server running.- See Also:
-
getConnectors
@ManagedAttribute(value="connectors for this server", readonly=true) public Connector[] getConnectors()- Returns:
- Returns the connectors.
-
addConnector
-
removeConnector
Convenience method which callsgetConnectors()andsetConnectors(Connector[])to remove a connector.- Parameters:
connector- The connector to remove.
-
setConnectors
Set the connectors for this server. Each connector has this server set as it's ThreadPool and its Handler.- Parameters:
connectors- The connectors to set.
-
addBeanToAllConnectors
Add a bean to all connectors on the server. If the bean is an instance ofConnection.Listenerit will also be registered as a listener on all connections accepted by the connectors.- Parameters:
bean- the bean to be added.
-
getThreadPool
- Returns:
- Returns the threadPool.
-
isDumpAfterStart
- Returns:
- true if
ContainerLifeCycle.dumpStdErr()is called after starting
-
setDumpAfterStart
public void setDumpAfterStart(boolean dumpAfterStart) - Parameters:
dumpAfterStart- true ifContainerLifeCycle.dumpStdErr()is called after starting
-
isDumpBeforeStop
- Returns:
- true if
ContainerLifeCycle.dumpStdErr()is called before stopping
-
setDumpBeforeStop
public void setDumpBeforeStop(boolean dumpBeforeStop) - Parameters:
dumpBeforeStop- true ifContainerLifeCycle.dumpStdErr()is called before stopping
-
getDateField
-
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classAbstractHandler- Throws:
Exception
-
start
Description copied from class:ContainerLifeCycleStarts the given lifecycle.- Overrides:
startin classContainerLifeCycle- Parameters:
l- the lifecycle to start- Throws:
Exception- if unable to start lifecycle
-
doStop
Description copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classAbstractHandler- Throws:
Exception
-
handle
- Throws:
IOExceptionjavax.servlet.ServletException
-
handleOptions
- Throws:
IOException
-
handleAsync
- Throws:
IOExceptionjavax.servlet.ServletException
-
join
- Throws:
InterruptedException
-
getSessionIdManager
- Returns:
- Returns the sessionIdManager.
-
setSessionIdManager
- Parameters:
sessionIdManager- The sessionIdManager to set.
-
clearAttributes
public void clearAttributes()- Specified by:
clearAttributesin interfaceAttributes
-
getAttribute
- Specified by:
getAttributein interfaceAttributes
-
getAttributeNames
- Specified by:
getAttributeNamesin interfaceAttributes
-
getAttributeNameSet
- Specified by:
getAttributeNameSetin interfaceAttributes
-
removeAttribute
- Specified by:
removeAttributein interfaceAttributes
-
setAttribute
- Specified by:
setAttributein interfaceAttributes
-
getURI
- Returns:
- The URI of the first
NetworkConnectorand firstContextHandler, or null
-
toString
- Overrides:
toStringin classAbstractLifeCycle
-
dump
Description copied from interface:DumpableDump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.- Specified by:
dumpin interfaceDumpable- Overrides:
dumpin classContainerLifeCycle- Parameters:
out- The appendable to dump toindent- The indent to apply after any new lines.- Throws:
IOException- if unable to write to Appendable
-
main
-