java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
- All Implemented Interfaces:
Handler
,HandlerContainer
,org.eclipse.jetty.util.Attributes
,org.eclipse.jetty.util.component.Container
,org.eclipse.jetty.util.component.Destroyable
,org.eclipse.jetty.util.component.Dumpable
,org.eclipse.jetty.util.component.Dumpable.DumpableContainer
,org.eclipse.jetty.util.component.LifeCycle
@ManagedObject("Jetty HTTP Servlet server")
public class Server
extends HandlerWrapper
implements org.eclipse.jetty.util.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 classes/interfaces inherited from class org.eclipse.jetty.server.handler.AbstractHandler
AbstractHandler.ErrorDispatchHandler
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Attributes
org.eclipse.jetty.util.Attributes.Wrapper
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener
-
Field Summary
Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
_handler
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPING
Fields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEY
-
Constructor Summary
ConstructorDescriptionServer()
Server
(int port) Convenience constructor Creates server and aServerConnector
at the passed port.Server
(InetSocketAddress addr) Convenience constructorServer
(org.eclipse.jetty.util.thread.ThreadPool pool) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBeanToAllConnectors
(Object bean) Add a bean to all connectors on the server.void
addConnector
(Connector connector) void
protected void
doStart()
protected void
doStop()
void
dump
(Appendable out, String indent) getAttribute
(String name) org.eclipse.jetty.http.HttpField
boolean
long
org.eclipse.jetty.util.thread.ThreadPool
getURI()
static String
void
handle
(HttpChannel channel) void
handleAsync
(HttpChannel channel) protected void
handleOptions
(Request request, Response response) boolean
isDryRun()
boolean
boolean
void
join()
static void
void
removeAttribute
(String name) void
removeConnector
(Connector connector) Convenience method which callsgetConnectors()
andsetConnectors(Connector[])
to remove a connector.void
setAttribute
(String name, Object attribute) void
setConnectors
(Connector[] connectors) Set the connectors for this server.void
setDryRun
(boolean dryRun) void
setDumpAfterStart
(boolean dumpAfterStart) void
setDumpBeforeStop
(boolean dumpBeforeStop) void
setErrorHandler
(ErrorHandler errorHandler) void
setRequestLog
(RequestLog requestLog) void
setSessionIdManager
(SessionIdManager sessionIdManager) void
setStopAtShutdown
(boolean stop) Set stop server at shutdown behaviour.void
setStopTimeout
(long stopTimeout) protected void
start
(org.eclipse.jetty.util.component.LifeCycle l) toString()
Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
destroy, expandChildren, getHandler, getHandlers, handle, insertHandler, setHandler
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler
doError, getServer
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable
dumpSelf
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Constructor Details
-
Server
public Server() -
Server
public Server(@Name("port") int port) Convenience constructor Creates server and aServerConnector
at 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
ServerConnector
at the passed address.- Parameters:
addr
- the inet socket address to create the connector from
-
Server
public Server(@Name("threadpool") org.eclipse.jetty.util.thread.ThreadPool pool)
-
-
Method Details
-
isDryRun
public boolean isDryRun() -
setDryRun
public void setDryRun(boolean dryRun) -
getRequestLog
-
getErrorHandler
-
setRequestLog
-
setErrorHandler
-
getVersion
-
setStopTimeout
public void setStopTimeout(long stopTimeout) -
getStopTimeout
public long getStopTimeout() -
getStopAtShutdown
public boolean getStopAtShutdown() -
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:
-
Runtime.addShutdownHook(Thread)
ShutdownThread
-
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.Listener
it will also be registered as a listener on all connections accepted by the connectors.- Parameters:
bean
- the bean to be added.
-
getThreadPool
@ManagedAttribute("the server thread pool") public org.eclipse.jetty.util.thread.ThreadPool getThreadPool()- Returns:
- Returns the threadPool.
-
isDumpAfterStart
@ManagedAttribute("dump state to stderr after start") public boolean 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
@ManagedAttribute("dump state to stderr before stop") public boolean 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
public org.eclipse.jetty.http.HttpField getDateField() -
doStart
- Overrides:
doStart
in classAbstractHandler
- Throws:
Exception
-
start
- Overrides:
start
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
Exception
-
doStop
- Overrides:
doStop
in classAbstractHandler
- Throws:
Exception
-
handle
- Throws:
IOException
jakarta.servlet.ServletException
-
handleOptions
- Throws:
IOException
-
handleAsync
- Throws:
IOException
jakarta.servlet.ServletException
-
join
- Throws:
InterruptedException
-
getSessionIdManager
- Returns:
- Returns the sessionIdManager.
-
setSessionIdManager
- Parameters:
sessionIdManager
- The sessionIdManager to set.
-
clearAttributes
public void clearAttributes()- Specified by:
clearAttributes
in interfaceorg.eclipse.jetty.util.Attributes
-
getAttribute
- Specified by:
getAttribute
in interfaceorg.eclipse.jetty.util.Attributes
-
getAttributeNames
- Specified by:
getAttributeNames
in interfaceorg.eclipse.jetty.util.Attributes
-
getAttributeNameSet
- Specified by:
getAttributeNameSet
in interfaceorg.eclipse.jetty.util.Attributes
-
removeAttribute
- Specified by:
removeAttribute
in interfaceorg.eclipse.jetty.util.Attributes
-
setAttribute
- Specified by:
setAttribute
in interfaceorg.eclipse.jetty.util.Attributes
-
getURI
- Returns:
- The URI of the first
NetworkConnector
and firstContextHandler
, or null
-
toString
- Overrides:
toString
in classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
dump
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Overrides:
dump
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
IOException
-
main
- Throws:
Exception
-