org.restlet
Class Server

java.lang.Object
  extended by org.restlet.Uniform
      extended by org.restlet.Restlet
          extended by org.restlet.Connector
              extended by org.restlet.Server

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
Server(Context context, java.util.List<Protocol> protocols, int port, Restlet target)
          Constructor.
Server(Context context, java.util.List<Protocol> protocols, java.lang.String address, int port, Restlet target)
          Constructor.
Server(Context context, java.util.List<Protocol> protocols, java.lang.String address, int port, Restlet target, java.lang.String helperClass)
          Constructor.
Server(Context context, Protocol protocol, int port, Restlet target)
          Constructor.
Server(Context context, Protocol protocol, Restlet target)
          Constructor using the protocol's default port.
Server(Context context, Protocol protocol, java.lang.String address, int port, Restlet target)
          Constructor.
Server(java.util.List<Protocol> protocols, int port, Restlet target)
          Constructor.
Server(java.util.List<Protocol> protocols, java.lang.String address, int port, Restlet target)
          Constructor.
Server(Protocol protocol, int port, Restlet target)
          Constructor.
Server(Protocol protocol, Restlet target)
          Constructor using the protocol's default port.
Server(Protocol protocol, java.lang.String address, int port, Restlet target)
          Constructor.
Server(Protocol protocol, java.lang.String address, Restlet target)
          Constructor using the protocol's default port.
 
Method Summary
 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'.
 int getPort()
          Returns the listening port if specified.
 Restlet getTarget()
          Returns the target Restlet.
 void handle(Request request, Response response)
          Handles a call.
 boolean hasTarget()
          Indicates if a target Restlet is set.
protected  void setAddress(java.lang.String address)
          Sets the optional listening IP address (local host used if null).
protected  void setPort(int port)
          Sets the listening port if specified.
 void setTarget(Restlet target)
          Sets the target Restlet.
 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
getApplication, getContext, getLogger, init, isStarted, isStopped, setContext
 
Methods inherited from class org.restlet.Uniform
delete, delete, get, get, handle, head, head, options, options, post, post, put, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Server

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

Parameters:
context - The context.
protocols - The connector protocols.
port - The listening port.
target - The target Restlet.

Server

public Server(Context context,
              java.util.List<Protocol> protocols,
              java.lang.String address,
              int port,
              Restlet target)
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.
target - The target Restlet.

Server

public Server(Context context,
              java.util.List<Protocol> protocols,
              java.lang.String address,
              int port,
              Restlet target,
              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.
target - The target Restlet.
helperClass - Optional helper class name.

Server

public Server(Context context,
              Protocol protocol,
              int port,
              Restlet target)
Constructor.

Parameters:
context - The context.
protocol - The connector protocol.
port - The listening port.
target - The target Restlet.

Server

public Server(Context context,
              Protocol protocol,
              Restlet target)
Constructor using the protocol's default port.

Parameters:
context - The context.
protocol - The connector protocol.
target - The target Restlet.

Server

public Server(Context context,
              Protocol protocol,
              java.lang.String address,
              int port,
              Restlet target)
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.
target - The target Restlet.

Server

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

Parameters:
protocols - The connector protocols.
port - The listening port.
target - The target Restlet.

Server

public Server(java.util.List<Protocol> protocols,
              java.lang.String address,
              int port,
              Restlet target)
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.
target - The target Restlet.

Server

public Server(Protocol protocol,
              int port,
              Restlet target)
Constructor.

Parameters:
protocol - The connector protocol.
port - The listening port.
target - The target Restlet.

Server

public Server(Protocol protocol,
              Restlet target)
Constructor using the protocol's default port.

Parameters:
protocol - The connector protocol.
target - The target Restlet.

Server

public Server(Protocol protocol,
              java.lang.String address,
              int port,
              Restlet target)
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.
target - The target Restlet.

Server

public Server(Protocol protocol,
              java.lang.String address,
              Restlet target)
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.
target - The target 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.

Returns:
The actual ephemeral port used.
See Also:
InetSocketAddress.InetSocketAddress(int), ServerSocket.getLocalPort()

getPort

public int getPort()
Returns the listening port if specified.

Returns:
The listening port if specified.

getTarget

public Restlet getTarget()
Returns the target Restlet.

Returns:
The target Restlet.

handle

public void handle(Request request,
                   Response response)
Description copied from class: Restlet
Handles a call. The default behavior is to call the (now deprecated) Restlet.init(Request, Response) method. In next version, Restlet.init(Request, Response) will be removed and its logic directly added to this method instead.

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

Overrides:
handle in class Restlet
Parameters:
request - The request to handle.
response - The response to update.

hasTarget

public boolean hasTarget()
Indicates if a target Restlet is set.

Returns:
True if a target Restlet is set.

setAddress

protected 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).

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

public void setTarget(Restlet target)
Sets the target Restlet.

Parameters:
target - The target 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


Copyright © 2005-2008 Noelios Technologies.