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
public abstract class Restlet extends java.lang.Object implements Uniform
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.- Author:
- Jerome Louvel
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FindercreateFinder(java.lang.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.ApplicationgetApplication()Returns the parent application if it exists, or null.java.lang.StringgetAuthor()Returns the author(s).ContextgetContext()Returns the context.java.lang.StringgetDescription()Returns the description.java.lang.Class<? extends Finder>getFinderClass()Returns the finder class used to instantiate resource classes.java.util.logging.LoggergetLogger()Returns the context's logger.java.lang.StringgetName()Returns the display name.java.lang.StringgetOwner()Returns the owner(s).Responsehandle(Request request)Handles a call.voidhandle(Request request, Response response)Handles a call.voidhandle(Request request, Response response, Uniform onResponseCallback)Handles a call.voidhandle(Request request, Uniform onReceivedCallback)Handles a call.booleanisStarted()Indicates if the Restlet is started.booleanisStopped()Indicates if the Restlet is stopped.voidsetAuthor(java.lang.String author)Sets the author(s).voidsetContext(Context context)Sets the context.voidsetDescription(java.lang.String description)Sets the description.voidsetFinderClass(java.lang.Class<? extends Finder> finderClass)Sets the finder class to instantiate.voidsetName(java.lang.String name)Sets the display name.voidsetOwner(java.lang.String owner)Sets the owner(s).voidstart()Starts the Restlet.voidstop()Stops the Restlet.
-
-
-
Constructor Detail
-
Restlet
public Restlet()
Constructor with null context.
-
Restlet
public Restlet(Context context)
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:
Context.createChildContext()
-
-
Method Detail
-
createFinder
public Finder createFinder(java.lang.Class<? extends ServerResource> resourceClass)
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:
Finder.createFinder(Class, Class, Context, Logger)
-
finalize
protected void finalize() throws java.lang.ThrowableAttempts tostop()the Restlet if it is still started.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
getApplication
public Application getApplication()
Returns the parent application if it exists, or null.- Returns:
- The parent application if it exists, or null.
-
getAuthor
public java.lang.String getAuthor()
Returns the author(s).- Returns:
- The author(s).
-
getContext
public Context getContext()
Returns the context.- Returns:
- The context.
-
getDescription
public java.lang.String getDescription()
Returns the description.- Returns:
- The description
-
getFinderClass
public java.lang.Class<? extends Finder> 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
public java.util.logging.Logger getLogger()
Returns the context's logger.- Returns:
- The context's logger.
-
getName
public java.lang.String getName()
Returns the display name.- Returns:
- The display name.
-
getOwner
public java.lang.String getOwner()
Returns the owner(s).- Returns:
- The owner(s).
-
handle
public final Response handle(Request request)
Handles a call. Creates an emptyResponseobject and then invokeshandle(Request, Response).- Parameters:
request- The request to handle.- Returns:
- The returned response.
-
handle
public void handle(Request request, Response response)
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
public final void handle(Request request, Response response, Uniform onResponseCallback)
Handles a call.- Parameters:
request- The request to handle.response- The response to update.onResponseCallback- The callback invoked upon response reception.
-
handle
public final void handle(Request request, Uniform onReceivedCallback)
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
public void setAuthor(java.lang.String author)
Sets the author(s).- Parameters:
author- The author(s).
-
setContext
public void setContext(Context context)
Sets the context.- Parameters:
context- The context.
-
setDescription
public void setDescription(java.lang.String description)
Sets the description.- Parameters:
description- The description.
-
setFinderClass
public void setFinderClass(java.lang.Class<? extends Finder> finderClass)
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
public void setName(java.lang.String name)
Sets the display name.- Parameters:
name- The display name.
-
setOwner
public void setOwner(java.lang.String owner)
Sets the owner(s).- Parameters:
owner- The owner(s).
-
start
public void start() throws java.lang.ExceptionStarts 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:
java.lang.Exception
-
stop
public void stop() throws java.lang.ExceptionStops 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:
java.lang.Exception
-
-