org.restlet
Class Application

java.lang.Object
  extended by org.restlet.Restlet
      extended by org.restlet.Application
All Implemented Interfaces:
Uniform

public class Application
extends Restlet

Restlet managing a coherent set of resources and services. Applications are guaranteed to receive calls with their base reference set relatively to the VirtualHost that served them. This class is both a descriptor able to create the root Restlet and the actual Restlet that can be attached to one or more VirtualHost instances.

Applications also have many useful services associated. They are all enabled by default and are available as properties that can be eventually overridden:

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
Application()
          Constructor.
Application(Context context)
          Constructor.
 
Method Summary
 Restlet createInboundRoot()
          Creates a inbound root Restlet that will receive all incoming calls.
 Restlet createOutboundRoot()
          Creates a outbound root Restlet that will receive all outgoing calls from ClientResource.
 ConnectorService getConnectorService()
          Returns the connector service.
 ConnegService getConnegService()
          Returns the content negotiation service.
 ConverterService getConverterService()
          Returns the converter service.
static Application getCurrent()
          This variable is stored internally as a thread local variable and updated each time a call enters an application.
 DecoderService getDecoderService()
          Returns the decoder service.
 EncoderService getEncoderService()
          Returns the encoder service.
 Restlet getInboundRoot()
          Returns the inbound root Restlet.
 MetadataService getMetadataService()
          Returns the metadata service.
 Restlet getOutboundRoot()
          Returns the outbound root Restlet.
 RangeService getRangeService()
          Returns the range service.
 Role getRole(String name)
          Returns the role associated to the given name.
 List<Role> getRoles()
          Returns the modifiable list of roles.
 ServiceList getServices()
          Returns the modifiable list of services.
 StatusService getStatusService()
          Returns the status service.
 TaskService getTaskService()
          Returns a task service to run concurrent tasks.
 TunnelService getTunnelService()
          Returns the tunnel service.
 void handle(Request request, Response response)
          Handles a call.
 void setClientRoot(Class<? extends ServerResource> clientRootClass)
          Deprecated. Use setOutboundRoot(Class) instead
 void setConnectorService(ConnectorService connectorService)
          Sets the connector service.
 void setConnegService(ConnegService connegService)
          Sets the content negotiation service.
 void setContext(Context context)
          Sets the context.
 void setConverterService(ConverterService converterService)
          Sets the converter service.
static void setCurrent(Application application)
          Sets the context to associated with the current thread.
 void setDecoderService(DecoderService decoderService)
          Sets the decoder service.
 void setEncoderService(EncoderService encoderService)
          Sets the encoder service.
 void setInboundRoot(Class<? extends ServerResource> inboundRootClass)
          Sets the inbound root Resource class.
 void setInboundRoot(Restlet inboundRoot)
          Sets the inbound root Restlet.
 void setMetadataService(MetadataService metadataService)
          Sets the metadata service.
 void setOutboundRoot(Class<? extends ServerResource> outboundRootClass)
          Sets the outbound root Resource class.
 void setOutboundRoot(Restlet outboundRoot)
          Sets the outbound root Restlet.
 void setRangeService(RangeService rangeService)
          Sets the range service.
 void setRoles(List<Role> roles)
          Sets the modifiable list of roles.
 void setStatusService(StatusService statusService)
          Sets the status service.
 void setTaskService(TaskService taskService)
          Sets the task service.
 void setTunnelService(TunnelService tunnelService)
          Sets the tunnel service.
 void start()
          Starts the application, all the enabled associated services then the inbound and outbound roots.
 void stop()
          Stops the application, the inbound and outbound roots then all the enabled associated services.
 
Methods inherited from class org.restlet.Restlet
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setDescription, setFinderClass, setName, setOwner
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Application

public Application()
Constructor. Note this constructor is convenient because you don't have to provide a context like for Application(Context). Therefore the context will initially be null. It's only when you attach the application to a virtual host via one of its attach*() methods that a proper context will be set.


Application

public Application(Context context)
Constructor.

Parameters:
context - The context to use based on parent component context. This context should be created using the Context.createChildContext() method to ensure a proper isolation with the other applications.
Method Detail

getCurrent

public static Application getCurrent()
This variable is stored internally as a thread local variable and updated each time a call enters an application. Warning: this method should only be used under duress. You should by default prefer obtaining the current application using methods such as Resource.getApplication()

Returns:
The current context.

setCurrent

public static void setCurrent(Application application)
Sets the context to associated with the current thread.

Parameters:
application - The thread's context.

createInboundRoot

public Restlet createInboundRoot()
Creates a inbound root Restlet that will receive all incoming calls. In general, instances of Router, Filter or Finder classes will be used as initial application Restlet. The default implementation returns null by default. This method is intended to be overridden by subclasses.

Returns:
The inbound root Restlet.

createOutboundRoot

public Restlet createOutboundRoot()
Creates a outbound root Restlet that will receive all outgoing calls from ClientResource. In general, instances of Router and Filter classes will be used. The default implementation returns a Restlet giving access to the the outbound service layer and finally to the Context.getClientDispatcher().

This method is intended to be overridden by subclasses but in order to benefit from the outbound service filtering layer, the original outbound root must be careful attached again at the end of the user filtering layer.

Returns:
The outbound root Restlet.

getConnectorService

public ConnectorService getConnectorService()
Returns the connector service. The service is enabled by default.

Returns:
The connector service.

getConnegService

public ConnegService getConnegService()
Returns the content negotiation service. The service is enabled by default.

Returns:
The content negotiation service.

getConverterService

public ConverterService getConverterService()
Returns the converter service. The service is enabled by default.

Returns:
The converter service.

getDecoderService

public DecoderService getDecoderService()
Returns the decoder service. The service is enabled by default.

Returns:
The decoder service.

getEncoderService

public EncoderService getEncoderService()
Returns the encoder service. The service is disabled by default.

Returns:
The encoder service.

getInboundRoot

public Restlet getInboundRoot()
Returns the inbound root Restlet.

Returns:
The inbound root Restlet.

getMetadataService

public MetadataService getMetadataService()
Returns the metadata service. The service is enabled by default.

Returns:
The metadata service.

getOutboundRoot

public Restlet getOutboundRoot()
Returns the outbound root Restlet.

Returns:
The outbound root Restlet.

getRangeService

public RangeService getRangeService()
Returns the range service.

Returns:
The range service.

getRole

public Role getRole(String name)
Returns the role associated to the given name.

Parameters:
name - The name of the role to find.
Returns:
The role matched or null.

getRoles

public List<Role> getRoles()
Returns the modifiable list of roles.

Returns:
The modifiable list of roles.

getServices

public ServiceList getServices()
Returns the modifiable list of services.

Returns:
The modifiable list of services.

getStatusService

public StatusService getStatusService()
Returns the status service. The service is enabled by default.

Returns:
The status service.

getTaskService

public TaskService getTaskService()
Returns a task service to run concurrent tasks. The service is enabled by default.

Returns:
A task service.

getTunnelService

public TunnelService getTunnelService()
Returns the tunnel service. The service is enabled by default.

Returns:
The tunnel service.

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.

setClientRoot

@Deprecated
public void setClientRoot(Class<? extends ServerResource> clientRootClass)
Deprecated. Use setOutboundRoot(Class) instead

Sets the client root Resource class.

Parameters:
clientRootClass - The client root ServerResource subclass.

setConnectorService

public void setConnectorService(ConnectorService connectorService)
Sets the connector service.

Parameters:
connectorService - The connector service.

setConnegService

public void setConnegService(ConnegService connegService)
Sets the content negotiation service.

Parameters:
connegService - The content negotiation service.

setContext

public void setContext(Context context)
Description copied from class: Restlet
Sets the context.

Overrides:
setContext in class Restlet
Parameters:
context - The context.

setConverterService

public void setConverterService(ConverterService converterService)
Sets the converter service.

Parameters:
converterService - The converter service.

setDecoderService

public void setDecoderService(DecoderService decoderService)
Sets the decoder service.

Parameters:
decoderService - The decoder service.

setEncoderService

public void setEncoderService(EncoderService encoderService)
Sets the encoder service.

Parameters:
encoderService - The encoder service.

setInboundRoot

public void setInboundRoot(Class<? extends ServerResource> inboundRootClass)
Sets the inbound root Resource class.

Parameters:
inboundRootClass - The inbound root Resource class.

setInboundRoot

public void setInboundRoot(Restlet inboundRoot)
Sets the inbound root Restlet.

Parameters:
inboundRoot - The inbound root Restlet.

setMetadataService

public void setMetadataService(MetadataService metadataService)
Sets the metadata service.

Parameters:
metadataService - The metadata service.

setOutboundRoot

public void setOutboundRoot(Class<? extends ServerResource> outboundRootClass)
Sets the outbound root Resource class.

Parameters:
outboundRootClass - The client root ServerResource subclass.

setOutboundRoot

public void setOutboundRoot(Restlet outboundRoot)
Sets the outbound root Restlet.

Parameters:
outboundRoot - The outbound root Restlet.

setRangeService

public void setRangeService(RangeService rangeService)
Sets the range service.

Parameters:
rangeService - The range service.

setRoles

public void setRoles(List<Role> roles)
Sets the modifiable list of roles. This method clears the current list and adds all entries in the parameter list.

Parameters:
roles - A list of roles.

setStatusService

public void setStatusService(StatusService statusService)
Sets the status service.

Parameters:
statusService - The status service.

setTaskService

public void setTaskService(TaskService taskService)
Sets the task service.

Parameters:
taskService - The task service.

setTunnelService

public void setTunnelService(TunnelService tunnelService)
Sets the tunnel service.

Parameters:
tunnelService - The tunnel service.

start

public void start()
           throws Exception
Starts the application, all the enabled associated services then the inbound and outbound roots.

Overrides:
start in class Restlet
Throws:
Exception

stop

public void stop()
          throws Exception
Stops the application, the inbound and outbound roots then all the enabled associated services. Finally, it clears the internal cache of annotations.

Overrides:
stop in class Restlet
Throws:
Exception


Copyright © 2005-2013 Restlet.