| |
|
| java.lang.Object org.restlet.Uniform org.restlet.Restlet org.restlet.Router
All known Subclasses: com.noelios.restlet.component.ClientRouter, com.noelios.restlet.component.ServerRouter, org.restlet.VirtualHost,
Router | public class Router extends Restlet (Code) | | 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:
- Best match (default)
- First match
- Last match
- Random match
- Round robin
- Custom
Note that for routes using URI patterns will update the resource reference's
base reference during the routing if they are selected. It is also important
to know that the routing is very strict about path separators in your URI
patterns. Finally, you can modify the list of routes while handling incoming
calls as the delegation code is ensured to be thread-safe.
See Also: Tutorial: Routers and
* hierarchical URIs author: Jerome Louvel (contact@noelios.com) |
Field Summary | |
final public static int | BEST Each call will be routed to the route with the best score, if the
required score is reached. | final public static int | CUSTOM Each call will be routed according to a custom mode. | final public static int | FIRST Each call is routed to the first route if the required score is reached. | final public static int | LAST Each call will be routed to the last route if the required score is
reached. | final public static int | NEXT Each call is be routed to the next route target if the required score is
reached. | final public static int | RANDOM Each call will be randomly routed to one of the routes that reached the
required score. |
Method Summary | |
public Route | attach(Restlet target) Attaches a target Restlet to this router with an empty URI pattern. | public Route | attach(String uriPattern, Class<? extends Resource> targetClass) Attaches a target Resource class to this router based on a given URI
pattern. | public Route | attach(String uriPattern, Restlet target) Attaches a target Restlet to this router based on a given URI pattern. | public Route | attachDefault(Class<? extends Resource> defaultTargetClass) Attaches a Resource class to this router as the default target to invoke
when no route matches. | public Route | attachDefault(Restlet defaultTarget) Attaches a Restlet to this router as the default target to invoke when no
route matches. | protected Route | createRoute(String uriPattern, Restlet target) Creates a new route for the given URI pattern and target.
Parameters: uriPattern - The URI pattern that must match the relative part of theresource URI. Parameters: target - The target Restlet to attach. | public void | detach(Restlet target) Detaches the target from this router. | protected Route | getCustom(Request request, Response response) Returns the matched route according to a custom algorithm. | public Route | getDefaultRoute() Returns the default route to test if no other one was available after
retrying the maximum number of attemps. | public Class<? extends Finder> | getFinderClass() Returns the finder class to instantiate. | public int | getMaxAttempts() Returns the maximum number of attempts if no attachment could be matched
on the first attempt. | public Restlet | getNext(Request request, Response response) Returns the next Restlet if available.
Parameters: request - The request to handle. Parameters: response - The response to update. | public float | getRequiredScore() Returns the minimum score required to have a match. | public long | getRetryDelay() Returns the delay (in seconds) before a new attempt. | public RouteList | getRoutes() Returns the modifiable list of routes. | public int | getRoutingMode() Returns the routing mode. | public void | handle(Request request, Response response) Handles a call by invoking the next Restlet if it is available. | public void | setDefaultRoute(Route defaultRoute) Sets the default route tested if no other one was available. | public void | setFinderClass(Class<? extends Finder> finderClass) Sets the finder class to instantiate. | public void | setMaxAttempts(int maxAttempts) Sets the maximum number of attempts if no attachment could be matched on
the first attempt. | public void | setRequiredScore(float score) Sets the score required to have a match. | public void | setRetryDelay(long retryDelay) Sets the delay (in seconds) before a new attempt. | public void | setRoutingMode(int routingMode) Sets the routing mode. |
BEST | final public static int BEST(Code) | | Each call will be routed to the route with the best score, if the
required score is reached.
|
CUSTOM | final public static int CUSTOM(Code) | | Each call will be routed according to a custom mode.
|
FIRST | final public static int FIRST(Code) | | Each call is routed to the first route if the required score is reached.
If the required score is not reached, then the route is skipped and the
next one is considered.
|
LAST | final public static int LAST(Code) | | Each call will be routed to the last route if the required score is
reached. If the required score is not reached, then the route is skipped
and the previous one is considered.
|
NEXT | final public static int NEXT(Code) | | Each call is be routed to the next route target if the required score is
reached. The next route is relative to the previous call routed (round
robin mode). If the required score is not reached, then the route is
skipped and the next one is considered. If the last route is reached, the
first route will be considered.
|
RANDOM | final public static int RANDOM(Code) | | Each call will be randomly routed to one of the routes that reached the
required score. If the random route selected is not a match then the
immediate next route is evaluated until one matching route is found. If
we get back to the inital random route selected with no match, then we
return null.
|
Router | public Router()(Code) | | Constructor. Note that usage of this constructor is not recommended as
the Router won't have a proper context set. In general you will prefer to
use the other constructor and pass it the parent application's context or
eventually the parent component's context if you don't use applications.
|
Router | public Router(Context context)(Code) | | Constructor.
Parameters: context - The context. |
attach | public Route attach(Restlet target)(Code) | | Attaches a target Restlet to this router with an empty URI pattern. A new
route will be added routing to the target when any call is received.
Parameters: target - The target Restlet to attach. The created route. |
attach | public Route attach(String uriPattern, Class<? extends Resource> targetClass)(Code) | | Attaches a target Resource class to this router based on a given URI
pattern. A new route will be added routing to the target when calls with
a URI matching the pattern will be received.
Parameters: uriPattern - The URI pattern that must match the relative part of theresource URI. Parameters: targetClass - The target Resource class to attach. The created route. |
attach | public Route attach(String uriPattern, Restlet target)(Code) | | Attaches a target Restlet to this router based on a given URI pattern. A
new route will be added routing to the target when calls with a URI
matching the pattern will be received.
Parameters: uriPattern - The URI pattern that must match the relative part of theresource URI. Parameters: target - The target Restlet to attach. The created route. |
attachDefault | public Route attachDefault(Class<? extends Resource> defaultTargetClass)(Code) | | Attaches a Resource class to this router as the default target to invoke
when no route matches. It actually sets a default route that scores all
calls to 1.0.
Parameters: defaultTargetClass - The target Resource class to attach. The created route. |
attachDefault | public Route attachDefault(Restlet defaultTarget)(Code) | | Attaches a Restlet to this router as the default target to invoke when no
route matches. It actually sets a default route that scores all calls to
1.0.
Parameters: defaultTarget - The Restlet to use as the default target. The created route. |
createRoute | protected Route createRoute(String uriPattern, Restlet target)(Code) | | Creates a new route for the given URI pattern and target.
Parameters: uriPattern - The URI pattern that must match the relative part of theresource URI. Parameters: target - The target Restlet to attach. The created route. |
detach | public void detach(Restlet target)(Code) | | Detaches the target from this router. All routes routing to this target
Restlet are removed from the list of routes and the default route is set
to null.
Parameters: target - The target Restlet to detach. |
getCustom | protected Route getCustom(Request request, Response response)(Code) | | Returns the matched route according to a custom algorithm. To use in
combination of the RouterMode.CUSTOM enumeration. The default
implementation (to be overriden), returns null.
Parameters: request - The request to handle. Parameters: response - The response to update. The matched route if available or null. |
getDefaultRoute | public Route getDefaultRoute()(Code) | | Returns the default route to test if no other one was available after
retrying the maximum number of attemps.
The default route tested if no other one was available. |
getFinderClass | public Class<? extends Finder> getFinderClass()(Code) | | Returns the finder class to instantiate.
the finder class to instantiate. |
getMaxAttempts | public int getMaxAttempts()(Code) | | Returns the maximum number of attempts if no attachment could be matched
on the first attempt. This is useful when the attachment scoring is
dynamic and therefore could change on a retry. The default value is set
to 1.
The maximum number of attempts if no attachment could be matchedon the first attempt. |
getNext | public Restlet getNext(Request request, Response response)(Code) | | Returns the next Restlet if available.
Parameters: request - The request to handle. Parameters: response - The response to update. The next Restlet if available or null. |
getRequiredScore | public float getRequiredScore()(Code) | | Returns the minimum score required to have a match.
The minimum score required to have a match. |
getRetryDelay | public long getRetryDelay()(Code) | | Returns the delay (in seconds) before a new attempt. The default value is
500 ms.
The delay (in seconds) before a new attempt. |
getRoutes | public RouteList getRoutes()(Code) | | Returns the modifiable list of routes.
The modifiable list of routes. |
getRoutingMode | public int getRoutingMode()(Code) | | Returns the routing mode.
The routing mode. |
handle | public void handle(Request request, Response response)(Code) | | Handles a call by invoking the next Restlet if it is available.
Parameters: request - The request to handle. Parameters: response - The response to update. |
setDefaultRoute | public void setDefaultRoute(Route defaultRoute)(Code) | | Sets the default route tested if no other one was available.
Parameters: defaultRoute - The default route tested if no other one was available. |
setFinderClass | public void setFinderClass(Class<? extends Finder> finderClass)(Code) | | Sets the finder class to instantiate.
Parameters: finderClass - The finder class to instantiate. |
setMaxAttempts | public void setMaxAttempts(int maxAttempts)(Code) | | Sets the maximum number of attempts if no attachment could be matched on
the first attempt. This is useful when the attachment scoring is dynamic
and therefore could change on a retry.
Parameters: maxAttempts - The maximum number of attempts. |
setRequiredScore | public void setRequiredScore(float score)(Code) | | Sets the score required to have a match.
Parameters: score - The score required to have a match. |
setRetryDelay | public void setRetryDelay(long retryDelay)(Code) | | Sets the delay (in seconds) before a new attempt.
Parameters: retryDelay - The delay (in seconds) before a new attempt. |
setRoutingMode | public void setRoutingMode(int routingMode)(Code) | | Sets the routing mode.
Parameters: routingMode - The routing mode. |
|
|
|