001: /*
002: * Copyright 2005-2007 Noelios Consulting.
003: *
004: * The contents of this file are subject to the terms of the Common Development
005: * and Distribution License (the "License"). You may not use this file except in
006: * compliance with the License.
007: *
008: * You can obtain a copy of the license at
009: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010: * language governing permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL HEADER in each file and
013: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014: * applicable, add the following below this CDDL HEADER, with the fields
015: * enclosed by brackets "[]" replaced with your own identifying information:
016: * Portions Copyright [yyyy] [name of copyright owner]
017: */
018:
019: package com.noelios.restlet.ext.jetty;
020:
021: import org.mortbay.jetty.AbstractConnector;
022: import org.mortbay.jetty.bio.SocketConnector;
023: import org.mortbay.jetty.nio.BlockingChannelConnector;
024: import org.mortbay.jetty.nio.SelectChannelConnector;
025: import org.restlet.Server;
026: import org.restlet.data.Protocol;
027:
028: /**
029: * Jetty HTTP server connector. Here is the list of additional parameters that
030: * are supported: <table>
031: * <tr>
032: * <th>Parameter name</th>
033: * <th>Value type</th>
034: * <th>Default value</th>
035: * <th>Description</th>
036: * </tr>
037: * <tr>
038: * <td>type</td>
039: * <td>int</td>
040: * <td>1</td>
041: * <td>The type of Jetty connector to use.<br/> 1 : Selecting NIO connector
042: * (Jetty's SelectChannelConnector class).<br/> 2 : Blocking NIO connector
043: * (Jetty's BlockingChannelConnector class).<br/> 3 : Blocking BIO connector
044: * (Jetty's SocketConnector class).</td>
045: * </tr>
046: * </table>
047: *
048: * @see <a href="http://jetty.mortbay.org/jetty6/">Jetty home page</a>
049: * @author Jerome Louvel (contact@noelios.com)
050: */
051: public class HttpServerHelper extends JettyServerHelper {
052: /**
053: * Constructor.
054: *
055: * @param server
056: * The server to help.
057: */
058: public HttpServerHelper(Server server) {
059: super (server);
060: getProtocols().add(Protocol.HTTP);
061: }
062:
063: /**
064: * Creates a new internal Jetty connector.
065: *
066: * @return A new internal Jetty connector.
067: */
068: protected AbstractConnector createConnector() {
069: AbstractConnector result = null;
070:
071: // Create and configure the Jetty HTTP connector
072: switch (getType()) {
073: case 1:
074: // Selecting NIO connector
075: result = new SelectChannelConnector();
076: break;
077: case 2:
078: // Blocking NIO connector
079: result = new BlockingChannelConnector();
080: break;
081: case 3:
082: // Blocking BIO connector
083: result = new SocketConnector();
084: break;
085: }
086:
087: return result;
088: }
089:
090: /**
091: * Returns the type of Jetty connector to use.
092: *
093: * @return The type of Jetty connector to use.
094: */
095: public int getType() {
096: return Integer.parseInt(getParameters().getFirstValue("type",
097: "1"));
098: }
099:
100: }
|