Package org.eclipse.jetty.server
Class Server
- 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.AttributesJetty 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
-
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
-
-
Field Summary
-
Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
_handler
-
-
Constructor Summary
Constructors Constructor Description Server()Server(int port)Convenience constructor Creates server and aServerConnectorat the passed port.Server(java.net.InetSocketAddress addr)Convenience constructorServer(org.eclipse.jetty.util.thread.ThreadPool pool)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBeanToAllConnectors(java.lang.Object bean)Add a bean to all connectors on the server.voidaddConnector(Connector connector)voidclearAttributes()protected voiddoStart()protected voiddoStop()voiddump(java.lang.Appendable out, java.lang.String indent)java.lang.ObjectgetAttribute(java.lang.String name)java.util.Enumeration<java.lang.String>getAttributeNames()java.util.Set<java.lang.String>getAttributeNameSet()Connector[]getConnectors()HttpFieldgetDateField()ErrorHandlergetErrorHandler()RequestLoggetRequestLog()SessionIdManagergetSessionIdManager()booleangetStopAtShutdown()org.eclipse.jetty.util.thread.ThreadPoolgetThreadPool()java.net.URIgetURI()static java.lang.StringgetVersion()voidhandle(HttpChannel channel)voidhandleAsync(HttpChannel channel)protected voidhandleOptions(Request request, Response response)booleanisDumpAfterStart()booleanisDumpBeforeStop()voidjoin()static voidmain(java.lang.String... args)voidremoveAttribute(java.lang.String name)voidremoveConnector(Connector connector)Convenience method which callsgetConnectors()andsetConnectors(Connector[])to remove a connector.voidsetAttribute(java.lang.String name, java.lang.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 voidstart(org.eclipse.jetty.util.component.LifeCycle l)java.lang.StringtoString()-
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
doShutdown, 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, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
Server
public Server()
-
Server
public Server(@Name("port") int port)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:
NetworkConnector.getLocalPort()
-
Server
public Server(@Name("address") java.net.InetSocketAddress addr)Convenience constructorCreates server and a
ServerConnectorat 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 Detail
-
getRequestLog
public RequestLog getRequestLog()
-
getErrorHandler
public ErrorHandler getErrorHandler()
-
setRequestLog
public void setRequestLog(RequestLog requestLog)
-
setErrorHandler
public void setErrorHandler(ErrorHandler errorHandler)
-
getVersion
@ManagedAttribute("version of this server") public static java.lang.String 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 classorg.eclipse.jetty.util.component.ContainerLifeCycle- See Also:
ContainerLifeCycle.setStopTimeout(long)
-
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
public void addConnector(Connector connector)
-
removeConnector
public void removeConnector(Connector connector)
Convenience method which callsgetConnectors()andsetConnectors(Connector[])to remove a connector.- Parameters:
connector- The connector to remove.
-
setConnectors
public void setConnectors(Connector[] connectors)
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
public void addBeanToAllConnectors(java.lang.Object bean)
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
@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 HttpField getDateField()
-
doStart
protected void doStart() throws java.lang.Exception- Overrides:
doStartin classAbstractHandler- Throws:
java.lang.Exception
-
start
protected void start(org.eclipse.jetty.util.component.LifeCycle l) throws java.lang.Exception- Overrides:
startin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception- Overrides:
doStopin classAbstractHandler- Throws:
java.lang.Exception
-
handle
public void handle(HttpChannel channel) throws java.io.IOException, javax.servlet.ServletException
- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
handleOptions
protected void handleOptions(Request request, Response response) throws java.io.IOException
- Throws:
java.io.IOException
-
handleAsync
public void handleAsync(HttpChannel channel) throws java.io.IOException, javax.servlet.ServletException
- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
join
public void join() throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
getSessionIdManager
public SessionIdManager getSessionIdManager()
- Returns:
- Returns the sessionIdManager.
-
setSessionIdManager
public void setSessionIdManager(SessionIdManager sessionIdManager)
- Parameters:
sessionIdManager- The sessionIdManager to set.
-
clearAttributes
public void clearAttributes()
- Specified by:
clearAttributesin interfaceorg.eclipse.jetty.util.Attributes
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
- Specified by:
getAttributein interfaceorg.eclipse.jetty.util.Attributes
-
getAttributeNames
public java.util.Enumeration<java.lang.String> getAttributeNames()
- Specified by:
getAttributeNamesin interfaceorg.eclipse.jetty.util.Attributes
-
getAttributeNameSet
public java.util.Set<java.lang.String> getAttributeNameSet()
- Specified by:
getAttributeNameSetin interfaceorg.eclipse.jetty.util.Attributes
-
removeAttribute
public void removeAttribute(java.lang.String name)
- Specified by:
removeAttributein interfaceorg.eclipse.jetty.util.Attributes
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object attribute)- Specified by:
setAttributein interfaceorg.eclipse.jetty.util.Attributes
-
getURI
public java.net.URI getURI()
- Returns:
- The URI of the first
NetworkConnectorand firstContextHandler, or null
-
toString
public java.lang.String toString()
- Overrides:
toStringin classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Overrides:
dumpin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
java.io.IOException
-
main
public static void main(java.lang.String... args) throws java.lang.Exception- Throws:
java.lang.Exception
-
-