01: /*
02: * Copyright 2005-2007 Noelios Consulting.
03: *
04: * The contents of this file are subject to the terms of the Common Development
05: * and Distribution License (the "License"). You may not use this file except in
06: * compliance with the License.
07: *
08: * You can obtain a copy of the license at
09: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
10: * language governing permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL HEADER in each file and
13: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
14: * applicable, add the following below this CDDL HEADER, with the fields
15: * enclosed by brackets "[]" replaced with your own identifying information:
16: * Portions Copyright [yyyy] [name of copyright owner]
17: */
18:
19: package com.noelios.restlet.component;
20:
21: import java.util.logging.Level;
22:
23: import org.restlet.Client;
24: import org.restlet.Route;
25: import org.restlet.Router;
26: import org.restlet.data.Protocol;
27: import org.restlet.data.Request;
28: import org.restlet.data.Response;
29:
30: /**
31: * Router scorer based on a target client connector.
32: *
33: * @author Jerome Louvel (contact@noelios.com)
34: */
35: public class ClientRoute extends Route {
36: /**
37: * Constructor.
38: *
39: * @param router
40: * The parent router.
41: * @param target
42: * The target client.
43: */
44: public ClientRoute(Router router, Client target) {
45: super (router, "", target);
46: }
47:
48: /**
49: * Returns the target client.
50: *
51: * @return The target client.
52: */
53: public Client getClient() {
54: return (Client) getNext();
55: }
56:
57: /**
58: * Sets the next client.
59: *
60: * @param next
61: * The next client.
62: */
63: public void setNext(Client next) {
64: super .setNext(next);
65: }
66:
67: /**
68: * Returns the score for a given call (between 0 and 1.0).
69: *
70: * @param request
71: * The request to score.
72: * @param response
73: * The response to score.
74: * @return The score for a given call (between 0 and 1.0).
75: */
76: public float score(Request request, Response response) {
77: float result = 0F;
78:
79: // Add the protocol score
80: Protocol protocol = request.getProtocol();
81:
82: if (protocol == null) {
83: getLogger()
84: .warning(
85: "Unable to determine the protocol to use for this call.");
86: } else if (getClient().getProtocols().contains(protocol)) {
87: result = 1.0F;
88: }
89:
90: if (getLogger().isLoggable(Level.FINER)) {
91: getLogger().finer(
92: "Call score for the \""
93: + getClient().getProtocols().toString()
94: + "\" client: " + result);
95: }
96:
97: return result;
98: }
99: }
|