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);
}
}
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);
}
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;
}
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;
}
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();
}
Aggregations