本文整理汇总了Java中org.restlet.routing.Route类的典型用法代码示例。如果您正苦于以下问题:Java Route类的具体用法?Java Route怎么用?Java Route使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Route类属于org.restlet.routing包,在下文中一共展示了Route类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBest
import org.restlet.routing.Route; //导入依赖的package包/类
/**
* Returns the best route match for a given call.
*
* @param request
* The request to score.
* @param response
* The response to score.
* @param requiredScore
* The minimum score required to have a match.
* @return The best route match or null.
*/
public Route getBest(Request request, Response response, float requiredScore) {
Route result = null;
float bestScore = 0F;
float score;
for (Route current : this) {
score = current.score(request, response);
if ((score > bestScore) && (score >= requiredScore)) {
bestScore = score;
result = current;
}
}
return result;
}
示例2: getNext
import org.restlet.routing.Route; //导入依赖的package包/类
/**
* Returns a next route match in a round robin mode for a given call.
*
* @param request
* The request to score.
* @param response
* The response to score.
* @param requiredScore
* The minimum score required to have a match.
* @return A next route or null.
*/
public synchronized Route getNext(Request request, Response response,
float requiredScore) {
if (!isEmpty()) {
for (final int initialIndex = this.lastIndex++; initialIndex != this.lastIndex; this.lastIndex++) {
if (this.lastIndex >= size()) {
this.lastIndex = 0;
}
final Route route = get(this.lastIndex);
if (route.score(request, response) >= requiredScore) {
return route;
}
}
}
// No match found
return null;
}
示例3: stopHostApplications
import org.restlet.routing.Route; //导入依赖的package包/类
/**
* Stop all applications attached to a virtual host
*
* @param host
* @throws Exception
*/
private void stopHostApplications(VirtualHost host) throws Exception {
for (Route route : host.getRoutes()) {
if (route.getNext().isStarted()) {
route.getNext().stop();
}
}
}
示例4: getFirst
import org.restlet.routing.Route; //导入依赖的package包/类
/**
* Returns the first route match for a given call.
*
* @param request
* The request to score.
* @param response
* The response to score.
* @param requiredScore
* The minimum score required to have a match.
* @return The first route match or null.
*/
public Route getFirst(Request request, Response response,
float requiredScore) {
for (Route current : this) {
if (current.score(request, response) >= requiredScore) {
return current;
}
}
// No match found
return null;
}
示例5: getLast
import org.restlet.routing.Route; //导入依赖的package包/类
/**
* Returns the last route match for a given call.
*
* @param request
* The request to score.
* @param response
* The response to score.
* @param requiredScore
* The minimum score required to have a match.
* @return The last route match or null.
*/
public synchronized Route getLast(Request request, Response response,
float requiredScore) {
for (int j = size() - 1; (j >= 0); j--) {
final Route route = get(j);
if (route.score(request, response) >= requiredScore) {
return route;
}
}
// No match found
return null;
}
示例6: getRandom
import org.restlet.routing.Route; //导入依赖的package包/类
/**
* Returns a random route match for a given call. Note that the current
* implementation doesn't uniformly return routes unless they all score
* above the required score.
*
* @param request
* The request to score.
* @param response
* The response to score.
* @param requiredScore
* The minimum score required to have a match.
* @return A random route or null.
*/
public synchronized Route getRandom(Request request, Response response,
float requiredScore) {
int length = size();
if (length > 0) {
int j = new Random().nextInt(length);
Route route = get(j);
if (route.score(request, response) >= requiredScore) {
return route;
}
boolean loopedAround = false;
do {
if ((j == length) && (loopedAround == false)) {
j = 0;
loopedAround = true;
}
route = get(j++);
if (route.score(request, response) >= requiredScore) {
return route;
}
} while ((j < length) || !loopedAround);
}
// No match found
return null;
}
示例7: createEntryPoint
import org.restlet.routing.Route; //导入依赖的package包/类
private EntryPoint createEntryPoint()
{
Map<String, RestLink> entryPoints = new HashMap<>();
for( Route r : parameters.router().get().getRoutes() )
{
if( r instanceof TemplateRoute)
{
TemplateRoute route = (TemplateRoute) r;
Template template = route.getTemplate();
// Only include patterns that doesn't have variables, and has a proper name.
if( template.getVariableNames().isEmpty() && route.getName().indexOf( '>' ) == -1 )
{
Reference hostRef = parameters.request().get().getOriginalRef();
// Reference reference = new Reference( hostRef, template.getPattern() );
RestLink link;
if( route.getDescription() == null )
{
link = resourceBuilder.createRestLink( template.getPattern(), hostRef, Method.GET );
}
else
{
link = resourceBuilder.createRestLink( template.getPattern(), hostRef, Method.GET, route.getDescription() );
}
entryPoints.put( route.getName(), link );
}
}
}
ValueBuilder<EntryPoint> builder = vbf.newValueBuilder( EntryPoint.class );
builder.prototype().identity().set( StringIdentity.identityOf( "/" ) );
builder.prototype().api().set( entryPoints );
return builder.newInstance();
}
示例8: attachFallback
import org.restlet.routing.Route; //导入依赖的package包/类
/**
* @param pathTemplate
* The URI path template that must match the relative part of the
* resource URI.
* @param target
* The target Restlet to attach.
* @return The created route.
*/
public TemplateRoute attachFallback( String pathTemplate, Restlet target )
{
TemplateRoute existingRoute = null;
for( Route route : getRoutes() )
{
if( route instanceof TemplateRoute )
{
TemplateRoute templateRoute = (TemplateRoute) route;
if( templateRoute.getTemplate().getPattern().equals( pathTemplate ) )
{
existingRoute = templateRoute;
break;
}
}
}
if( existingRoute != null )
{
Restlet current = existingRoute.getNext();
if( current instanceof Fallback )
{
// Add to current Fallback
( (Fallback) current ).addTarget( target );
}
else
{
// Replace current target with Fallback
Fallback fallback = new Fallback( getContext(), cacheDuration, current, target );
existingRoute.setNext( fallback );
}
return existingRoute;
}
return attach( pathTemplate, target );
}
示例9: list
import org.restlet.routing.Route; //导入依赖的package包/类
private void list(Map<Restlet, String> all, Restlet restlet, String path) {
all.put(restlet, path);
if (restlet instanceof Router) {
for (Route r : ((Router)restlet).getRoutes()) {
list(all, r, path + ((TemplateRoute)r).getTemplate().getPattern());
}
} else if (restlet instanceof Filter) {
list(all, ((Filter) restlet).getNext(), path);
}
}
示例10: RouteList
import org.restlet.routing.Route; //导入依赖的package包/类
/**
* Constructor.
*/
public RouteList() {
super(new CopyOnWriteArrayList<Route>());
this.lastIndex = -1;
}
示例11: findRoute
import org.restlet.routing.Route; //导入依赖的package包/类
@Override
public Route findRoute( String name, Router router )
{
return router.getRoutes().stream().filter( route -> name.equals( route.getName() ) ).findFirst().orElse( null );
}
示例12: detach
import org.restlet.routing.Route; //导入依赖的package包/类
@Override
public void detach( Restlet target )
{
boolean found = false;
Route dead = null;
for( Route route : getRoutes() )
{
Restlet restlet = route.getNext();
if( restlet instanceof Fallback )
{
Fallback fallback = (Fallback) restlet;
for( Restlet fallbackRestlet : fallback.getTargets() )
{
if( fallbackRestlet == target )
{
found = true;
break;
}
}
if( found )
{
fallback.getTargets().remove( target );
int size = fallback.getTargets().size();
if( size == 1 )
// No need for fallback anymore
route.setNext( fallback.getTargets().get( 0 ) );
else if( size == 0 )
// No need for route anymore
dead = route;
break;
}
}
}
if( dead != null )
getRoutes().remove( dead );
else if( !found )
super.detach( target );
}
示例13: createRoot
import org.restlet.routing.Route; //导入依赖的package包/类
public Restlet createRoot() {
Router router = new Router(getContext());
//router.setDefaultMatchingMode(Router.BEST);
//System.out.println("MatchingMode: "+ router.getDefaultMatchingMode() + " : "+ router.getRequiredScore());
router.attach(URL_DATASOURCES, DataSources.class);
//Register the route for the home page url pattern
String target = "http://bridgedb.org/wiki/BridgeWebservice";
Redirector redirector = new Redirector(getContext(), target, Redirector.MODE_CLIENT_TEMPORARY);
router.attach(URL_HOME, redirector);
router.attach(URL_CONFIG, Config.class);
router.attach(URL_CONTENTS, Contents.class);
/* IDMapper methods */
//Register the route for the xrefs url pattern
Route xrefsRoute = router.attach(URL_XREFS, Xrefs.class);
//Specify that the dataSource parameter needs to be included
//in the attributes
xrefsRoute.extractQuery(PAR_TARGET_SYSTEM, PAR_TARGET_SYSTEM, true);
Route searchRoute = router.attach( URL_SEARCH, FreeSearch.class );
searchRoute.extractQuery( PAR_TARGET_LIMIT, PAR_TARGET_LIMIT, true );
router.attach(URL_XREF_EXISTS, XrefExists.class);
/* IDMapperCapabilities methods */
router.attach (URL_PROPERTIES, Properties.class );
router.attach (
URL_SUPPORTED_SOURCE_DATASOURCES, SupportedSourceDataSources.class );
router.attach (
URL_SUPPORTED_TARGET_DATASOURCES, SupportedTargetDataSources.class );
router.attach(URL_ATTRIBUTE_SET, AttributeSet.class);
router.attach(URL_IS_FREE_SEARCH_SUPPORTED, IsFreeSearchSupported.class);
router.attach(URL_IS_MAPPING_SUPPORTED, IsMappingSupported.class);
/* AttributeMapper methods */
Route attrSearchRoute = router.attach( URL_ATTRIBUTE_SEARCH, AttributeSearch.class );
attrSearchRoute.extractQuery( PAR_TARGET_LIMIT, PAR_TARGET_LIMIT, true );
attrSearchRoute.extractQuery( PAR_TARGET_ATTR_NAME, PAR_TARGET_ATTR_NAME, true );
Route attributesRoute = router.attach(URL_ATTRIBUTES, Attributes.class );
attributesRoute.extractQuery( PAR_TARGET_ATTR_NAME, PAR_TARGET_ATTR_NAME, true );
/* Extra methods */
// Register the route for backPageText
router.attach( URL_BACK_PAGE_TEXT, BackPageText.class );
//Register the route for a url pattern that doesn't match other patterns
router.attach(URL_NO_MATCH, NoMatch.class);
return router;
}
示例14: describeRoutes
import org.restlet.routing.Route; //导入依赖的package包/类
private void describeRoutes(StringBuilder b, Router router, String path) {
RouteList routes = router.getRoutes();
b.append("[").append(path).append("] = Router: ").append(router.getName()).append(": ").append(router.getDescription()).append("\n");
for (Route r : routes) {
if (r instanceof TemplateRoute) {
describe(b, r.getNext(), path + ((TemplateRoute)r).getTemplate().getPattern());
}
}
}