Package org.restlet
Class Server
java.lang.Object
org.restlet.Restlet
org.restlet.Connector
org.restlet.Server
- All Implemented Interfaces:
Uniform
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.
For advanced cases, it is possible to obtained the wrapped
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.
For advanced cases, it is possible to obtained the wrapped
RestletHelper instance that is used by this client to handle the
calls via the "org.restlet.engine.helper" attribute stored in the
Context object.- Author:
- Jerome Louvel
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.Constructor.Constructor.Constructor.Server(Context context, List<Protocol> protocols, String address, int port, Restlet next, String helperClass) Constructor.Constructor.Constructor.Server(Context context, Protocol protocol, int port, Class<? extends ServerResource> nextClass) Constructor.Constructor.Server(Context context, Protocol protocol, Class<? extends ServerResource> nextClass) Constructor.Constructor.Constructor using the protocol's default port.Constructor.Constructor.Server(Protocol protocol, int port, Class<? extends ServerResource> nextClass) Constructor.Constructor.Server(Protocol protocol, Class<? extends ServerResource> nextClass) Constructor using the protocol's default port.Constructor using the protocol's default port.Constructor.Constructor.Server(Protocol protocol, String address, Class<? extends ServerResource> nextClass) Constructor using the protocol's default port.Constructor using the protocol's default port.Constructor using the protocol's default port. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the actual server port after it has started.Returns the optional listening IP address (local host used if null).intReturns the actual ephemeral port used when the listening port is set to '0'.getNext()Returns the next Restlet.intgetPort()Returns the listening port if specified.voidHandles a call.booleanhasNext()Indicates if a next Restlet is set.booleanIndicates the underlying connector helper is available.voidsetAddress(String address) Sets the optional listening IP address (local host used if null).voidsetNext(Class<? extends ServerResource> nextClass) Sets the next Restlet as a Finder for a given resource class.voidSets the next Restlet.protected voidsetPort(int port) Sets the listening port if specified.voidstart()Starts the Restlet.voidstop()Stops the Restlet.Methods inherited from class org.restlet.Connector
getProtocols, setProtocolsMethods inherited from class org.restlet.Restlet
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner
-
Constructor Details
-
Server
Constructor.- Parameters:
context- The context.protocols- The connector protocols.port- The listening port.next- The next Restlet.
-
Server
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, List<Protocol> protocols, String address, int port, Restlet next, 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
Constructor. Note that it uses the protocol's default port.- Parameters:
context- The parent context.protocol- The connector protocol.
-
Server
Constructor.- Parameters:
context- The context.protocol- The connector protocol.nextClass- The next server resource.
-
Server
Constructor.- Parameters:
context- The parent context.protocol- The connector protocol.port- The listening port.
-
Server
public Server(Context context, Protocol protocol, int port, Class<? extends ServerResource> nextClass) Constructor.- Parameters:
context- The context.protocol- The connector protocol.port- The listening port.nextClass- The next server resource.
-
Server
Constructor.- Parameters:
context- The context.protocol- The connector protocol.port- The listening port.next- The next Restlet.
-
Server
Constructor using the protocol's default port.- Parameters:
context- The context.protocol- The connector protocol.next- The next Restlet.
-
Server
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
Constructor.- Parameters:
protocols- The connector protocols.port- The listening port.next- The next Restlet.
-
Server
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
Constructor.- Parameters:
protocol- The connector protocol.
-
Server
Constructor using the protocol's default port.- Parameters:
protocol- The connector protocol.nextClass- The next server resource.
-
Server
Constructor.- Parameters:
protocol- The connector protocol.port- The listening port.
-
Server
Constructor.- Parameters:
protocol- The connector protocol.port- The listening port.nextClass- The next server resource.
-
Server
Constructor.- Parameters:
protocol- The connector protocol.port- The listening port.next- The next Restlet.
-
Server
Constructor using the protocol's default port.- Parameters:
protocol- The connector protocol.next- The next Restlet.
-
Server
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
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
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
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
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 Details
-
getActualPort
public int getActualPort()Returns the actual server port after it has started. If an ephemeral port is used it will be returned, otherwise the fixed port will be provided.- Returns:
- The actual server port.
-
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
Returns the next Restlet.- Returns:
- The next Restlet.
-
getPort
public int getPort()Returns the listening port if specified.- Returns:
- The listening port if specified.
-
handle
Description copied from class:RestletHandles a call. The default behavior is to initialize the Restlet by setting the current context using theContext.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 toStatus.SERVER_ERROR_INTERNAL.Subclasses overriding this method should make sure that they call super.handle(request, response) before adding their own logic.
-
hasNext
public boolean hasNext()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:
isAvailablein classConnector- Returns:
- True if the underlying connector helper is available.
-
setAddress
Sets the optional listening IP address (local host used if null).- Parameters:
address- The optional listening IP address (local host used if null).
-
setNext
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
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 thegetEphemeralPort()method.- Parameters:
port- The listening port if specified.
-
start
Description copied from class:RestletStarts the Restlet. By default its only sets "started" internal property to true. WARNING: this method must be called at the end of the starting process by subclasses otherwise concurrent threads could enter into the call handling logic too early. -
stop
Description copied from class:RestletStops the Restlet. By default its only sets "started" internal property to false. WARNING: this method must be called at the beginning of the stopping process by subclasses otherwise concurrent threads could continue to (improperly) handle calls.
-