|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.restlet.Restlet
org.restlet.routing.Router
public class Router
Restlet routing calls to one of the attached routes. Each route can compute
an affinity score for each call depending on various criteria. The attach()
method allow the creation of routes based on URI patterns matching the
beginning of a the resource reference's remaining part.
In addition, several routing modes are supported, implementing various
algorithms:
Field Summary | |
---|---|
static int |
BEST
Deprecated. Use MODE_BEST_MATCH instead. |
static int |
CUSTOM
Deprecated. Use MODE_CUSTOM instead. |
static int |
FIRST
Deprecated. Use MODE_FIRST_MATCH instead. |
static int |
LAST
Deprecated. Use MODE_LAST_MATCH instead. |
static int |
MODE_BEST_MATCH
Each call will be routed to the route with the best score, if the required score is reached. |
static int |
MODE_CUSTOM
Each call will be routed according to a custom mode. |
static int |
MODE_FIRST_MATCH
Each call is routed to the first route if the required score is reached. |
static int |
MODE_LAST_MATCH
Each call will be routed to the last route if the required score is reached. |
static int |
MODE_NEXT_MATCH
Each call is be routed to the next route target if the required score is reached. |
static int |
MODE_RANDOM_MATCH
Each call will be randomly routed to one of the routes that reached the required score. |
static int |
NEXT
Deprecated. Use MODE_NEXT_MATCH instead. |
static int |
RANDOM
Deprecated. Use MODE_RANDOM_MATCH instead. |
Constructor Summary | |
---|---|
Router()
Constructor. |
|
Router(Context context)
Constructor. |
Method Summary | |
---|---|
Route |
attach(Restlet target)
Attaches a target Restlet to this router with an empty URI pattern. |
Route |
attach(Restlet target,
int matchingMode)
Attaches a target Restlet to this router with an empty URI pattern. |
Route |
attach(String pathTemplate,
Class<?> targetClass)
Attaches a target Resource class to this router based on a given URI pattern. |
Route |
attach(String pathTemplate,
Class<?> targetClass,
int matchingMode)
Attaches a target Resource class to this router based on a given URI pattern. |
Route |
attach(String pathTemplate,
Restlet target)
Attaches a target Restlet to this router based on a given URI pattern. |
Route |
attach(String pathTemplate,
Restlet target,
int matchingMode)
Attaches a target Restlet to this router based on a given URI pattern. |
Route |
attachDefault(Class<?> defaultTargetClass)
Attaches a Resource class to this router as the default target to invoke when no route matches. |
Route |
attachDefault(Restlet defaultTarget)
Attaches a Restlet to this router as the default target to invoke when no route matches. |
Finder |
createFinder(Class<?> targetClass)
Creates a new finder instance based on the "targetClass" property. |
protected Route |
createRoute(String uriPattern,
Restlet target)
Creates a new route for the given URI pattern and target. |
protected Route |
createRoute(String uriPattern,
Restlet target,
int matchingMode)
Creates a new route for the given URI pattern, target and matching mode. |
void |
detach(Class<?> targetClass)
Detaches the target from this router. |
void |
detach(Restlet target)
Detaches the target from this router. |
protected void |
doHandle(Restlet next,
Request request,
Response response)
Effectively handles the call using the selected next Restlet ,
typically the selected Route . |
protected Route |
getCustom(Request request,
Response response)
Returns the matched route according to a custom algorithm. |
int |
getDefaultMatchingMode()
Returns the default matching mode to use when selecting routes based on URIs. |
boolean |
getDefaultMatchingQuery()
Returns the default setting for whether the routing should be done on URIs with or without taking into account query string. |
boolean |
getDefaultMatchQuery()
Deprecated. Use getDefaultMatchingQuery() instead. |
Route |
getDefaultRoute()
Returns the default route to test if no other one was available after retrying the maximum number of attempts. |
Class<? extends Finder> |
getFinderClass()
Returns the finder class to instantiate. |
protected int |
getMatchingMode(Restlet target)
Returns the matching mode for the target Restlet. |
int |
getMaxAttempts()
Returns the maximum number of attempts if no attachment could be matched on the first attempt. |
Restlet |
getNext(Request request,
Response response)
Returns the next Restlet if available. |
float |
getRequiredScore()
Returns the minimum score required to have a match. |
long |
getRetryDelay()
Returns the delay in milliseconds before a new attempt is made. |
RouteList |
getRoutes()
Returns the modifiable list of routes. |
int |
getRoutingMode()
Returns the routing mode. |
void |
handle(Request request,
Response response)
Handles a call by invoking the next Restlet if it is available. |
protected void |
logRoute(Route route)
Logs the route selected. |
void |
setDefaultMatchingMode(int defaultMatchingMode)
Sets the default matching mode to use when selecting routes based on URIs. |
void |
setDefaultMatchingQuery(boolean defaultMatchingQuery)
Sets the default setting for whether the routing should be done on URIs with or without taking into account query string. |
void |
setDefaultMatchQuery(boolean defaultMatchingQuery)
Deprecated. Use setDefaultMatchingQuery(boolean) instead. |
void |
setDefaultRoute(Route defaultRoute)
Sets the default route tested if no other one was available. |
void |
setFinderClass(Class<? extends Finder> finderClass)
Sets the finder class to instantiate. |
void |
setMaxAttempts(int maxAttempts)
Sets the maximum number of attempts if no attachment could be matched on the first attempt. |
void |
setRequiredScore(float score)
Sets the score required to have a match. |
void |
setRetryDelay(long retryDelay)
Sets the delay in milliseconds before a new attempt is made. |
void |
setRoutes(RouteList routes)
Sets the modifiable list of routes. |
void |
setRoutingMode(int routingMode)
Sets the routing mode. |
void |
start()
Starts the filter and the attached routes. |
void |
stop()
Stops the filter and the attached routes. |
Methods inherited from class org.restlet.Restlet |
---|
finalize, getApplication, getAuthor, getContext, getDescription, getLogger, getName, getOwner, isStarted, isStopped, setAuthor, setContext, setDescription, setName, setOwner |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@Deprecated public static final int BEST
MODE_BEST_MATCH
instead.
@Deprecated public static final int CUSTOM
MODE_CUSTOM
instead.
@Deprecated public static final int FIRST
MODE_FIRST_MATCH
instead.
@Deprecated public static final int LAST
MODE_LAST_MATCH
instead.
public static final int MODE_BEST_MATCH
public static final int MODE_CUSTOM
public static final int MODE_FIRST_MATCH
public static final int MODE_LAST_MATCH
public static final int MODE_NEXT_MATCH
public static final int MODE_RANDOM_MATCH
@Deprecated public static final int NEXT
MODE_NEXT_MATCH
instead.
@Deprecated public static final int RANDOM
MODE_RANDOM_MATCH
instead.
Constructor Detail |
---|
public Router()
public Router(Context context)
context
- The context.Method Detail |
---|
public Route attach(Restlet target)
getMatchingMode(Restlet)
will be added routing to the target
when any call is received.
target
- The target Restlet to attach.
public Route attach(Restlet target, int matchingMode)
target
- The target Restlet to attach.matchingMode
- The matching mode.
public Route attach(String pathTemplate, Class<?> targetClass)
getMatchingMode(Restlet)
will be added routing to the target
when calls with a URI matching the pattern will be received.
pathTemplate
- The URI path template that must match the relative part of the
resource URI.targetClass
- The target Resource class to attach.
public Route attach(String pathTemplate, Class<?> targetClass, int matchingMode)
pathTemplate
- The URI path template that must match the relative part of the
resource URI.targetClass
- The target Resource class to attach.matchingMode
- The matching mode.
public Route attach(String pathTemplate, Restlet target)
getMatchingMode(Restlet)
will be added routing to the target
when calls with a URI matching the pattern will be received.
pathTemplate
- The URI path template that must match the relative part of the
resource URI.target
- The target Restlet to attach.
public Route attach(String pathTemplate, Restlet target, int matchingMode)
pathTemplate
- The URI path template that must match the relative part of the
resource URI.target
- The target Restlet to attach.matchingMode
- The matching mode.
public Route attachDefault(Class<?> defaultTargetClass)
defaultTargetClass
- The target Resource class to attach.
public Route attachDefault(Restlet defaultTarget)
defaultTarget
- The Restlet to use as the default target.
public Finder createFinder(Class<?> targetClass)
targetClass
- The target Resource class to attach.
protected Route createRoute(String uriPattern, Restlet target)
getDefaultMatchingQuery()
and the matching mode will be given by
getMatchingMode(Restlet)
.
uriPattern
- The URI pattern that must match the relative part of the
resource URI.target
- The target Restlet to attach.
protected Route createRoute(String uriPattern, Restlet target, int matchingMode)
getDefaultMatchingQuery()
.
uriPattern
- The URI pattern that must match the relative part of the
resource URI.target
- The target Restlet to attach.matchingMode
- The matching mode.
public void detach(Class<?> targetClass)
targetClass
- The target class to detach.public void detach(Restlet target)
target
- The target Restlet to detach.protected void doHandle(Restlet next, Request request, Response response)
Restlet
,
typically the selected Route
. By default, it just invokes the
next Restlet.
next
- The next Restlet to invoke.request
- The request.response
- The response.protected Route getCustom(Request request, Response response)
MODE_CUSTOM
option. The default
implementation (to be overridden), returns null.
request
- The request to handle.response
- The response to update.
public int getDefaultMatchingMode()
Template.MODE_EQUALS
.
public boolean getDefaultMatchingQuery()
@Deprecated public boolean getDefaultMatchQuery()
getDefaultMatchingQuery()
instead.
public Route getDefaultRoute()
public Class<? extends Finder> getFinderClass()
protected int getMatchingMode(Restlet target)
getDefaultMatchingMode()
. If the target is an instance of
Directory
or Router
then the mode returned is
Template.MODE_STARTS_WITH
to allow further routing by those
objects. If the target is an instance of Filter
, then it returns
the matching mode for the Filter.getNext()
Restlet recursively.
target
- The target Restlet.
public int getMaxAttempts()
public Restlet getNext(Request request, Response response)
request
- The request to handle.response
- The response to update.
public float getRequiredScore()
0.5
.
public long getRetryDelay()
500
.
public RouteList getRoutes()
public int getRoutingMode()
MODE_FIRST_MATCH
mode.
public void handle(Request request, Response response)
handle
in interface Uniform
handle
in class Restlet
request
- The request to handle.response
- The response to update.protected void logRoute(Route route)
route
- The route selected.public void setDefaultMatchingMode(int defaultMatchingMode)
Template.MODE_EQUALS
.
defaultMatchingMode
- The default matching mode.public void setDefaultMatchingQuery(boolean defaultMatchingQuery)
defaultMatchingQuery
- The default setting for whether the routing should be done on
URIs with or without taking into account query string.@Deprecated public void setDefaultMatchQuery(boolean defaultMatchingQuery)
setDefaultMatchingQuery(boolean)
instead.
defaultMatchingQuery
- The default setting for whether the routing should be done on
URIs with or without taking into account query string.public void setDefaultRoute(Route defaultRoute)
defaultRoute
- The default route tested if no other one was available.public void setFinderClass(Class<? extends Finder> finderClass)
finderClass
- The finder class to instantiate.public void setMaxAttempts(int maxAttempts)
maxAttempts
- The maximum number of attempts.public void setRequiredScore(float score)
0.5
.
score
- The score required to have a match.public void setRetryDelay(long retryDelay)
500
.
retryDelay
- The delay in milliseconds before a new attempt is made.public void setRoutes(RouteList routes)
routes
- The modifiable list of routes.public void setRoutingMode(int routingMode)
MODE_FIRST_MATCH
mode.
routingMode
- The routing mode.public void start() throws Exception
start
in class Restlet
Exception
public void stop() throws Exception
stop
in class Restlet
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |