本文整理匯總了Java中org.eclipse.jetty.server.nio.SelectChannelConnector類的典型用法代碼示例。如果您正苦於以下問題:Java SelectChannelConnector類的具體用法?Java SelectChannelConnector怎麽用?Java SelectChannelConnector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SelectChannelConnector類屬於org.eclipse.jetty.server.nio包,在下文中一共展示了SelectChannelConnector類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createServer
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
private Server createServer() {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(8384);
server.addConnector(connector);
ServletHandler handler = new ServletHandler();
Servlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String path = req.getServletPath().substring(1);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
resp.getWriter().append(path);
}
};
handler.addServletWithMapping(new ServletHolder(servlet), "/");
server.setHandler(handler);
return server;
}
示例2: run
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
public void run(int port) throws Exception {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
server.addConnector(connector);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase("./performance/site/");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler,
new DefaultHandler() });
server.setHandler(handlers);
server.start();
System.out.println("Started performance file server at port: " + port);
server.join();
}
示例3: buildJetty
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
public void buildJetty(int port, String sourceDir, String webXmlFile) throws Exception {
server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
server.addConnector(connector);
WebAppContext context = new WebAppContext();
context.setResourceBase(sourceDir);
context.setDescriptor(sourceDir + "/WEB-INF/" + webXmlFile);
context.setLogUrlOnStart(true);
context.setContextPath("/");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
}
示例4: createServerInSource
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
/**
* 創建用於開發運行調試的Jetty Server, 以src/main/webapp為Web應用目錄.
*/
public static Server createServerInSource(int port, String contextPath) {
Server server = new Server();
// 設置在JVM退出時關閉Jetty的鉤子。
server.setStopAtShutdown(true);
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
// 解決Windows下重複啟動Jetty居然不報告端口衝突的問題.
connector.setReuseAddress(false);
server.setConnectors(new Connector[] { connector });
WebAppContext webContext = new WebAppContext(DEFAULT_WEBAPP_PATH, contextPath);
// 修改webdefault.xml,解決Windows下Jetty Lock住靜態文件的問題.
webContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
server.setHandler(webContext);
return server;
}
示例5: initJettyServer
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
private Server initJettyServer(ComponentRepository repo) {
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(getPort());
connector.setConfidentialPort(getSecurePort());
connector.setRequestHeaderSize(16384);
Server jettyServer = new Server();
jettyServer.setConnectors(new Connector[] {connector});
ContextHandlerCollection contexts = new ContextHandlerCollection();
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(contexts);
addHandlers(repo, jettyServer, contexts);
jettyServer.setHandler(handlers);
jettyServer.setStopAtShutdown(true);
jettyServer.setGracefulShutdown(2000);
jettyServer.setSendDateHeader(true);
jettyServer.setSendServerVersion(true);
ComponentInfo info = new ComponentInfo(Server.class, "jetty");
repo.registerComponent(info, jettyServer);
repo.registerLifecycle(new ServerLifecycle(jettyServer));
return jettyServer;
}
示例6: startServer
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
@BeforeClass
public void startServer() throws Exception {
int port = 49152 + RandomUtils.nextInt(65535 - 49152);
String serverUrl = "http://localhost:" + port + "/jax";
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
_jettyServer = new Server();
_jettyServer.setConnectors(new Connector[]{connector});
ContextHandlerCollection contexts = new ContextHandlerCollection();
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(contexts);
WebAppContext ogWebAppContext = new WebAppContext("RemoteViewRunnerTest", "/");
org.springframework.core.io.Resource resource = new ClassPathResource("web-engine");
ogWebAppContext.setBaseResource(Resource.newResource(resource.getFile()));
DataViewRunnerResource viewRunnerResource = new DataViewRunnerResource(new TestViewRunner());
ComponentRepository repo = new ComponentRepository(ComponentLogger.Console.VERBOSE);
repo.getRestComponents().publishResource(viewRunnerResource);
repo.getRestComponents().publishHelper(new FudgeObjectBinaryConsumer());
repo.getRestComponents().publishHelper(new FudgeObjectBinaryProducer());
ogWebAppContext.setEventListeners(new EventListener[]{new ComponentRepositoryServletContextListener(repo)});
handlers.addHandler(ogWebAppContext);
_jettyServer.setHandler(handlers);
_jettyServer.start();
_remoteViewRunner = new RemoteViewRunner(URI.create(serverUrl));
}
示例7: start
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
/**
* 啟動jetty
*/
private static void start() throws Exception {
long bg = System.currentTimeMillis();
Server server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(PORT);
server.setConnectors(new Connector[] {connector});
WebAppContext webAppContext = new WebAppContext("src/main/webapp", "/");
webAppContext.setDescriptor("src/main/webapp/WEB-INF/web.xml");
webAppContext.setDisplayName("multilanguage");
WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext);
webAppContext.setClassLoader(classLoader);
webAppContext.setParentLoaderPriority(true);
server.setHandler(webAppContext);
System.out.println("ContextPath: " + webAppContext.getContextPath() + "; Descriptor: "
+ webAppContext.getDescriptor());
server.start();
long time = System.currentTimeMillis() - bg;
System.out.println("Jetty started in " + time + "ms");
}
示例8: start
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
public void start() throws Exception {
server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(port);
server.setConnectors(new Connector[]{connector});
RequestLogHandler requestLogHandler = new RequestLogHandler();
configureRequestLogImpl();
requestLogHandler.setRequestLog(requestLogImpl);
HandlerList handlers = new HandlerList();
handlers.addHandler(requestLogHandler);
handlers.addHandler(getRequestHandler());
server.setHandler(handlers);
server.start();
}
示例9: WebSocketServer
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
public WebSocketServer(int port, String rootDirPath, final MainWindow m, final Statement smt, final java.sql.Connection sqlcon) {
idCounter = 0;
connector = new SelectChannelConnector();
connector.setPort(port);
addConnector(connector);
wsHandler = new WebSocketHandler() {
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request,
String protocol) {
idCounter++;
System.out.printf("Protocol:%s\n", protocol);
return new MyWebSocket(idCounter, m, smt, sqlcon);
}
};
resHandler = new ResourceHandler();
resHandler.setDirectoriesListed(true);
resHandler.setResourceBase(rootDirPath);
wsHandler.setHandler(resHandler);
setHandler(wsHandler);
}
開發者ID:ryohashioka,項目名稱:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House,代碼行數:25,代碼來源:WebSocketServer.java
示例10: configureAndStart
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
/**
* Configures and starts a new Jetty server instance.
* This server is configured to answer incoming request in a dummy way.
* @param server the server that should be started
* @param httpPort the http server port
* @param httpsPort the https server port
* @param isPerfTest determines whether server is started in performance test mode or not
* @throws Exception
*/
public void configureAndStart(final Server server, final Integer httpPort, final Integer httpsPort, final Boolean isPerfTest) {
try {
SelectChannelConnector httpConnector = createHttpConnector(httpPort);
SslSelectChannelConnector sslConnector = createSslConnector(httpsPort);
server.setConnectors(new Connector[]{httpConnector, sslConnector});
if (isPerfTest) {
server.setHandler(new PerformanceTestHandler());
} else {
server.setHandler(new CompositeHandler(new ExampleHandler(new InputStreamConverter()), new SequenceTestHandler(new InputStreamConverter()), new PerformanceTestHandler()));
}
startServer(server);
server.join();
} catch (Exception e) {
throw new SystemException("server cannot be started", e);
}
}
示例11: start
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
public void start() throws Exception {
URI uri = new URI(agent.getRegistryURL());
server = new Server();
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
ServletHolder holder = new ServletHolder();
holder.setServlet(camelServlet);
context.addServlet(holder, "/*");
server.setHandler(context);
server.start();
int port = 80;
if( uri.getPort() >=0 ) {
port = uri.getPort();
}
connector = new SelectChannelConnector();
connector.setPort(port);
server.addConnector(connector);
connector.start();
}
示例12: setupJettyServer
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
private static Server setupJettyServer(VarOneConfiguration conf) {
AbstractConnector connector = new SelectChannelConnector();
// Set some timeout options to make debugging easier.
int timeout = 1000 * 30;
connector.setMaxIdleTime(timeout);
connector.setSoLingerTime(-1);
connector.setHost(conf.getServerAddress());
connector.setPort(conf.getServerPort());
final Server server = new Server();
server.addConnector(connector);
return server;
}
示例13: createServer
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
private Server createServer(final int port, final boolean multiThreaded) throws Exception {
final String testName = getClass().getSimpleName() + "_" + getName();
final DataCleanerConfiguration configuration = ClusterTestHelper.createConfiguration(testName, multiThreaded);
final SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
final WebAppContext webApp = new WebAppContext();
webApp.setAttribute(SlaveServlet.SERVLET_CONTEXT_ATTRIBUTE_CONFIGURATION, configuration);
webApp.setContextPath("/");
webApp.setWar("src/test/resources/jetty_webapp_folder");
final Server server = new Server();
server.addConnector(connector);
server.setHandler(webApp);
server.start();
System.out.println("Jetty server started on port " + port);
return server;
}
示例14: createServer
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
private Server createServer(int port, boolean multiThreaded) throws Exception {
final String testName = getClass().getSimpleName() + "_" + getName();
final AnalyzerBeansConfiguration configuration = ClusterTestHelper.createConfiguration(testName, multiThreaded);
final SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
final WebAppContext webApp = new WebAppContext();
webApp.setAttribute(SlaveServlet.SERVLET_CONTEXT_ATTRIBUTE_CONFIGURATION, configuration);
webApp.setContextPath("/");
webApp.setWar("src/test/resources/jetty_webapp_folder");
final Server server = new Server();
server.addConnector(connector);
server.setHandler(webApp);
server.start();
System.out.println("Jetty server started on port " + port);
return server;
}
示例15: start
import org.eclipse.jetty.server.nio.SelectChannelConnector; //導入依賴的package包/類
@Override
public void start() throws IOException
{
_server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(_port);
_server.setConnectors(new Connector[] { connector });
_server.setThreadPool(new QueuedThreadPool(_threadPoolSize));
ServletContextHandler root =
new ServletContextHandler(_server, _contextPath, ServletContextHandler.SESSIONS);
root.addServlet(new ServletHolder(_servlet), "/*");
try
{
_server.start();
}
catch (Exception e)
{
throw new IOException("Failed to start Jetty", e);
}
}