Search in sources :

Example 1 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project dubbo by alibaba.

the class JettyContainer method start.

public void start() {
    String serverPort = ConfigUtils.getProperty(JETTY_PORT);
    int port;
    if (serverPort == null || serverPort.length() == 0) {
        port = DEFAULT_JETTY_PORT;
    } else {
        port = Integer.parseInt(serverPort);
    }
    connector = new SelectChannelConnector();
    connector.setPort(port);
    ServletHandler handler = new ServletHandler();
    String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
    if (resources != null && resources.length() > 0) {
        FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
        resourceHolder.setInitParameter("resources", resources);
    }
    ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
    pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
    pageHolder.setInitOrder(2);
    Server server = new Server();
    server.addConnector(connector);
    server.addHandler(handler);
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
    }
}
Also used : SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) ServletHandler(org.mortbay.jetty.servlet.ServletHandler) FilterHolder(org.mortbay.jetty.servlet.FilterHolder) Server(org.mortbay.jetty.Server) ServletHolder(org.mortbay.jetty.servlet.ServletHolder)

Example 2 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project Honu by jboulon.

the class ThriftJettyCollector method main.

public static void main(String[] args) throws Exception {
    Configuration conf = HonuConfigurationFactory.getInstance().getCollectorConfiguration();
    THREADS = conf.getInt("chukwaCollector.http.threads", THREADS);
    // Set up jetty connector
    int portNum = conf.getInt("chukwaCollector.http.port", 9999);
    SelectChannelConnector jettyConnector = new SelectChannelConnector();
    jettyConnector.setLowResourcesConnections(THREADS - 10);
    jettyConnector.setLowResourceMaxIdleTime(1500);
    jettyConnector.setPort(portNum);
    int sslPortNum = conf.getInt("chukwaCollector.https.port", 9998);
    SslSocketConnector sslConnector = new SslSocketConnector();
    sslConnector.setPort(sslPortNum);
    sslConnector.setMaxIdleTime(1500);
    sslConnector.setKeystore(conf.get("chukwaCollector.keystore"));
    sslConnector.setTruststore(conf.get("chukwaCollector.truststore"));
    sslConnector.setPassword(conf.get("chukwaCollector.password"));
    sslConnector.setKeyPassword(conf.get("chukwaCollector.keyPassword"));
    sslConnector.setTrustPassword(conf.get("chukwaCollector.trustPassword"));
    // Set up jetty server proper, using connector
    jettyServer = new Server(portNum);
    jettyServer.setConnectors(new Connector[] { jettyConnector, sslConnector });
    org.mortbay.thread.BoundedThreadPool pool = new org.mortbay.thread.BoundedThreadPool();
    pool.setMaxThreads(THREADS);
    jettyServer.setThreadPool(pool);
    // Add the collector servlet to server
    Context root = new Context(jettyServer, "/", Context.SESSIONS);
    root.addServlet(new ServletHolder(new ThriftServletCollector()), "/*");
    jettyServer.start();
    jettyServer.setStopAtShutdown(true);
}
Also used : SslSocketConnector(org.mortbay.jetty.security.SslSocketConnector) Configuration(org.apache.hadoop.conf.Configuration) Server(org.mortbay.jetty.Server) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) ThriftServletCollector(org.honu.datacollection.collector.servlet.ThriftServletCollector)

Example 3 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project sonatype-aether by sonatype.

the class HttpServer method newHttpConnector.

protected Connector newHttpConnector() {
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(httpPort);
    return connector;
}
Also used : SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector)

Example 4 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project commons by twitter.

the class JettyHttpServerDispatch method openConnector.

/**
   * Opens a new Connector which is a Jetty specific way of handling the
   * lifecycle and configuration of the Jetty server. The connector will
   * open a Socket on an available port between minPort and maxPort.
   * A subclass can override this method to modify connector configurations
   * such as queue-size or header-buffer-size.
   * @param minPort the minimum port number to bind to.
   * @param maxPort the maximum port number to bind to.
   * @return
   */
protected Connector openConnector(int minPort, int maxPort) {
    if (minPort != 0 || maxPort != 0) {
        Preconditions.checkState(minPort > 0, "Invalid port range.");
        Preconditions.checkState(maxPort > 0, "Invalid port range.");
        Preconditions.checkState(minPort <= maxPort, "Invalid port range.");
    }
    int attempts = 0;
    int port;
    int maxAttempts = minPort == maxPort ? 1 : 5;
    while (++attempts <= maxAttempts) {
        if (minPort == maxPort) {
            port = minPort;
        } else {
            port = minPort + new Random().nextInt(maxPort - minPort);
        }
        LOG.info("Attempting to listen on port " + port);
        try {
            // TODO(John Sirois): consider making Connector impl parametrizable
            AbstractConnector connector = new SelectChannelConnector();
            connector.setPort(port);
            // Create the server with a maximum TCP backlog of 50, meaning that when the request queue
            // exceeds 50, subsequent connections may be rejected.
            connector.setAcceptQueueSize(50);
            connector.open();
            return connector;
        } catch (IOException e) {
            LOG.log(Level.WARNING, "Failed to create HTTP server on port " + port, e);
        }
    }
    return null;
}
Also used : SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Random(java.util.Random) IOException(java.io.IOException) AbstractConnector(org.mortbay.jetty.AbstractConnector)

Example 5 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project guice by google.

the class Main method main.

public static void main(String[] args) throws Exception {
    Server server = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.setConnectors(new Connector[] { connector });
    WebAppContext webapp = new WebAppContext("./root", "/example");
    server.addHandler(webapp);
    server.start();
    server.join();
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server)

Aggregations

SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)12 Server (org.mortbay.jetty.Server)7 Connector (org.mortbay.jetty.Connector)5 ServletHolder (org.mortbay.jetty.servlet.ServletHolder)3 IOException (java.io.IOException)2 SslSocketConnector (org.mortbay.jetty.security.SslSocketConnector)2 Context (org.mortbay.jetty.servlet.Context)2 WebAppContext (org.mortbay.jetty.webapp.WebAppContext)2 QueuedThreadPool (org.mortbay.thread.QueuedThreadPool)2 Random (java.util.Random)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Configuration (org.apache.hadoop.conf.Configuration)1 Options (org.apache.openejb.loader.Options)1 ServiceException (org.apache.openejb.server.ServiceException)1 ThriftServletCollector (org.honu.datacollection.collector.servlet.ThriftServletCollector)1 AbstractConnector (org.mortbay.jetty.AbstractConnector)1 Handler (org.mortbay.jetty.Handler)1