Search in sources :

Example 1 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project dropwizard by dropwizard.

the class HttpConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, ThreadPool threadPool) {
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig);
    final Scheduler scheduler = new ScheduledExecutorScheduler();
    final ByteBufferPool bufferPool = buildBufferPool();
    return buildConnector(server, scheduler, bufferPool, name, threadPool, new Jetty93InstrumentedConnectionFactory(httpConnectionFactory, metrics.timer(httpConnections())));
}
Also used : ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Scheduler(org.eclipse.jetty.util.thread.Scheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 2 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class HttpConnectionOverFCGI method acquireBuffer.

private ByteBuffer acquireBuffer() {
    HttpClient client = destination.getHttpClient();
    ByteBufferPool bufferPool = client.getByteBufferPool();
    return bufferPool.acquire(client.getResponseBufferSize(), true);
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) HttpClient(org.eclipse.jetty.client.HttpClient)

Example 3 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class ClientGeneratorTest method testGenerateRequestContent.

private void testGenerateRequestContent(final int contentLength) throws Exception {
    ByteBuffer content = ByteBuffer.allocate(contentLength);
    ByteBufferPool byteBufferPool = new MappedByteBufferPool();
    ClientGenerator generator = new ClientGenerator(byteBufferPool);
    final int id = 13;
    Generator.Result result = generator.generateRequestContent(id, content, true, null);
    final AtomicInteger totalLength = new AtomicInteger();
    ServerParser parser = new ServerParser(new ServerParser.Listener.Adapter() {

        @Override
        public boolean onContent(int request, FCGI.StreamType stream, ByteBuffer buffer) {
            Assert.assertEquals(id, request);
            totalLength.addAndGet(buffer.remaining());
            return false;
        }

        @Override
        public void onEnd(int request) {
            Assert.assertEquals(id, request);
            Assert.assertEquals(contentLength, totalLength.get());
        }
    });
    for (ByteBuffer buffer : result.getByteBuffers()) {
        parser.parse(buffer);
        Assert.assertFalse(buffer.hasRemaining());
    }
    // Parse again one byte at a time
    for (ByteBuffer buffer : result.getByteBuffers()) {
        buffer.flip();
        while (buffer.hasRemaining()) parser.parse(ByteBuffer.wrap(new byte[] { buffer.get() }));
        Assert.assertFalse(buffer.hasRemaining());
    }
}
Also used : MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) ByteBuffer(java.nio.ByteBuffer) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerParser(org.eclipse.jetty.fcgi.parser.ServerParser) FCGI(org.eclipse.jetty.fcgi.FCGI)

Example 4 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class ClientParserTest method testParseSmallResponseContent.

@Test
public void testParseSmallResponseContent() throws Exception {
    final int id = 13;
    HttpFields fields = new HttpFields();
    ByteBuffer content = ByteBuffer.wrap(new byte[1024]);
    final int contentLength = content.remaining();
    final int code = 200;
    final String contentTypeName = "Content-Length";
    final String contentTypeValue = String.valueOf(contentLength);
    fields.put(contentTypeName, contentTypeValue);
    ByteBufferPool byteBufferPool = new MappedByteBufferPool();
    ServerGenerator generator = new ServerGenerator(byteBufferPool);
    Generator.Result result1 = generator.generateResponseHeaders(id, code, "OK", fields, null);
    Generator.Result result2 = generator.generateResponseContent(id, content, true, false, null);
    final AtomicInteger verifier = new AtomicInteger();
    ClientParser parser = new ClientParser(new ClientParser.Listener.Adapter() {

        @Override
        public boolean onContent(int request, FCGI.StreamType stream, ByteBuffer buffer) {
            Assert.assertEquals(id, request);
            Assert.assertEquals(contentLength, buffer.remaining());
            verifier.addAndGet(2);
            return false;
        }

        @Override
        public void onEnd(int request) {
            Assert.assertEquals(id, request);
            verifier.addAndGet(3);
        }
    });
    for (ByteBuffer buffer : result1.getByteBuffers()) {
        parser.parse(buffer);
        Assert.assertFalse(buffer.hasRemaining());
    }
    for (ByteBuffer buffer : result2.getByteBuffers()) {
        parser.parse(buffer);
        Assert.assertFalse(buffer.hasRemaining());
    }
    Assert.assertEquals(5, verifier.get());
}
Also used : MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) ServerGenerator(org.eclipse.jetty.fcgi.generator.ServerGenerator) ByteBuffer(java.nio.ByteBuffer) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpFields(org.eclipse.jetty.http.HttpFields) Generator(org.eclipse.jetty.fcgi.generator.Generator) ServerGenerator(org.eclipse.jetty.fcgi.generator.ServerGenerator) FCGI(org.eclipse.jetty.fcgi.FCGI) Test(org.junit.Test)

Example 5 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class ClientParserTest method testParseResponseHeaders.

@Test
public void testParseResponseHeaders() throws Exception {
    final int id = 13;
    HttpFields fields = new HttpFields();
    final int statusCode = 200;
    final String statusMessage = "OK";
    final String contentTypeName = "Content-Type";
    final String contentTypeValue = "text/html;charset=utf-8";
    fields.put(contentTypeName, contentTypeValue);
    ByteBufferPool byteBufferPool = new MappedByteBufferPool();
    ServerGenerator generator = new ServerGenerator(byteBufferPool);
    Generator.Result result = generator.generateResponseHeaders(id, statusCode, statusMessage, fields, null);
    // Use the fundamental theorem of arithmetic to test the results.
    // This way we know onHeader() has been called the right number of
    // times with the right arguments, and so onHeaders().
    final int[] primes = new int[] { 2, 3, 5 };
    int value = 1;
    for (int prime : primes) value *= prime;
    final AtomicInteger params = new AtomicInteger(1);
    ClientParser parser = new ClientParser(new ClientParser.Listener.Adapter() {

        @Override
        public void onBegin(int request, int code, String reason) {
            Assert.assertEquals(statusCode, code);
            Assert.assertEquals(statusMessage, reason);
            params.set(params.get() * primes[0]);
        }

        @Override
        public void onHeader(int request, HttpField field) {
            Assert.assertEquals(id, request);
            switch(field.getName()) {
                case contentTypeName:
                    Assert.assertEquals(contentTypeValue, field.getValue());
                    params.set(params.get() * primes[1]);
                    break;
                default:
                    break;
            }
        }

        @Override
        public void onHeaders(int request) {
            Assert.assertEquals(id, request);
            params.set(params.get() * primes[2]);
        }
    });
    for (ByteBuffer buffer : result.getByteBuffers()) {
        parser.parse(buffer);
        Assert.assertFalse(buffer.hasRemaining());
    }
    Assert.assertEquals(value, params.get());
}
Also used : MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) ServerGenerator(org.eclipse.jetty.fcgi.generator.ServerGenerator) ByteBuffer(java.nio.ByteBuffer) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpField(org.eclipse.jetty.http.HttpField) HttpFields(org.eclipse.jetty.http.HttpFields) Generator(org.eclipse.jetty.fcgi.generator.Generator) ServerGenerator(org.eclipse.jetty.fcgi.generator.ServerGenerator) Test(org.junit.Test)

Aggregations

ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)72 ByteBuffer (java.nio.ByteBuffer)53 Test (org.junit.Test)51 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)40 Parser (org.eclipse.jetty.http2.parser.Parser)37 HttpFields (org.eclipse.jetty.http.HttpFields)29 MetaData (org.eclipse.jetty.http.MetaData)24 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)21 HeaderGenerator (org.eclipse.jetty.http2.generator.HeaderGenerator)21 PrefaceFrame (org.eclipse.jetty.http2.frames.PrefaceFrame)20 SettingsFrame (org.eclipse.jetty.http2.frames.SettingsFrame)20 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)19 OutputStream (java.io.OutputStream)16 Socket (java.net.Socket)16 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)14 IOException (java.io.IOException)13 CountDownLatch (java.util.concurrent.CountDownLatch)13 EndPoint (org.eclipse.jetty.io.EndPoint)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8