/**
   * @param server The server this connector will be added to. Must not be null.
   * @param executor An executor for this connector or null to use the servers executor
   * @param scheduler A scheduler for this connector or null to either a {@link Scheduler} set as a
   *     server bean or if none set, then a new {@link TimerScheduler} instance.
   * @param pool A buffer pool for this connector or null to either a {@link ByteBufferPool} set as
   *     a server bean or none set, the new {@link ArrayByteBufferPool} instance.
   * @param acceptors the number of acceptor threads to use, or 0 for a default value.
   * @param factories The Connection Factories to use.
   */
  public AbstractConnector(
      Server server,
      Executor executor,
      Scheduler scheduler,
      ByteBufferPool pool,
      int acceptors,
      ConnectionFactory... factories) {
    _server = server;
    _executor = executor != null ? executor : _server.getThreadPool();
    if (scheduler == null) scheduler = _server.getBean(Scheduler.class);
    _scheduler = scheduler != null ? scheduler : new TimerScheduler();
    if (pool == null) pool = _server.getBean(ByteBufferPool.class);
    _byteBufferPool = pool != null ? pool : new ArrayByteBufferPool();

    addBean(_server, false);
    addBean(_executor);
    if (executor == null) unmanage(_executor); // inherited from server
    addBean(_scheduler);
    addBean(_byteBufferPool);

    for (ConnectionFactory factory : factories) addConnectionFactory(factory);

    if (acceptors <= 0) acceptors = Math.max(1, (Runtime.getRuntime().availableProcessors()) / 2);
    if (acceptors > 2 * Runtime.getRuntime().availableProcessors())
      LOG.warn("Acceptors should be <= 2*availableProcessors: " + this);
    _acceptors = new Thread[acceptors];
  }
Пример #2
0
  @Test
  public void testStandardTestWar() throws Exception {
    PreconfigureStandardTestWar.main(new String[] {});

    WebDescriptor descriptor =
        new WebDescriptor(
            Resource.newResource(
                "./target/test-standard-preconfigured/WEB-INF/quickstart-web.xml"));
    descriptor.setValidating(true);
    descriptor.parse();
    Node node = descriptor.getRoot();
    assertThat(node, Matchers.notNullValue());

    System.setProperty("jetty.home", "target");

    // war file or dir to start
    String war = "target/test-standard-preconfigured";

    // optional jetty context xml file to configure the webapp
    Resource contextXml = Resource.newResource("src/test/resources/test.xml");

    Server server = new Server(0);

    QuickStartWebApp webapp = new QuickStartWebApp();
    webapp.setAutoPreconfigure(true);
    webapp.setWar(war);
    webapp.setContextPath("/");

    // apply context xml file
    if (contextXml != null) {
      // System.err.println("Applying "+contextXml);
      XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
      xmlConfiguration.configure(webapp);
    }

    server.setHandler(webapp);

    server.start();

    URL url =
        new URL(
            "http://127.0.0.1:"
                + server.getBean(NetworkConnector.class).getLocalPort()
                + "/test/dump/info");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    assertEquals(200, connection.getResponseCode());
    assertThat(
        IO.toString((InputStream) connection.getContent()),
        Matchers.containsString("Dump Servlet"));

    server.stop();
  }