Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  private void configureMonitoring(final NetworkListener listener) {
    final Transport transport = listener.getTransport();

    final MonitoringConfig<TransportProbe> transportMonitoringCfg = transport.getMonitoringConfig();
    final MonitoringConfig<ConnectionProbe> connectionMonitoringCfg =
        transport.getConnectionMonitoringConfig();
    final MonitoringConfig<MemoryProbe> memoryMonitoringCfg =
        transport.getMemoryManager().getMonitoringConfig();
    final MonitoringConfig<ThreadPoolProbe> threadPoolMonitoringCfg =
        transport.getThreadPoolMonitoringConfig();

    transportMonitoringCfg.addProbes(
        serverConfig.getMonitoringConfig().getTransportConfig().getProbes());
    connectionMonitoringCfg.addProbes(
        serverConfig.getMonitoringConfig().getConnectionConfig().getProbes());
    memoryMonitoringCfg.addProbes(serverConfig.getMonitoringConfig().getMemoryConfig().getProbes());
    threadPoolMonitoringCfg.addProbes(
        serverConfig.getMonitoringConfig().getThreadPoolConfig().getProbes());
  }
Exemplo n.º 2
0
  @Override
  public ThreadPoolConfig createDefaultWorkerPoolConfig(final Transport transport) {

    final ThreadPoolConfig config = ThreadPoolConfig.defaultConfig().copy();
    final int coresCount = Runtime.getRuntime().availableProcessors();
    config.setPoolName("Grizzly-worker");
    config.setCorePoolSize(coresCount * 2);
    config.setMaxPoolSize(coresCount * 2);
    config.setMemoryManager(transport.getMemoryManager());
    return config;
  }
Exemplo n.º 3
0
  private void configureListener(final NetworkListener listener) {
    FilterChain chain = listener.getFilterChain();
    if (chain == null) {
      final FilterChainBuilder builder = FilterChainBuilder.newInstance();
      builder.add(new TransportFilter());
      if (listener.isSecure()) {
        SSLEngineConfigurator sslConfig = listener.getSslEngineConfig();
        if (sslConfig == null) {
          sslConfig =
              new SSLEngineConfigurator(SSLContextConfigurator.DEFAULT_CONFIG, false, false, false);
          listener.setSSLEngineConfig(sslConfig);
        }
        final SSLBaseFilter filter = new SSLBaseFilter(sslConfig);
        builder.add(filter);
      }
      final int maxHeaderSize =
          listener.getMaxHttpHeaderSize() == -1
              ? org.glassfish.grizzly.http.HttpServerFilter.DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE
              : listener.getMaxHttpHeaderSize();

      // Passing null value for the delayed executor, because IdleTimeoutFilter should
      // handle idle connections for us
      final org.glassfish.grizzly.http.HttpServerFilter httpServerCodecFilter =
          new org.glassfish.grizzly.http.HttpServerFilter(
              listener.isChunkingEnabled(),
              maxHeaderSize,
              null,
              listener.getKeepAliveConfig(),
              null,
              listener.getMaxRequestHeaders(),
              listener.getMaxResponseHeaders());
      final Set<ContentEncoding> contentEncodings = configureCompressionEncodings(listener);
      for (ContentEncoding contentEncoding : contentEncodings) {
        httpServerCodecFilter.addContentEncoding(contentEncoding);
      }

      httpServerCodecFilter
          .getMonitoringConfig()
          .addProbes(serverConfig.getMonitoringConfig().getHttpConfig().getProbes());
      builder.add(httpServerCodecFilter);

      builder.add(
          new IdleTimeoutFilter(
              delayedExecutor,
              listener.getKeepAliveConfig().getIdleTimeoutInSeconds(),
              TimeUnit.SECONDS));

      final Transport transport = listener.getTransport();
      final FileCache fileCache = listener.getFileCache();
      fileCache.initialize(delayedExecutor);
      final FileCacheFilter fileCacheFilter = new FileCacheFilter(fileCache);
      fileCache
          .getMonitoringConfig()
          .addProbes(serverConfig.getMonitoringConfig().getFileCacheConfig().getProbes());
      builder.add(fileCacheFilter);

      final ServerFilterConfiguration config = new ServerFilterConfiguration(serverConfig);

      if (listener.isSendFileExplicitlyConfigured()) {
        config.setSendFileEnabled(listener.isSendFileEnabled());
        fileCache.setFileSendEnabled(listener.isSendFileEnabled());
      }

      if (listener.getBackendConfig() != null) {
        config.setBackendConfiguration(listener.getBackendConfig());
      }

      if (listener.getDefaultErrorPageGenerator() != null) {
        config.setDefaultErrorPageGenerator(listener.getDefaultErrorPageGenerator());
      }

      config.setTraceEnabled(config.isTraceEnabled() || listener.isTraceEnabled());

      config.setMaxFormPostSize(listener.getMaxFormPostSize());
      config.setMaxBufferedPostSize(listener.getMaxBufferedPostSize());

      final HttpServerFilter httpServerFilter = new HttpServerFilter(config, delayedExecutor);
      httpServerFilter.setHttpHandler(httpHandlerChain);

      httpServerFilter
          .getMonitoringConfig()
          .addProbes(serverConfig.getMonitoringConfig().getWebServerConfig().getProbes());

      builder.add(httpServerFilter);
      chain = builder.build();

      final AddOn[] addons = listener.getAddOnSet().getArray();
      if (addons != null) {
        for (AddOn addon : addons) {
          addon.setup(listener, chain);
        }
      }

      listener.setFilterChain(chain);
      final int transactionTimeout = listener.getTransactionTimeout();
      if (transactionTimeout >= 0) {
        ThreadPoolConfig threadPoolConfig = transport.getWorkerThreadPoolConfig();

        if (threadPoolConfig != null) {
          threadPoolConfig.setTransactionTimeout(
              delayedExecutor, transactionTimeout, TimeUnit.SECONDS);
        }
      }
    }
    configureMonitoring(listener);
  }