~ubuntu-branches/ubuntu/saucy/restlet/saucy

« back to all changes in this revision

Viewing changes to org.restlet.ext.jetty/src/org/restlet/ext/jetty/HttpServerHelper.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 16:25:45 UTC
  • Revision ID: package-import@ubuntu.com-20120611162545-5w2o0resi5y3pybc
Tags: upstream-2.0.14
ImportĀ upstreamĀ versionĀ 2.0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2005-2012 Restlet S.A.S.
 
3
 * 
 
4
 * The contents of this file are subject to the terms of one of the following
 
5
 * open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
 
6
 * 1.0 (the "Licenses"). You can select the license that you prefer but you may
 
7
 * not use this file except in compliance with one of these Licenses.
 
8
 * 
 
9
 * You can obtain a copy of the Apache 2.0 license at
 
10
 * http://www.opensource.org/licenses/apache-2.0
 
11
 * 
 
12
 * You can obtain a copy of the LGPL 3.0 license at
 
13
 * http://www.opensource.org/licenses/lgpl-3.0
 
14
 * 
 
15
 * You can obtain a copy of the LGPL 2.1 license at
 
16
 * http://www.opensource.org/licenses/lgpl-2.1
 
17
 * 
 
18
 * You can obtain a copy of the CDDL 1.0 license at
 
19
 * http://www.opensource.org/licenses/cddl1
 
20
 * 
 
21
 * You can obtain a copy of the EPL 1.0 license at
 
22
 * http://www.opensource.org/licenses/eclipse-1.0
 
23
 * 
 
24
 * See the Licenses for the specific language governing permissions and
 
25
 * limitations under the Licenses.
 
26
 * 
 
27
 * Alternatively, you can obtain a royalty free commercial license with less
 
28
 * limitations, transferable or non-transferable, directly at
 
29
 * http://www.restlet.com/products/restlet-framework
 
30
 * 
 
31
 * Restlet is a registered trademark of Restlet S.A.S.
 
32
 */
 
33
 
 
34
package org.restlet.ext.jetty;
 
35
 
 
36
import org.eclipse.jetty.server.AbstractConnector;
 
37
import org.eclipse.jetty.server.bio.SocketConnector;
 
38
import org.eclipse.jetty.server.nio.BlockingChannelConnector;
 
39
import org.eclipse.jetty.server.nio.SelectChannelConnector;
 
40
import org.restlet.Server;
 
41
import org.restlet.data.Protocol;
 
42
 
 
43
/**
 
44
 * Jetty HTTP server connector. Here is the list of additional parameters that
 
45
 * are supported. They should be set in the Server's context before it is
 
46
 * started:
 
47
 * <table>
 
48
 * <tr>
 
49
 * <th>Parameter name</th>
 
50
 * <th>Value type</th>
 
51
 * <th>Default value</th>
 
52
 * <th>Description</th>
 
53
 * </tr>
 
54
 * <tr>
 
55
 * <td>type</td>
 
56
 * <td>int</td>
 
57
 * <td>1</td>
 
58
 * <td>The type of Jetty connector to use.<br>
 
59
 * 1 : Selecting NIO connector (Jetty's SelectChannelConnector class).<br>
 
60
 * 2 : Blocking NIO connector (Jetty's BlockingChannelConnector class).<br>
 
61
 * 3 : Blocking BIO connector (Jetty's SocketConnector class).</td>
 
62
 * </tr>
 
63
 * </table>
 
64
 * 
 
65
 * @see <a href="http://jetty.mortbay.org/jetty6/">Jetty home page</a>
 
66
 * @author Jerome Louvel
 
67
 */
 
68
public class HttpServerHelper extends JettyServerHelper {
 
69
    /**
 
70
     * Constructor.
 
71
     * 
 
72
     * @param server
 
73
     *            The server to help.
 
74
     */
 
75
    public HttpServerHelper(Server server) {
 
76
        super(server);
 
77
        getProtocols().add(Protocol.HTTP);
 
78
    }
 
79
 
 
80
    /**
 
81
     * Creates a new internal Jetty connector.
 
82
     * 
 
83
     * @return A new internal Jetty connector.
 
84
     */
 
85
    @Override
 
86
    protected AbstractConnector createConnector() {
 
87
        AbstractConnector result = null;
 
88
 
 
89
        // Create and configure the Jetty HTTP connector
 
90
        switch (getType()) {
 
91
        case 1:
 
92
            // Selecting NIO connector
 
93
            result = new SelectChannelConnector();
 
94
            break;
 
95
        case 2:
 
96
            // Blocking NIO connector
 
97
            result = new BlockingChannelConnector();
 
98
            break;
 
99
        case 3:
 
100
            // Blocking BIO connector
 
101
            result = new SocketConnector();
 
102
            break;
 
103
        }
 
104
 
 
105
        return result;
 
106
    }
 
107
 
 
108
    /**
 
109
     * Returns the type of Jetty connector to use.
 
110
     * 
 
111
     * @return The type of Jetty connector to use.
 
112
     */
 
113
    public int getType() {
 
114
        return Integer.parseInt(getHelpedParameters()
 
115
                .getFirstValue("type", "1"));
 
116
    }
 
117
 
 
118
}