当前位置: 首页>>代码示例>>Java>>正文


Java NetworkListener类代码示例

本文整理汇总了Java中org.glassfish.grizzly.http.server.NetworkListener的典型用法代码示例。如果您正苦于以下问题:Java NetworkListener类的具体用法?Java NetworkListener怎么用?Java NetworkListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NetworkListener类属于org.glassfish.grizzly.http.server包,在下文中一共展示了NetworkListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerWebsocket

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
private void registerWebsocket() throws IOException {
  Configuration configuration = ConfigurationReader.INSTANCE.readConfiguration("core-site.xml");
  websocketServicePort = Integer
      .parseInt(configuration.get("events.server.websocket.port", "8082"));
  try {
    ServerSocket s = new ServerSocket(websocketServicePort);
    websocketServicePort = s.getLocalPort();
    s.close();
    waitTillSocketIsClosed(s);
    String webSocketserviceHost = java.net.InetAddress.getLocalHost().getHostAddress();
    final HttpServer server = HttpServer.createSimpleServer(null, webSocketserviceHost,
        websocketServicePort);
    for (NetworkListener listener : server.getListeners()) {
      listener.registerAddOn(new WebSocketAddOn());
    }
    WebSocketEngine.getEngine().register("", "/event-stream", new EventsSocketApplication());
    server.start();

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }, "Server-Showdown-Thread"));

  } catch (IOException | InterruptedException e) {
    throw new IllegalStateException("Failed to start api-service. name = events.service", e);
  }
}
 
开发者ID:DataRPM-Labs,项目名称:sigma-events,代码行数:30,代码来源:EventEngineAPIServiceStarter.java

示例2: startServer

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
public static HttpServer startServer() {
    HttpServer server = new HttpServer();
    server.addListener(new NetworkListener("grizzly", "0.0.0.0", 8080));

    final TCPNIOTransportBuilder transportBuilder = TCPNIOTransportBuilder.newInstance();
    //transportBuilder.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transportBuilder.setIOStrategy(SameThreadIOStrategy.getInstance());
    server.getListener("grizzly").setTransport(transportBuilder.build());
    final ResourceConfig rc = new ResourceConfig().packages("xyz.muetsch.jersey");
    rc.register(JacksonFeature.class);
    final ServerConfiguration config = server.getServerConfiguration();
    config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(rc, GrizzlyHttpContainer.class), "/rest/todo/");

    try {
        server.start();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return server;
}
 
开发者ID:n1try,项目名称:http-server-benchmarks,代码行数:22,代码来源:Main.java

示例3: configureThreadPools

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
private void configureThreadPools(final NetworkListener networkListener, final String poolNamePrefix,
        final int workerThreads, final int kernelThreads) {
    final TCPNIOTransport transport = networkListener.getTransport();

    if (transport.getKernelThreadPoolConfig() == null) {
        transport.setKernelThreadPoolConfig(ThreadPoolConfig.defaultConfig());
    }
    transport.getKernelThreadPoolConfig().setPoolName(poolNamePrefix + "-Kernel").setMaxPoolSize(kernelThreads)
            .setCorePoolSize(kernelThreads);
    transport.setSelectorRunnersCount(kernelThreads);

    if (transport.getWorkerThreadPoolConfig() == null) {
        transport.setWorkerThreadPoolConfig(ThreadPoolConfig.defaultConfig());
    }
    transport.getWorkerThreadPoolConfig().setPoolName(poolNamePrefix + "-Worker").setMaxPoolSize(workerThreads)
            .setCorePoolSize(workerThreads);
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:18,代码来源:RestServer.java

示例4: startServer

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
public static HttpServer startServer() throws IOException {
  
  String baseUri = ConfigProperties.getInstance().getProperty("BASE_URI");
  if(baseUri != null) {
    BASE_URI = baseUri; 
    LOG.info("base uri set to: "+baseUri);
  }
  final ResourceConfig rc = new ResourceConfig().packages("org.eu.eark.hsink");

  HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
      URI.create(BASE_URI), rc, false);

  ServerConfiguration serverConfig = server.getServerConfiguration();

  NetworkListener nL = server.getListener(server.getListeners().iterator()
      .next().getName()); // grizzly
  // disable server timeouts
  nL.setChunkingEnabled(true);
  nL.setDisableUploadTimeout(true);
  nL.getKeepAlive().setIdleTimeoutInSeconds(-1); // 256
  // server.getServerConfiguration();

  server.start();
  return server;
}
 
开发者ID:eark-project,项目名称:dm-hdfs-storage,代码行数:26,代码来源:Main.java

示例5: startServer

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
private HttpServer startServer(URI uri) throws IOException {
	ResourceConfig rc = new RallyeApplication();
	HttpServer serv = createServer(uri, rc); // Do NOT start the server just yet
	logger.info("Starting Grizzly server at " + uri);

	//Register Websocket Stuff
	WebSocketAddOn addon = new WebSocketAddOn();
	for(org.glassfish.grizzly.http.server.NetworkListener listener : serv.getListeners()) {
		logger.info("Registering websocket on "+listener);
		listener.registerAddOn(addon);
	}
	PushWebsocketApp.setData(RallyeBinder.data); //TODO: Remove this ugliness.
	AdminWebsocketApp.setData(RallyeBinder.data); //TODO: Remove this ugliness.
	WebSocketEngine.getEngine().register("/rallye", "/push", PushWebsocketApp.getInstance());
	WebSocketEngine.getEngine().register("/rallye","/admin", AdminWebsocketApp.getInstance());

	serv.start();  
	return serv;
}
 
开发者ID:jakobwenzel,项目名称:rallye-server,代码行数:20,代码来源:RallyeServer.java

示例6: TintServer

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
public TintServer(String host, Integer port, @Nullable File configFile,
            @Nullable Properties additionalProperties) {
        LOGGER.info("starting " + host + "\t" + port + " (" + new Date() + ")...");

        int timeoutInSeconds = -1;

        try {
            // Load the pipeline
            TintPipeline pipeline = new TintPipeline();
            pipeline.loadDefaultProperties();
            pipeline.loadPropertiesFromFile(configFile);
            pipeline.addProperties(additionalProperties);

            // todo: parametrize this!
//            pipeline.loadSerializers();

            pipeline.load();

            LOGGER.info("Pipeline loaded");

            final HttpServer httpServer = new HttpServer();
            NetworkListener nl = new NetworkListener("tint-server", host, port);
            httpServer.addListener(nl);

            TintHandler tintHandler = new TintHandler(pipeline);
            tintHandler.setRequestURIEncoding(Charset.forName("UTF-8"));

            httpServer.getServerConfiguration().setSessionTimeoutSeconds(timeoutInSeconds);
            httpServer.getServerConfiguration().setMaxPostSize(4194304);
            httpServer.getServerConfiguration().addHttpHandler(tintHandler, "/tint");

            httpServer.start();
            Thread.currentThread().join();
        } catch (Exception e) {
            LOGGER.error("error running " + host + ":" + port);
            e.printStackTrace();
        }
    }
 
开发者ID:dhfbk,项目名称:tint,代码行数:39,代码来源:TintServer.java

示例7: doInit

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
private void doInit(MessageCenter mc) {
	LongPollServer poll = new LongPollServer(wsContext);
	AdminServlet admin = new AdminServlet(wsContext);
	this.wsAddOn = new WSAddOn(wsContext);
	this.addHandler(admin, "/admin/*");
	this.addHandler(poll, "/poll/*");
	for (NetworkListener ls : server.getListeners()) {
		ls.registerAddOn(wsAddOn);
	}
}
 
开发者ID:coderczp,项目名称:HtmlSocket,代码行数:11,代码来源:PullServer.java

示例8: createSSLListener

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
private NetworkListener createSSLListener(int port, SSLProperties sslProperties) {

		SSLConfigurationBuilder sslBuilder = new SSLConfigurationBuilder();
		NetworkListener listener = new NetworkListener("grizzly", "0.0.0.0", Integer.valueOf(port));
		listener.getFileCache().setEnabled(false);

		listener.setSecure(true);
		listener.setSSLEngineConfig(sslBuilder.build(sslProperties));

		return listener;
	}
 
开发者ID:aol,项目名称:micro-server,代码行数:12,代码来源:GrizzlyApplication.java

示例9: startServer

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
@Override
protected void startServer(int port, Action<ServerWebSocket> websocketAction) throws Exception {
  server = HttpServer.createSimpleServer(null, port);
  NetworkListener listener = server.getListener("grizzly");
  listener.registerAddOn(new WebSocketAddOn());
  WebSocketEngine.getEngine().register("", TEST_URI, new AsityWebSocketApplication()
    .onwebsocket(websocketAction));
  server.start();
}
 
开发者ID:cettia,项目名称:asity,代码行数:10,代码来源:GrizzlyServerWebSocketTest.java

示例10: setup

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
@Override
public void setup(NetworkListener networkListener, FilterChainBuilder builder) {

    // Get the index of HttpCodecFilter in the HttpServer filter chain
    final int httpCodecFilterIdx = builder.indexOfType(HttpServerFilter.class);

    if (httpCodecFilterIdx >= 0) {
        // Insert the WebSocketFilter right after HttpCodecFilter
        HttpServerFilter originalFilter = (HttpServerFilter) builder.get(httpCodecFilterIdx);
        builder.set(httpCodecFilterIdx, new ContentLengthFilter(originalFilter));
    }
}
 
开发者ID:bouncestorage,项目名称:swiftproxy,代码行数:13,代码来源:ContentLengthAddOn.java

示例11: main

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
public static void main(String[] args) {

        OSM osm = new OSM(args[0]);

        if (args.length > 1 && args[1].startsWith("--load")) {
            osm.intersectionDetection = true;
            osm.tileIndexing = true;
            if (args[1].equalsIgnoreCase("--loadurl")) {
                osm.readFromUrl(args[2]);
            } else {
                osm.readFromFile(args[2]);
            }
            // TODO catch writing exceptions here and shut down properly, closing OSM database.
            LOG.info("Done populating OSM database.");
            osm.close();
            return;
        }

        Thread updateThread = Updater.spawnUpdateThread(osm);

        LOG.info("Starting VEX HTTP server on port {} of interface {}", PORT, BIND_ADDRESS);
        HttpServer httpServer = new HttpServer();
        httpServer.addListener(new NetworkListener("vanilla_extract", BIND_ADDRESS, PORT));
        // Bypass Jersey etc. and add a low-level Grizzly handler.
        // As in servlets, * is needed in base path to identify the "rest" of the path.
        httpServer.getServerConfiguration().addHttpHandler(new VexHttpHandler(osm), "/*");
        try {
            httpServer.start();
            LOG.info("VEX server running.");
            Thread.currentThread().join();
            updateThread.interrupt();
        } catch (BindException be) {
            LOG.error("Cannot bind to port {}. Is it already in use?", PORT);
        } catch (IOException ioe) {
            LOG.error("IO exception while starting server.");
        } catch (InterruptedException ie) {
            LOG.info("Interrupted, shutting down.");
        }
        httpServer.shutdown();
    }
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:41,代码来源:VanillaExtract.java

示例12: start

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
@PostConstruct
public void start() {
    server = new HttpServer();
    final NetworkListener listener = new NetworkListener("grizzly", "localhost", new PortRange(port));
    server.addListener(listener);

    try {
        server.start();
        logger.info("Test server running on {}", port);
    } catch (final Throwable e) {
        logger.error("Error with test server", e);
    }
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-mint,代码行数:14,代码来源:ContainerWrapper.java

示例13: start

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
public void start(final int servicePort, final int statusPort, final String bindAddress) throws IOException {
    final URI baseUri = UriBuilder.fromUri("http://" + bindAddress).port(servicePort).build();
    logger.info("Configuring REST server on: " + baseUri.toString());
    httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
    enableAutoGenerationOfSwaggerSpecification();
    configureThreadPools(httpServer.getListener("grizzly"), SERVICE_POOL_NAME_PREFIX, SERVICE_WORKER_THREADS,
            SERVICE_KERNEL_THREADS);
    final NetworkListener statusPortListener = new NetworkListener("status", baseUri.getHost(), statusPort);
    configureThreadPools(statusPortListener, STATUS_POOL_NAME_PREFIX, STATUS_WORKER_THREADS, STATUS_KERNEL_THREADS);
    httpServer.addListener(statusPortListener);
    logger.info("Starting REST server; servicePort:[" + servicePort + "] statusPort:[" + statusPort + "]");
    httpServer.start();
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:14,代码来源:RestServer.java

示例14: startServer

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
@Override
protected void startServer() throws Exception {
    server = HttpServer.createSimpleServer(null, port);
    NetworkListener listener = server.getListener("grizzly");
    listener.registerAddOn(new WebSocketAddOn());
    WebSocketEngine.getEngine().register("", "/test", new VibeWebSocketApplication().onwebsocket(performer.serverAction()));
    server.start();
}
 
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:9,代码来源:GrizzlyServerWebSocketTest.java

示例15: LensServer

import org.glassfish.grizzly.http.server.NetworkListener; //导入依赖的package包/类
/**
 * Instantiates a new lens server.
 *
 * @param conf the conf
 * @throws IOException Signals that an I/O exception has occurred.
 */
private LensServer(HiveConf conf) throws IOException {
  startServices(conf);
  String baseURI = conf.get(LensConfConstants.SERVER_BASE_URL, LensConfConstants.DEFAULT_SERVER_BASE_URL);
  HttpServer server = GrizzlyHttpServerFactory.createHttpServer(UriBuilder.fromUri(baseURI).build(), getApp(),
    false);

  int corePoolSize = conf.getInt(LensConfConstants.GRIZZLY_CORE_POOL_SIZE,
          LensConfConstants.DEFAULT_GRIZZLY_CORE_POOL_SIZE);
  int maxPoolSize = conf.getInt(LensConfConstants.GRIZZLY_MAX_POOL_SIZE,
          LensConfConstants.DEFAULT_GRIZZLY_MAX_POOL_SIZE);

  ThreadPoolConfig config = ThreadPoolConfig.defaultConfig();
  config.setPoolName("lensserver-pool");
  config.setCorePoolSize(corePoolSize);
  config.setMaxPoolSize(maxPoolSize);
  config.setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d")
    .setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());

  NetworkListener listener = server.getListeners().iterator().next();
  listener.getTransport().setWorkerThreadPoolConfig(config);
  serverList.add(server);

  WebappContext adminCtx = new WebappContext("admin", "");
  MetricsServiceImpl metricsService = LensServices.get().getService(MetricsService.NAME);
  adminCtx
    .setAttribute("com.codahale.metrics.servlets.MetricsServlet.registry", (metricsService.getMetricRegistry()));
  adminCtx.setAttribute("com.codahale.metrics.servlets.HealthCheckServlet.registry", metricsService.getHealthCheck());
  final ServletRegistration sgMetrics = adminCtx.addServlet("admin", new AdminServlet());
  sgMetrics.addMapping("/admin/*");
  adminCtx.deploy(server);
}
 
开发者ID:apache,项目名称:lens,代码行数:38,代码来源:LensServer.java


注:本文中的org.glassfish.grizzly.http.server.NetworkListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。