use of org.mortbay.jetty.bio.SocketConnector in project nhin-d by DirectProject.
the class ConfigServiceRunner method startConfigService.
public static synchronized void startConfigService() throws Exception {
if (server == null) {
/*
* Setup the configuration service server
*/
server = new Server();
SocketConnector connector = new SocketConnector();
HTTPPort = AvailablePortFinder.getNextAvailable(1024);
connector.setPort(HTTPPort);
WebAppContext context = new WebAppContext();
context.setContextPath("/config");
context.setServer(server);
context.setWar("war/config-service.war");
server.setSendServerVersion(false);
server.addConnector(connector);
server.addHandler(context);
server.start();
configServiceURL = "http://localhost:" + HTTPPort + "/config/ConfigurationService";
}
}
use of org.mortbay.jetty.bio.SocketConnector 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);
}
use of org.mortbay.jetty.bio.SocketConnector in project jackrabbit by apache.
the class RepositoryStubImpl method getRepository.
@Override
public Repository getRepository() throws RepositoryStubException {
if (repository == null) {
repository = super.getRepository();
}
if (connector == null) {
connector = new SocketConnector();
connector.setHost("localhost");
String pvalue = System.getProperty("org.apache.jackrabbit.jcr2dav.RepositoryStubImpl.port", "0");
int port = pvalue.equals("") ? 0 : Integer.parseInt(pvalue);
connector.setPort(port);
}
if (server == null) {
server = new Server();
server.addConnector(connector);
ServletHolder holder = new ServletHolder(new JcrRemotingServlet() {
protected Repository getRepository() {
return repository;
}
});
holder.setInitParameter(JCRWebdavServerServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "");
holder.setInitParameter(JCRWebdavServerServlet.INIT_PARAM_MISSING_AUTH_MAPPING, "");
holder.setInitParameter(JcrRemotingServlet.INIT_PARAM_PROTECTED_HANDLERS_CONFIG, protectedRemoveImplClass);
Context context = new Context(server, "/");
context.addServlet(holder, "/*");
server.addHandler(context);
try {
server.start();
} catch (Exception e) {
throw new RepositoryStubException(e);
}
}
if (client == null) {
try {
Map<String, String> parameters = new HashMap<String, String>();
String uri = "http://localhost:" + connector.getLocalPort() + "/";
String parmName = System.getProperty(this.getClass().getName() + ".REPURIPARM", JcrUtils.REPOSITORY_URI);
parameters.put(parmName, uri);
parameters.put(PROP_ACCESSCONTROL_PROVIDER_CLASS, acProviderImplClass);
client = JcrUtils.getRepository(parameters);
} catch (Exception e) {
throw new RepositoryStubException(e);
}
}
return client;
}
use of org.mortbay.jetty.bio.SocketConnector in project ambrose by twitter.
the class ScriptStatusServer method run.
/**
* Run the server in the current thread.
*/
@Override
public void run() {
// override newServerSocket to log local port once bound
Connector connector = new SocketConnector() {
@Override
protected ServerSocket newServerSocket(String host, int port, int backlog) throws IOException {
ServerSocket ss = super.newServerSocket(host, port, backlog);
int localPort = ss.getLocalPort();
LOG.info("Ambrose web server listening on port {}", localPort);
LOG.info("Browse to http://localhost:{}/ to see job progress", localPort);
return ss;
}
};
connector.setPort(port);
server = new Server();
server.setConnectors(new Connector[] { connector });
// this needs to be loaded via the jar'ed resources, not the relative dir
String resourcePath = "com/twitter/ambrose/server/web";
URL resourceUrl = checkNotNull(APIHandler.class.getClassLoader().getResource(resourcePath), "Failed to find resource '%s'", resourcePath);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setWelcomeFiles(new String[] { "workflow.html" });
resourceHandler.setResourceBase(resourceUrl.toExternalForm());
HandlerList handler = new HandlerList();
handler.setHandlers(new Handler[] { resourceHandler, new APIHandler(workflowIndexReadService, statsReadService), new DefaultHandler() });
server.setHandler(handler);
server.setStopAtShutdown(false);
try {
server.start();
server.join();
} catch (Exception e) {
LOG.error("Error launching ScriptStatusServer", e);
}
}
use of org.mortbay.jetty.bio.SocketConnector in project nhin-d by DirectProject.
the class MonitorServiceRunner method startMonitorService.
public static synchronized void startMonitorService() throws Exception {
if (server == null) {
/*
* Setup the configuration service server
*/
server = new Server();
SocketConnector connector = new SocketConnector();
HTTPPort = AvailablePortFinder.getNextAvailable(8090);
connector.setPort(HTTPPort);
// certificate service
WebAppContext context = new WebAppContext("src/test/resources/webapp-liverun", "/");
server.setSendServerVersion(false);
server.addConnector(connector);
server.addHandler(context);
server.start();
serviceURL = "http://localhost:" + HTTPPort + "/";
}
}
Aggregations