Package org.restlet
Class Restlet
java.lang.Object
org.restlet.Restlet
- All Implemented Interfaces:
Uniform
- Direct Known Subclasses:
Application,Component,Connector,Filter,Finder,Redirector,Router,WrapperRestlet
Uniform class that provides a context and life cycle support. It has many
subclasses that focus on specific ways to process calls. The context property
is typically provided by a parent Component as a way to encapsulate access to
shared features such as logging and client connectors.
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.
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 -
Method Summary
Modifier and TypeMethodDescriptioncreateFinder(Class<? extends ServerResource> resourceClass) Creates a new finder instance based on the "targetClass" property.protected voidfinalize()Attempts tostop()the Restlet if it is still started.Returns the parent application if it exists, or null.Returns the author(s).Returns the context.Returns the description.Returns the finder class used to instantiate resource classes.Returns the context's logger.getName()Returns the display name.getOwner()Returns the owner(s).final ResponseHandles a call.voidHandles a call.final voidHandles a call.final voidHandles a call.booleanIndicates if the Restlet is started.booleanIndicates if the Restlet is stopped.voidSets the author(s).voidsetContext(Context context) Sets the context.voidsetDescription(String description) Sets the description.voidsetFinderClass(Class<? extends Finder> finderClass) Sets the finder class to instantiate.voidSets the display name.voidSets the owner(s).voidstart()Starts the Restlet.voidstop()Stops the Restlet.
-
Constructor Details
-
Restlet
public Restlet()Constructor with null context. -
Restlet
Constructor with the Restlet's context which can be the parent's application context, but shouldn't be the parent Component's context for security reasons.- Parameters:
context- The context of the Restlet.- See Also:
-
-
Method Details
-
createFinder
Creates a new finder instance based on the "targetClass" property. If none is define, thecreateFinder(Class)method is invoked if available, otherwise theFinder.createFinder(Class, Class, Context, Logger)method is called with theFinderclass as parameter.- Parameters:
resourceClass- The targetServerResourceclass to find.- Returns:
- The new finder instance.
- See Also:
-
finalize
Attempts tostop()the Restlet if it is still started. -
getApplication
Returns the parent application if it exists, or null.- Returns:
- The parent application if it exists, or null.
-
getAuthor
Returns the author(s).- Returns:
- The author(s).
-
getContext
Returns the context.- Returns:
- The context.
-
getDescription
Returns the description.- Returns:
- The description
-
getFinderClass
Returns the finder class used to instantiate resource classes. By default, it returns theFinderclass. This property is leveraged byApplication.setOutboundRoot(Class)andApplication.setInboundRoot(Class)methods.- Returns:
- the finder class to instantiate.
-
getLogger
Returns the context's logger.- Returns:
- The context's logger.
-
getName
Returns the display name.- Returns:
- The display name.
-
getOwner
Returns the owner(s).- Returns:
- The owner(s).
-
handle
Handles a call. Creates an emptyResponseobject and then invokeshandle(Request, Response).- Parameters:
request- The request to handle.- Returns:
- The returned response.
-
handle
Handles 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.
-
handle
Handles a call.- Parameters:
request- The request to handle.response- The response to update.onResponseCallback- The callback invoked upon response reception.
-
handle
Handles a call.- Parameters:
request- The request to handle.onReceivedCallback- The callback invoked upon request reception.
-
isStarted
public boolean isStarted()Indicates if the Restlet is started.- Returns:
- True if the Restlet is started.
-
isStopped
public boolean isStopped()Indicates if the Restlet is stopped.- Returns:
- True if the Restlet is stopped.
-
setAuthor
Sets the author(s).- Parameters:
author- The author(s).
-
setContext
Sets the context.- Parameters:
context- The context.
-
setDescription
Sets the description.- Parameters:
description- The description.
-
setFinderClass
Sets the finder class to instantiate. This property is leveraged byApplication.setOutboundRoot(Class)andApplication.setInboundRoot(Class)methods.- Parameters:
finderClass- The finder class to instantiate.
-
setName
Sets the display name.- Parameters:
name- The display name.
-
setOwner
Sets the owner(s).- Parameters:
owner- The owner(s).
-
start
Starts 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.- Throws:
Exception
-
stop
Stops 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.- Throws:
Exception
-