org.restlet

## Class Server

- java.lang.Object
- - org.restlet.Restlet
  - - org.restlet.Connector
    - - org.restlet.Server

All Implemented Interfaces:
  Uniform

    public class Server
    extends Connector

Connector acting as a generic server. It internally uses one of the available connector helpers registered with the Restlet engine.
Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.

Author:
  Jerome Louvel

### Constructor Summary

Constructors
Constructor and Description
`Server(Context context, java.util.List<Protocol> protocols, int port, Restlet next)` Constructor.
`Server(Context context, java.util.List<Protocol> protocols, java.lang.String address, int port, Restlet next)` Constructor.
`Server(Context context, java.util.List<Protocol> protocols, java.lang.String address, int port, Restlet next, java.lang.String helperClass)` Constructor.
`Server(Context context, Protocol protocol, java.lang.Class<?> nextClass)` Constructor.
`Server(Context context, Protocol protocol, int port)` Constructor.
`Server(Context context, Protocol protocol, int port, java.lang.Class<?> nextClass)` Constructor.
`Server(Context context, Protocol protocol, int port, Restlet next)` Constructor.
`Server(Context context, Protocol protocol, Restlet next)` Constructor using the protocol's default port.
`Server(Context context, Protocol protocol, java.lang.String address, int port, Restlet next)` Constructor.
`Server(java.util.List<Protocol> protocols, int port, Restlet next)` Constructor.
`Server(java.util.List<Protocol> protocols, java.lang.String address, int port, Restlet next)` Constructor.
`Server(Protocol protocol)` Constructor.
`Server(Protocol protocol, java.lang.Class<?> nextClass)` Constructor using the protocol's default port.
`Server(Protocol protocol, int port)` Constructor.
`Server(Protocol protocol, int port, java.lang.Class<?> nextClass)` Constructor.
`Server(Protocol protocol, int port, Restlet next)` Constructor.
`Server(Protocol protocol, Restlet next)` Constructor using the protocol's default port.
`Server(Protocol protocol, java.lang.String address)` Constructor using the protocol's default port.
`Server(Protocol protocol, java.lang.String address, java.lang.Class<?> nextClass)` Constructor using the protocol's default port.
`Server(Protocol protocol, java.lang.String address, int port)` Constructor.
`Server(Protocol protocol, java.lang.String address, int port, Restlet next)` Constructor.
`Server(Protocol protocol, java.lang.String address, Restlet next)` Constructor using the protocol's default port.

### Method Summary

Methods
`java.lang.String` `getAddress()` Returns the optional listening IP address (local host used if null).
`int` `getEphemeralPort()` Returns the actual ephemeral port used when the listening port is set to '0'.
`Restlet` `getNext()` Returns the next Restlet.
`int` `getPort()` Returns the listening port if specified.
`Restlet` `getTarget()` Deprecated. Use the `getNext()` method instead.
`void` `handle(Request request, Response response)` Handles a call.
`boolean` `hasNext()` Indicates if a next Restlet is set.
`boolean` `hasTarget()` Deprecated. Use the `hasNext()` method instead.
`boolean` `isAvailable()` Indicates the underlying connector helper is available.
`void` `setAddress(java.lang.String address)` Sets the optional listening IP address (local host used if null).
`void` `setNext(java.lang.Class<?> nextClass)` Sets the next Restlet as a Finder for a given resource class.
`void` `setNext(Restlet next)` Sets the next Restlet.
`protected void` `setPort(int port)` Sets the listening port if specified.
`void` `setTarget(Restlet next)` Deprecated. Use the `setNext(Restlet)` method instead.
`void` `start()` Starts the Restlet.
`void` `stop()` Stops the Restlet.

### Methods inherited from class org.restlet.Connector

`getProtocols, setProtocols`

### Methods inherited from class org.restlet.Restlet

`finalize, getApplication, getAuthor, getContext, getDescription, getLogger, getName, getOwner, isStarted, isStopped, setAuthor, setContext, setDescription, setName, setOwner`

### Methods inherited from class java.lang.Object

`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### Server

    public Server(Context context,
          java.util.List<Protocol> protocols,
          int port,
          Restlet next)

Constructor.

Parameters:
  `context` - The context.
  `protocols` - The connector protocols.
  `port` - The listening port.
  `next` - The next Restlet.

#### Server

    public Server(Context context,
          java.util.List<Protocol> protocols,
          java.lang.String address,
          int port,
          Restlet next)

Constructor.

Parameters:
  `context` - The context.
  `protocols` - The connector protocols.
  `address` - The optional listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.
  `port` - The listening port.
  `next` - The next Restlet.

#### Server

    public Server(Context context,
          java.util.List<Protocol> protocols,
          java.lang.String address,
          int port,
          Restlet next,
          java.lang.String helperClass)

Constructor.

Parameters:
  `context` - The context.
  `protocols` - The connector protocols.
  `address` - The optional listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.
  `port` - The listening port.
  `next` - The next Restlet.
  `helperClass` - Optional helper class name.

#### Server

    public Server(Context context,
          Protocol protocol,
          java.lang.Class<?> nextClass)

Constructor.

Parameters:
  `context` - The context.
  `protocol` - The connector protocol.
  `nextClass` - The next server resource.

#### Server

    public Server(Context context,
          Protocol protocol,
          int port)

Constructor.

Parameters:
  `context` - The parent context.
  `protocol` - The connector protocol.
  `port` - The listening port.

#### Server

    public Server(Context context,
          Protocol protocol,
          int port,
          java.lang.Class<?> nextClass)

Constructor.

Parameters:
  `context` - The context.
  `protocol` - The connector protocol.
  `port` - The listening port.
  `nextClass` - The next server resource.

#### Server

    public Server(Context context,
          Protocol protocol,
          int port,
          Restlet next)

Constructor.

Parameters:
  `context` - The context.
  `protocol` - The connector protocol.
  `port` - The listening port.
  `next` - The next Restlet.

#### Server

    public Server(Context context,
          Protocol protocol,
          Restlet next)

Constructor using the protocol's default port.

Parameters:
  `context` - The context.
  `protocol` - The connector protocol.
  `next` - The next Restlet.

#### Server

    public Server(Context context,
          Protocol protocol,
          java.lang.String address,
          int port,
          Restlet next)

Constructor.

Parameters:
  `context` - The context.
  `protocol` - The connector protocol.
  `address` - The optional listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.
  `port` - The listening port.
  `next` - The next Restlet.

#### Server

    public Server(java.util.List<Protocol> protocols,
          int port,
          Restlet next)

Constructor.

Parameters:
  `protocols` - The connector protocols.
  `port` - The listening port.
  `next` - The next Restlet.

#### Server

    public Server(java.util.List<Protocol> protocols,
          java.lang.String address,
          int port,
          Restlet next)

Constructor.

Parameters:
  `protocols` - The connector protocols.
  `address` - The optional listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.
  `port` - The listening port.
  `next` - The next Restlet.

#### Server

    public Server(Protocol protocol)

Constructor.

Parameters:
  `protocol` - The connector protocol.

#### Server

    public Server(Protocol protocol,
          java.lang.Class<?> nextClass)

Constructor using the protocol's default port.

Parameters:
  `protocol` - The connector protocol.
  `nextClass` - The next server resource.

#### Server

    public Server(Protocol protocol,
          int port)

Constructor.

Parameters:
  `protocol` - The connector protocol.
  `port` - The listening port.

#### Server

    public Server(Protocol protocol,
          int port,
          java.lang.Class<?> nextClass)

Constructor.

Parameters:
  `protocol` - The connector protocol.
  `port` - The listening port.
  `nextClass` - The next server resource.

#### Server

    public Server(Protocol protocol,
          int port,
          Restlet next)

Constructor.

Parameters:
  `protocol` - The connector protocol.
  `port` - The listening port.
  `next` - The next Restlet.

#### Server

    public Server(Protocol protocol,
          Restlet next)

Constructor using the protocol's default port.

Parameters:
  `protocol` - The connector protocol.
  `next` - The next Restlet.

#### Server

    public Server(Protocol protocol,
          java.lang.String address)

Constructor using the protocol's default port.

Parameters:
  `protocol` - The connector protocol.
  `address` - The listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.

#### Server

    public Server(Protocol protocol,
          java.lang.String address,
          java.lang.Class<?> nextClass)

Constructor using the protocol's default port.

Parameters:
  `protocol` - The connector protocol.
  `address` - The listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.
  `nextClass` - The next server resource.

#### Server

    public Server(Protocol protocol,
          java.lang.String address,
          int port)

Constructor.

Parameters:
  `protocol` - The connector protocol.
  `address` - The optional listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.
  `port` - The listening port.

#### Server

    public Server(Protocol protocol,
          java.lang.String address,
          int port,
          Restlet next)

Constructor.

Parameters:
  `protocol` - The connector protocol.
  `address` - The optional listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.
  `port` - The listening port.
  `next` - The next Restlet.

#### Server

    public Server(Protocol protocol,
          java.lang.String address,
          Restlet next)

Constructor using the protocol's default port.

Parameters:
  `protocol` - The connector protocol.
  `address` - The listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.
  `next` - The next Restlet.

### Method Detail

#### getAddress

    public java.lang.String getAddress()

Returns the optional listening IP address (local host used if null).

Returns:
  The optional listening IP address (local host used if null).

#### getEphemeralPort

    public int getEphemeralPort()

Returns the actual ephemeral port used when the listening port is set to '0'. The default value is '-1' if no ephemeral port is known. See InetSocketAddress#InetSocketAddress(int) and ServerSocket#getLocalPort() methods for details.

Returns:
  The actual ephemeral port used.

#### getNext

    public Restlet getNext()

Returns the next Restlet.

Returns:
  The next Restlet.

#### getPort

    public int getPort()

Returns the listening port if specified.

Returns:
  The listening port if specified.

#### getTarget

    @Deprecated
    public Restlet getTarget()

Deprecated. Use the `getNext()` method instead.
Returns the next Restlet.

Returns:
  The next Restlet.

#### handle

    public void handle(Request request,
              Response response)

Description copied from class: `Restlet`
Handles a call. The default behavior is to initialize the Restlet by setting the current context using the `Context.setCurrent(Context)` method and by attempting to start it, unless it was already started. If an exception is thrown during the start action, then the response status is set to `Status.SERVER_ERROR_INTERNAL`.

Subclasses overriding this method should make sure that they call super.handle(request, response) before adding their own logic.

Specified by:
  `handle` in interface `Uniform`
Overrides:
  `handle` in class `Restlet`
Parameters:
  `request` - The request to handle.
  `response` - The response to update.

#### hasNext

    public boolean hasNext()

Indicates if a next Restlet is set.

Returns:
  True if a next Restlet is set.

#### hasTarget

    @Deprecated
    public boolean hasTarget()

Deprecated. Use the `hasNext()` method instead.
Indicates if a next Restlet is set.

Returns:
  True if a next Restlet is set.

#### isAvailable

    public boolean isAvailable()

Indicates the underlying connector helper is available.

Specified by:
  `isAvailable` in class `Connector`
Returns:
  True if the underlying connector helper is available.

#### setAddress

    public void setAddress(java.lang.String address)

Sets the optional listening IP address (local host used if null).

Parameters:
  `address` - The optional listening IP address (local host used if null).

#### setNext

    public void setNext(java.lang.Class<?> nextClass)

Sets the next Restlet as a Finder for a given resource class. When the call is delegated to the Finder instance, a new instance of the resource class will be created and will actually handle the request.

Parameters:
  `nextClass` - The next resource class to attach.

#### setNext

    public void setNext(Restlet next)

Sets the next Restlet.

Parameters:
  `next` - The next Restlet.

#### setPort

    protected void setPort(int port)

Sets the listening port if specified. Note that '0' means that the system will pick up an ephemeral port at the binding time. This ephemeral can be retrieved once the server is started using the `getEphemeralPort()` method.

Parameters:
  `port` - The listening port if specified.

#### setTarget

    @Deprecated
    public void setTarget(Restlet next)

Deprecated. Use the `setNext(Restlet)` method instead.
Sets the next Restlet.

Parameters:
  `next` - The next Restlet.

#### start

    public void start()
               throws java.lang.Exception

Description copied from class: `Restlet`
Starts the Restlet.

Overrides:
  `start` in class `Restlet`
Throws:
  `java.lang.Exception`

#### stop

    public void stop()
              throws java.lang.Exception

Description copied from class: `Restlet`
Stops the Restlet.

Overrides:
  `stop` in class `Restlet`
Throws:
  `java.lang.Exception`