Search in sources :

Example 6 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project CloudStack-archive by CloudStack-extras.

the class JettyVmDataServer method setupJetty.

private void setupJetty(int vmDataPort, int fileservingPort) throws Exception {
    _jetty = new Server();
    SelectChannelConnector connector0 = new SelectChannelConnector();
    connector0.setHost(_hostIp);
    connector0.setPort(fileservingPort);
    connector0.setMaxIdleTime(30000);
    connector0.setRequestBufferSize(8192);
    SelectChannelConnector connector1 = new SelectChannelConnector();
    connector1.setHost(_hostIp);
    connector1.setPort(vmDataPort);
    connector1.setThreadPool(new QueuedThreadPool(5));
    connector1.setMaxIdleTime(30000);
    connector1.setRequestBufferSize(8192);
    _jetty.setConnectors(new Connector[] { connector0, connector1 });
    Context root = new Context(_jetty, "/latest", Context.SESSIONS);
    root.setResourceBase(_vmDataDir);
    root.addServlet(new ServletHolder(new VmDataServlet(this, USER_DATA)), "/*");
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("/var/lib/images/");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { root, resource_handler, new DefaultHandler() });
    _jetty.setHandler(handlers);
    _jetty.start();
// _jetty.join();
}
Also used : Context(org.mortbay.jetty.servlet.Context) HandlerList(org.mortbay.jetty.handler.HandlerList) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server) QueuedThreadPool(org.mortbay.thread.QueuedThreadPool) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) ResourceHandler(org.mortbay.jetty.handler.ResourceHandler) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Example 7 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project voldemort by voldemort.

the class HttpService method startInner.

@Override
public void startInner() {
    try {
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setLowResourceMaxIdleTime(3000);
        connector.setPort(this.port);
        connector.setReuseAddress(true);
        QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setName("VoldemortHttp");
        threadPool.setMaxThreads(this.numberOfThreads);
        Server httpServer = new Server();
        httpServer.setConnectors(new Connector[] { connector });
        httpServer.setThreadPool(threadPool);
        httpServer.setSendServerVersion(false);
        httpServer.setSendDateHeader(false);
        Context context = new Context(httpServer, "/", Context.NO_SESSIONS);
        context.setAttribute(VoldemortServletContextListener.SERVER_KEY, server);
        context.setAttribute(VoldemortServletContextListener.VELOCITY_ENGINE_KEY, velocityEngine);
        context.addServlet(new ServletHolder(new AdminServlet(server, velocityEngine)), "/admin");
        context.addServlet(new ServletHolder(new StoreServlet(requestHandler)), "/stores");
        context.addServlet(new ServletHolder(new ReadOnlyStoreManagementServlet(server, velocityEngine)), "/read-only/mgmt");
        context.addServlet(new ServletHolder(new StatusServlet(server, velocityEngine)), "/server-status");
        this.context = context;
        this.httpServer = httpServer;
        this.httpServer.start();
        logger.info("HTTP service started on port " + this.port);
    } catch (Exception e) {
        String errorMessage = " Error starting service on port " + this.port;
        throw new VoldemortException(errorMessage, e);
    }
}
Also used : Context(org.mortbay.jetty.servlet.Context) StatusServlet(voldemort.server.http.gui.StatusServlet) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) AdminServlet(voldemort.server.http.gui.AdminServlet) Server(org.mortbay.jetty.Server) VoldemortServer(voldemort.server.VoldemortServer) QueuedThreadPool(org.mortbay.thread.QueuedThreadPool) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) ReadOnlyStoreManagementServlet(voldemort.server.http.gui.ReadOnlyStoreManagementServlet) VoldemortException(voldemort.VoldemortException) VoldemortException(voldemort.VoldemortException)

Example 8 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project tomee by apache.

the class JettyHttpServer method init.

@Override
public void init(final Properties props) throws Exception {
    final Options options = new Options(props);
    port = options.get("port", 8080);
    // Create all the Jetty objects but dont' start them
    server = new Server();
    final Connector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.setConnectors(new Connector[] { connector });
    final ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    final ServletContext servletContext = context.getServletContext();
    server.setHandler(context);
    final Handler handler = new AbstractHandler() {

        @Override
        public void handle(final String target, final HttpServletRequest req, final HttpServletResponse res, final int dispatch) throws IOException, ServletException {
            try {
                ((Request) req).setHandled(true);
                final HttpRequest httpRequest = new ServletRequestAdapter(req, res, servletContext);
                final HttpResponse httpResponse = new ServletResponseAdapter(res);
                JettyHttpServer.this.listener.onMessage(httpRequest, httpResponse);
            } catch (IOException | ServletException e) {
                throw e;
            } catch (Exception e) {
                throw new ServletException(e);
            }
        }
    };
    final SessionHandler sessionHandler = new SessionHandler();
    final SessionManager sessionManager = new HashSessionManager();
    sessionManager.setIdManager(new HashSessionIdManager());
    sessionHandler.setSessionManager(sessionManager);
    sessionHandler.setHandler(handler);
    context.setHandler(sessionHandler);
}
Also used : SessionHandler(org.mortbay.jetty.servlet.SessionHandler) Options(org.apache.openejb.loader.Options) Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server) HashSessionManager(org.mortbay.jetty.servlet.HashSessionManager) SessionManager(org.mortbay.jetty.SessionManager) HashSessionManager(org.mortbay.jetty.servlet.HashSessionManager) Request(org.mortbay.jetty.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Handler(org.mortbay.jetty.Handler) SessionHandler(org.mortbay.jetty.servlet.SessionHandler) ContextHandler(org.mortbay.jetty.handler.ContextHandler) AbstractHandler(org.mortbay.jetty.handler.AbstractHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) HashSessionIdManager(org.mortbay.jetty.servlet.HashSessionIdManager) AbstractHandler(org.mortbay.jetty.handler.AbstractHandler) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ServiceException(org.apache.openejb.server.ServiceException) ContextHandler(org.mortbay.jetty.handler.ContextHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) ServletContext(javax.servlet.ServletContext)

Example 9 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project gradle by gradle.

the class Jetty6PluginServer method createDefaultConnector.

public Object createDefaultConnector(int port) throws Exception {
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    connector.setMaxIdleTime(DEFAULT_MAX_IDLE_TIME);
    return connector;
}
Also used : SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector)

Example 10 with SelectChannelConnector

use of org.mortbay.jetty.nio.SelectChannelConnector in project roboguice by roboguice.

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