Class Server

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
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.
  • Constructor Details

    • Server

      public Server()
    • Server

      public Server(@Name("port") int port)
      Convenience constructor Creates server and a ServerConnector at the passed port.
      Parameters:
      port - The port of a network HTTP connector (or 0 for a randomly allocated port).
      See Also:
    • Server

      public Server(@Name("address") InetSocketAddress addr)
      Convenience constructor

      Creates 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

      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 String 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:
    • 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 calls getConnectors() and setConnectors(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(Object bean)
      Add a bean to all connectors on the server. If the bean is an instance of Connection.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 if ContainerLifeCycle.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 if ContainerLifeCycle.dumpStdErr() is called before stopping
    • getDateField

      public org.eclipse.jetty.http.HttpField getDateField()
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class AbstractHandler
      Throws:
      Exception
    • start

      protected void start(org.eclipse.jetty.util.component.LifeCycle l) throws Exception
      Overrides:
      start in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class AbstractHandler
      Throws:
      Exception
    • handle

      public void handle(HttpChannel channel) throws IOException, jakarta.servlet.ServletException
      Throws:
      IOException
      jakarta.servlet.ServletException
    • handleOptions

      protected void handleOptions(Request request, Response response) throws IOException
      Throws:
      IOException
    • handleAsync

      public void handleAsync(HttpChannel channel) throws IOException, jakarta.servlet.ServletException
      Throws:
      IOException
      jakarta.servlet.ServletException
    • join

      public void join() throws InterruptedException
      Throws:
      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:
      clearAttributes in interface org.eclipse.jetty.util.Attributes
    • getAttribute

      public Object getAttribute(String name)
      Specified by:
      getAttribute in interface org.eclipse.jetty.util.Attributes
    • getAttributeNames

      public Enumeration<String> getAttributeNames()
      Specified by:
      getAttributeNames in interface org.eclipse.jetty.util.Attributes
    • getAttributeNameSet

      public Set<String> getAttributeNameSet()
      Specified by:
      getAttributeNameSet in interface org.eclipse.jetty.util.Attributes
    • removeAttribute

      public void removeAttribute(String name)
      Specified by:
      removeAttribute in interface org.eclipse.jetty.util.Attributes
    • setAttribute

      public void setAttribute(String name, Object attribute)
      Specified by:
      setAttribute in interface org.eclipse.jetty.util.Attributes
    • getURI

      public URI getURI()
      Returns:
      The URI of the first NetworkConnector and first ContextHandler, or null
    • toString

      public String toString()
      Overrides:
      toString in class org.eclipse.jetty.util.component.AbstractLifeCycle
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Specified by:
      dump in interface org.eclipse.jetty.util.component.Dumpable
      Overrides:
      dump in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      IOException
    • main

      public static void main(String... args) throws Exception
      Throws:
      Exception