|
17 | 17 | */
|
18 | 18 | package io.undertow.util;
|
19 | 19 |
|
| 20 | +import io.undertow.server.HttpHandler; |
| 21 | + |
20 | 22 | /**
|
21 | 23 | * Routes requested URL paths to sets of underlying URL path templates.
|
22 | 24 | *
|
|
80 | 82 | * <li>It is assumed that most services that use routing based on path templates will setup a router once (when the service
|
81 | 83 | * starts) using a single thread and will then use that router to route millions of inbound requests using multiple concurrent
|
82 | 84 | * threads. Perhaps the setup will not happen exactly once, but the mutation of routes happen very few times when compared to
|
83 |
| - * the number of times that requests are routed. For this reason this factory is heavily biased towards optimising the |
| 85 | + * the number of times that requests are routed. For this reason this design is heavily biased towards optimising the |
84 | 86 | * performance of routing requests - sometimes at the expense of the performance of mutating routes.</li>
|
85 | 87 | * <li>Taking point (1) above into consideration. Documentation and comments refer to two distinct phases of processing:<ol>
|
86 | 88 | * <li>"Setup phase" as the phase/process during which routes are mutated and a router instance is created.</li>
|
|
98 | 100 | public interface PathTemplateRouter<T> {
|
99 | 101 |
|
100 | 102 | /**
|
101 |
| - * @return The default target for requests that do no match any specific routes. |
| 103 | + * @return The default target for requests that do not match any specific routes. |
102 | 104 | */
|
103 | 105 | T getDefaultTarget();
|
104 | 106 |
|
105 | 107 | /**
|
106 |
| - * Routes the requested URL path to the set of underlying URL path templates. |
107 |
| - * |
108 |
| - * @param path The requested URL path. |
| 108 | + * Routes the requested URL path to the best available target from the set of underlying URL path templates. |
109 | 109 | *
|
110 |
| - * @return The routing result. If the requested URL path matches any of the underlying URL path templates, then the most |
| 110 | + * <p> |
| 111 | + * If the requested URL path matches any of the underlying URL path templates, then the most |
111 | 112 | * specific match (target and template) will be returned in the result. If the requested URL path does not match any of the
|
112 |
| - * underlying URL path templates, then result will contain {@link #getDefaultTarget() } as the target and will contain an |
| 113 | + * underlying URL path templates, then the result will contain {@link #getDefaultTarget() } as the target and will contain an |
113 | 114 | * empty Optional in {@link PathTemplateRouteResult#getPathTemplate() }.
|
| 115 | + * |
| 116 | + * <p> |
| 117 | + * On completion of this method, the caller will have the best available target for the specified path. This method |
| 118 | + * merely provides the best target and does not call / action the target. That remains the responsibility of the caller. |
| 119 | + * This design allows the router to support different use cases, i.e.: |
| 120 | + * <ol> |
| 121 | + * <li>Determine the best available {@link HttpHandler} to process a client request based on the requested path.</li> |
| 122 | + * <li>Summarise HTTP access logs by normalising requested paths to available path templates.</li> |
| 123 | + * </ol> |
| 124 | + * |
| 125 | + * @param path The requested URL path. |
| 126 | + * |
| 127 | + * @return The routing result. |
114 | 128 | */
|
115 | 129 | PathTemplateRouteResult<T> route(String path);
|
116 | 130 | }
|
0 commit comments