Java Doc for Router.java in  » Web-Services » restlet-1.0.8 » org » restlet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services » restlet 1.0.8 » org.restlet 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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  intBEST
     Each call will be routed to the route with the best score, if the required score is reached.
final public static  intCUSTOM
     Each call will be routed according to a custom mode.
final public static  intFIRST
     Each call is routed to the first route if the required score is reached.
final public static  intLAST
     Each call will be routed to the last route if the required score is reached.
final public static  intNEXT
     Each call is be routed to the next route target if the required score is reached.
final public static  intRANDOM
     Each call will be randomly routed to one of the routes that reached the required score.

Constructor Summary
public  Router()
     Constructor.
public  Router(Context context)
     Constructor.

Method Summary
public  Routeattach(Restlet target)
     Attaches a target Restlet to this router with an empty URI pattern.
public  Routeattach(String uriPattern, Class<? extends Resource> targetClass)
     Attaches a target Resource class to this router based on a given URI pattern.
public  Routeattach(String uriPattern, Restlet target)
     Attaches a target Restlet to this router based on a given URI pattern.
public  RouteattachDefault(Class<? extends Resource> defaultTargetClass)
     Attaches a Resource class to this router as the default target to invoke when no route matches.
public  RouteattachDefault(Restlet defaultTarget)
     Attaches a Restlet to this router as the default target to invoke when no route matches.
protected  RoutecreateRoute(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  voiddetach(Restlet target)
     Detaches the target from this router.
protected  RoutegetCustom(Request request, Response response)
     Returns the matched route according to a custom algorithm.
public  RoutegetDefaultRoute()
     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  intgetMaxAttempts()
     Returns the maximum number of attempts if no attachment could be matched on the first attempt.
public  RestletgetNext(Request request, Response response)
     Returns the next Restlet if available.
Parameters:
  request - The request to handle.
Parameters:
  response - The response to update.
public  floatgetRequiredScore()
     Returns the minimum score required to have a match.
public  longgetRetryDelay()
     Returns the delay (in seconds) before a new attempt.
public  RouteListgetRoutes()
     Returns the modifiable list of routes.
public  intgetRoutingMode()
     Returns the routing mode.
public  voidhandle(Request request, Response response)
     Handles a call by invoking the next Restlet if it is available.
public  voidsetDefaultRoute(Route defaultRoute)
     Sets the default route tested if no other one was available.
public  voidsetFinderClass(Class<? extends Finder> finderClass)
     Sets the finder class to instantiate.
public  voidsetMaxAttempts(int maxAttempts)
     Sets the maximum number of attempts if no attachment could be matched on the first attempt.
public  voidsetRequiredScore(float score)
     Sets the score required to have a match.
public  voidsetRetryDelay(long retryDelay)
     Sets the delay (in seconds) before a new attempt.
public  voidsetRoutingMode(int routingMode)
     Sets the routing mode.

Field Detail
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.




Constructor Detail
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.




Method Detail
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.



Methods inherited from org.restlet.Restlet
public Context getContext()(Code)(Java Doc)
public Logger getLogger()(Code)(Java Doc)
public void handle(Request request, Response response)(Code)(Java Doc)
protected synchronized void init(Request request, Response response)(Code)(Java Doc)
public synchronized boolean isStarted()(Code)(Java Doc)
public synchronized boolean isStopped()(Code)(Java Doc)
public void setContext(Context context)(Code)(Java Doc)
public synchronized void start() throws Exception(Code)(Java Doc)
public synchronized void stop() throws Exception(Code)(Java Doc)

Methods inherited from org.restlet.Uniform
final public Response delete(String resourceUri)(Code)(Java Doc)
final public Response delete(Reference resourceRef)(Code)(Java Doc)
final public Response get(String resourceUri)(Code)(Java Doc)
final public Response get(Reference resourceRef)(Code)(Java Doc)
final public Response handle(Request request)(Code)(Java Doc)
abstract public void handle(Request request, Response response)(Code)(Java Doc)
final public Response head(String resourceUri)(Code)(Java Doc)
final public Response head(Reference resourceRef)(Code)(Java Doc)
final public Response options(String resourceUri)(Code)(Java Doc)
final public Response options(Reference resourceRef)(Code)(Java Doc)
final public Response post(String resourceUri, Representation entity)(Code)(Java Doc)
final public Response post(Reference resourceRef, Representation entity)(Code)(Java Doc)
final public Response put(String resourceUri, Representation entity)(Code)(Java Doc)
final public Response put(Reference resourceRef, Representation entity)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.