use of org.mortbay.jetty.Connector in project sonatype-aether by sonatype.
the class HttpServer method waitForConnectors.
protected void waitForConnectors() throws Exception {
// for unknown reasons, the connectors occasionally don't start properly, this tries hard to ensure they are up
List<Connector> badConnectors = new ArrayList<Connector>(2);
for (int r = 10; r > 0; r--) {
// wait some seconds for the connectors to come up
for (int i = 200; i > 0; i--) {
badConnectors.clear();
for (Connector connector : server.getConnectors()) {
if (connector.getLocalPort() < 0) {
badConnectors.add(connector);
}
}
if (badConnectors.isEmpty()) {
return;
}
try {
Thread.sleep(15);
} catch (InterruptedException e) {
return;
}
}
// restart the broken connectors and hope they make it this time
System.err.println("WARNING: " + badConnectors + " did not start properly, restarting");
for (Connector connector : badConnectors) {
connector.stop();
connector.start();
}
}
}
use of org.mortbay.jetty.Connector in project sonatype-aether by sonatype.
the class HttpServer method start.
/**
* Starts the server. Trying to start an already running server has no effect.
*
* @return This server, never {@code null}.
* @throws Exception If the server could not be started.
*/
public HttpServer start() throws Exception {
if (server != null) {
return this;
}
recordedRequests.clear();
List<Connector> connectors = new ArrayList<Connector>();
if (httpPort >= 0) {
connectors.add(newHttpConnector());
}
if (httpsPort >= 0 && keyStoreLocation != null) {
connectors.add(newHttpsConnector());
}
HandlerList handlerList = new HandlerList();
if (!recordedPatterns.isEmpty()) {
handlerList.addHandler(new RecordingHandler());
}
if (latency != 0) {
handlerList.addHandler(newSleepHandler(latency));
}
if (redirectToHttps) {
handlerList.addHandler(newSslRedirectHandler());
}
if (proxyUsername != null && proxyPassword != null) {
handlerList.addHandler(newProxyHandler());
}
if (!securedRealms.isEmpty()) {
handlerList.addHandler(newSecurityHandler());
}
if (!resourceDirs.isEmpty()) {
handlerList.addHandler(newResourceHandler());
}
handlerList.addHandler(new DefaultHandler());
server = new Server(0);
server.setHandler(handlerList);
server.setConnectors(connectors.toArray(new Connector[connectors.size()]));
server.start();
waitForConnectors();
addDefaultFilterTokens();
return this;
}
use of org.mortbay.jetty.Connector in project commons by twitter.
the class JettyHttpServerDispatch method listen.
@Override
public synchronized boolean listen(int minPort, int maxPort) {
boolean state = !isStarted();
Preconditions.checkState(state, "HttpServerDispatch has already been started on port: %d", port);
Connector connector = openConnector(minPort, maxPort);
// Couldn't open a server port.
if (connector == null)
return false;
port = connector.getLocalPort();
server = new Server();
server.addConnector(connector);
context = new Context(server, "/", Context.NO_SESSIONS);
if (requestLog.isPresent()) {
RequestLogHandler logHandler = new RequestLogHandler();
logHandler.setRequestLog(requestLog.get());
context.addHandler(logHandler);
}
context.addServlet(new ServletHolder(new RootHandler()), "/");
try {
server.start();
LOG.info("HTTP server is listening on port " + port);
return true;
} catch (Exception e) {
LOG.log(Level.SEVERE, "HTTP server failed to start on port " + connector.getLocalPort(), e);
return false;
}
}
use of org.mortbay.jetty.Connector 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();
}
use of org.mortbay.jetty.Connector in project OpenRefine by OpenRefine.
the class ShutdownSignalHandler method init.
public void init(String host, int port) throws Exception {
logger.info("Starting Server bound to '" + host + ":" + port + "'");
String memory = Configurations.get("refine.memory");
if (memory != null) {
logger.info("refine.memory size: " + memory + " JVM Max heap: " + Runtime.getRuntime().maxMemory());
}
int maxThreads = Configurations.getInteger("refine.queue.size", 30);
int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
long keepAliveTime = Configurations.getInteger("refine.queue.idle_time", 60);
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);
threadPool = new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue);
this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool));
Connector connector = new SocketConnector();
connector.setPort(port);
connector.setHost(host);
connector.setMaxIdleTime(Configurations.getInteger("refine.connection.max_idle_time", 60000));
connector.setStatsOn(false);
this.addConnector(connector);
File webapp = new File(Configurations.get("refine.webapp", "main/webapp"));
if (!isWebapp(webapp)) {
webapp = new File("main/webapp");
if (!isWebapp(webapp)) {
webapp = new File("webapp");
if (!isWebapp(webapp)) {
logger.warn("Warning: Failed to find web application at '" + webapp.getAbsolutePath() + "'");
System.exit(-1);
}
}
}
final String contextPath = Configurations.get("refine.context_path", "/");
final int maxFormContentSize = Configurations.getInteger("refine.max_form_content_size", 1048576);
logger.info("Initializing context: '" + contextPath + "' from '" + webapp.getAbsolutePath() + "'");
WebAppContext context = new WebAppContext(webapp.getAbsolutePath(), contextPath);
context.setMaxFormContentSize(maxFormContentSize);
this.setHandler(context);
this.setStopAtShutdown(true);
this.setSendServerVersion(true);
// Enable context autoreloading
if (Configurations.getBoolean("refine.autoreload", false)) {
scanForUpdates(webapp, context);
}
// start the server
try {
this.start();
} catch (BindException e) {
logger.error("Failed to start server - is there another copy running already on this port/address?");
throw e;
}
configure(context);
}
Aggregations