protected ThreadPoolConfig configureThreadPoolConfig(
      final NetworkListener networkListener, final ThreadPool threadPool) {

    final int maxQueueSize =
        threadPool.getMaxQueueSize() == null
            ? Integer.MAX_VALUE
            : Integer.parseInt(threadPool.getMaxQueueSize());
    final int minThreads = Integer.parseInt(threadPool.getMinThreadPoolSize());
    final int maxThreads = Integer.parseInt(threadPool.getMaxThreadPoolSize());
    final int timeout = Integer.parseInt(threadPool.getIdleThreadTimeoutSeconds());
    final ThreadPoolConfig poolConfig = ThreadPoolConfig.defaultConfig();
    poolConfig.setPoolName(networkListener.getName());
    poolConfig.setCorePoolSize(minThreads);
    poolConfig.setMaxPoolSize(maxThreads);
    poolConfig.setQueueLimit(maxQueueSize);

    // we specify the classloader that loaded this class to ensure
    // we present the same initial classloader no matter what mode
    // GlassFish is being run in.
    // See http://java.net/jira/browse/GLASSFISH-19639
    poolConfig.setInitialClassLoader(this.getClass().getClassLoader());

    poolConfig.setKeepAliveTime(timeout < 0 ? Long.MAX_VALUE : timeout, TimeUnit.SECONDS);
    if (transactionTimeoutMillis > 0 && !Utils.isDebugVM()) {
      poolConfig.setTransactionTimeout(
          obtainDelayedExecutor(), transactionTimeoutMillis, TimeUnit.MILLISECONDS);
    }

    return poolConfig;
  }
  protected void configureTransport(
      final NetworkListener networkListener,
      final Transport transportConfig,
      final FilterChainBuilder filterChainBuilder) {

    final String transportClassName = transportConfig.getClassname();
    if (TCPNIOTransport.class.getName().equals(transportClassName)) {
      transport = configureTCPTransport(transportConfig);
    } else if (UDPNIOTransport.class.getName().equals(transportClassName)) {
      transport = configureUDPTransport();
    } else {
      throw new GrizzlyConfigException("Unsupported transport type " + transportConfig.getName());
    }

    String selectorName = transportConfig.getSelectionKeyHandler();
    if (selectorName != null) {
      if (getSelectionKeyHandlerByName(selectorName, transportConfig) != null) {
        if (LOGGER.isLoggable(Level.INFO)) {
          LOGGER.warning(
              "Element, selection-key-handler, has been deprecated and is effectively ignored by the runtime.");
        }
      }
    }

    if (!Transport.BYTE_BUFFER_TYPE.equalsIgnoreCase(transportConfig.getByteBufferType())) {
      transport.setMemoryManager(
          new ByteBufferManager(
              true,
              AbstractMemoryManager.DEFAULT_MAX_BUFFER_SIZE,
              ByteBufferManager.DEFAULT_SMALL_BUFFER_SIZE));
    }

    final int acceptorThreads = Integer.parseInt(transportConfig.getAcceptorThreads());
    transport.setSelectorRunnersCount(acceptorThreads);

    final int readSize = Integer.parseInt(transportConfig.getSocketReadBufferSize());
    if (readSize > 0) {
      transport.setReadBufferSize(readSize);
    }

    final int writeSize = Integer.parseInt(transportConfig.getSocketWriteBufferSize());
    if (writeSize > 0) {
      transport.setWriteBufferSize(writeSize);
    }

    final ThreadPoolConfig kernelThreadPoolConfig = transport.getKernelThreadPoolConfig();

    kernelThreadPoolConfig.setPoolName(networkListener.getName() + "-kernel");
    if (acceptorThreads > 0) {
      kernelThreadPoolConfig.setCorePoolSize(acceptorThreads).setMaxPoolSize(acceptorThreads);
    }

    transport.setIOStrategy(loadIOStrategy(transportConfig.getIoStrategy()));
    transport.setNIOChannelDistributor(
        new RoundRobinConnectionDistributor(
            transport, Boolean.parseBoolean(transportConfig.getDedicatedAcceptorEnabled())));

    filterChainBuilder.add(new TransportFilter());
  }
  protected void configureSpdySupport(
      final ServiceLocator locator,
      final NetworkListener listener,
      final Spdy spdyElement,
      final FilterChainBuilder builder,
      final boolean secure) {
    if (spdyElement != null && spdyElement.getEnabled()) {

      boolean isNpnMode =
          spdyElement.getMode() == null || "npn".equalsIgnoreCase(spdyElement.getMode());

      // Spdy without NPN is supported, but warn that there may
      // be consequences to this configuration.
      if (!secure && isNpnMode) {
        LOGGER.log(
            Level.WARNING,
            "SSL is not enabled for listener {0}.  SPDY support will be enabled, but will not be secured.  Some clients may not be able to use SPDY in this configuration.",
            listener.getName());
      }

      // first try to lookup a service appropriate for the mode
      // that has been configured.
      AddOn spdyAddon = locator.getService(AddOn.class, "spdy");

      // if no service was found, attempt to load via reflection.
      if (spdyAddon == null) {
        Class<?> spdyMode;
        try {
          spdyMode = Utils.loadClass("org.glassfish.grizzly.spdy.SpdyMode");
        } catch (ClassNotFoundException cnfe) {
          if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine(
                "Unable to load class org.glassfish.grizzly.spdy.SpdyMode.  SPDY support cannot be enabled");
          }
          return;
        }
        Object[] enumConstants = spdyMode.getEnumConstants();
        Object mode = ((isNpnMode) ? enumConstants[1] : enumConstants[0]);
        spdyAddon = loadAddOn("org.glassfish.grizzly.spdy.SpdyAddOn", new Class[] {spdyMode}, mode);
      }

      if (spdyAddon != null) {
        // Configure SpdyAddOn
        configureElement(locator, listener, spdyElement, spdyAddon);

        // Spdy requires access to more information compared to the other addons
        // that are currently leveraged.  As such, we'll need to mock out a
        // Grizzly NetworkListener to pass to the addon.  This mock object will
        // only provide the information necessary for the addon to operate.
        // It will be important to keep this mock in sync with the details the
        // addon requires.
        spdyAddon.setup(createMockListener(), builder);
        isSpdyEnabled = true;
      }
    }
  }
示例#4
0
  @Test
  public void rawAttributeTest() throws NoSuchMethodException {

    String address = listener.getAddress();

    Dom raw = Dom.unwrap(listener);
    Attribute attr = raw.getProxyType().getMethod("getAddress").getAnnotation(Attribute.class);
    assertEquals(attr.defaultValue(), address);

    assertEquals(raw.attribute("address"), address);
    assertEquals(raw.rawAttribute("address"), address);
  }
示例#5
0
  @Override
  public void create(final CreateSsl command, ActionReport report) {

    NetworkConfig netConfig = command.config.getNetworkConfig();
    // ensure we have the specified listener
    NetworkListener listener = netConfig.getNetworkListener(command.listenerId);
    Protocol httpProtocol;
    try {
      if (listener == null) {
        report.setMessage(
            WebContainer.rb.getString(
                MessageFormat.format(CREATE_SSL_HTTP_NOT_FOUND, command.listenerId)));
        httpProtocol = command.findOrCreateProtocol(command.listenerId);
      } else {
        httpProtocol = listener.findHttpProtocol();
        Ssl ssl = httpProtocol.getSsl();
        if (ssl != null) {
          report.setMessage(
              WebContainer.rb.getString(
                  MessageFormat.format(CREATE_SSL_HTTP_ALREADY_EXISTS, command.listenerId)));
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          return;
        }
      }
      ConfigSupport.apply(
          new SingleConfigCode<Protocol>() {
            public Object run(Protocol param) throws TransactionFailure {
              Ssl newSsl = param.createChild(Ssl.class);
              command.populateSslElement(newSsl);
              param.setSsl(newSsl);
              return newSsl;
            }
          },
          httpProtocol);

    } catch (TransactionFailure e) {
      command.reportError(report, e);
    }
    command.reportSuccess(report);
  }
示例#6
0
  @Override
  public void delete(DeleteSsl command, ActionReport report) {

    NetworkConfig netConfig = command.config.getNetworkConfig();
    NetworkListener networkListener = netConfig.getNetworkListener(command.listenerId);

    if (networkListener == null) {
      report.setMessage(
          WebContainer.rb.getString(
              MessageFormat.format(DELETE_SSL_HTTP_LISTENER_NOT_FOUND, command.listenerId)));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }

    Protocol protocol = networkListener.findHttpProtocol();
    if (protocol.getSsl() == null) {
      report.setMessage(
          WebContainer.rb.getString(
              MessageFormat.format(DELETE_SSL_ELEMENT_DOES_NOT_EXIST, command.listenerId)));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }

    try {
      ConfigSupport.apply(
          new SingleConfigCode<Protocol>() {
            public Object run(Protocol param) {
              param.setSsl(null);
              return null;
            }
          },
          networkListener.findHttpProtocol());
    } catch (TransactionFailure e) {
      command.reportError(report, e);
    }
  }
  protected void configureAjpSupport(
      final ServiceLocator habitat,
      final NetworkListener networkListener,
      final Http http,
      final FilterChainBuilder filterChainBuilder) {

    final boolean jkSupportEnabled =
        http.getJkEnabled() != null
            ? Boolean.parseBoolean(http.getJkEnabled())
            : Boolean.parseBoolean(networkListener.getJkEnabled());

    if (jkSupportEnabled) {
      final AddOn ajpAddOn = loadAddOn(habitat, "ajp", "org.glassfish.grizzly.http.ajp.AjpAddOn");
      if (ajpAddOn != null) {
        configureElement(habitat, networkListener, http, ajpAddOn);
        ajpAddOn.setup(null, filterChainBuilder);
        isAjpEnabled = true;
      }
    }
  }
  // TODO: Must get the information from domain.xml Config objects.
  // TODO: Pending Grizzly issue 54
  @Override
  public void configure(final ServiceLocator habitat, final NetworkListener networkListener)
      throws IOException {
    setName(networkListener.getName());
    setAddress(InetAddress.getByName(networkListener.getAddress()));
    setPort(Integer.parseInt(networkListener.getPort()));

    final FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();

    configureTransport(networkListener, networkListener.findTransport(), filterChainBuilder);

    configureProtocol(habitat, networkListener, networkListener.findProtocol(), filterChainBuilder);

    configureThreadPool(habitat, networkListener, networkListener.findThreadPool());

    rootFilterChain = filterChainBuilder.build();
    transport.setProcessor(rootFilterChain);
  }