Example usage for io.netty.buffer Unpooled unmodifiableBuffer

List of usage examples for io.netty.buffer Unpooled unmodifiableBuffer

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled unmodifiableBuffer.

Prototype

@Deprecated
public static ByteBuf unmodifiableBuffer(ByteBuf... buffers) 

Source Link

Document

Wrap the given ByteBuf s in an unmodifiable ByteBuf .

Usage

From source file:com.heliosapm.tsdblite.handlers.http.HttpRequestManager.java

License:Apache License

/**
 * Creates a new HttpRequestManager//from ww w . j av  a  2s  .  co  m
 */
private HttpRequestManager() {
    favicon = Unpooled.unmodifiableBuffer(Unpooled.copiedBuffer(
            URLHelper.getBytesFromURL(getClass().getClassLoader().getResource("www/favicon.ico"))));
    favSize = favicon.readableBytes();
    log.info("Loaded favicon: [{}] Bytes", favSize);
    requestHandlers.put("/api/put", new SubmitTracesHandler());
    requestHandlers.put("/api/s", HttpStaticFileServerHandler.getInstance());
}

From source file:com.heliosapm.tsdblite.handlers.http.HttpSwitch.java

License:Apache License

/**
 * Creates a new HttpSwitch/*  w ww.jav  a2  s  .c  o  m*/
 */
public HttpSwitch(final EventExecutorGroup eventExecutorGroup) {
    this.eventExecutorGroup = eventExecutorGroup;
    favicon = Unpooled.unmodifiableBuffer(Unpooled.copiedBuffer(
            URLHelper.getBytesFromURL(getClass().getClassLoader().getResource("www/favicon.ico"))));
    favSize = favicon.readableBytes();

}

From source file:org.ratpackframework.test.handling.internal.DefaultInvocation.java

License:Apache License

public DefaultInvocation(Request request, Status status, MutableHeaders responseHeaders, ByteBuf responseBody,
        Registry registry, final int timeout, Handler handler) {

    // There are definitely concurrency bugs in here around timing out
    // ideally we should prevent the stat from changing after a timeout occurs

    this.headers = new DelegatingHeaders(responseHeaders);
    this.status = status;

    ExecutorService mainExecutor = newSingleThreadExecutor();
    ListeningExecutorService blockingExecutor = listeningDecorator(newSingleThreadExecutor());

    final CountDownLatch latch = new CountDownLatch(1);

    FileHttpTransmitter fileHttpTransmitter = new FileHttpTransmitter() {
        @Override//  w  ww. j av a  2 s .  c  o m
        public void transmit(Blocking blocking, BasicFileAttributes basicFileAttributes, File file) {
            sentFile = file;
            latch.countDown();
        }
    };

    Runnable committer = new Runnable() {
        public void run() {
            sentResponse = true;
            latch.countDown();
        }
    };

    Handler next = new Handler() {
        public void handle(Context context) {
            calledNext = true;
            latch.countDown();
        }
    };

    Response response = new DefaultResponse(status, responseHeaders, responseBody, fileHttpTransmitter,
            committer);
    Context context = new DefaultContext(request, response, registry, mainExecutor, blockingExecutor, next) {
        @Override
        public void render(Object object) throws NoSuchRendererException {
            rendered = object;
            latch.countDown();
        }
    };

    try {
        handler.handle(context);
    } catch (Exception e) {
        exception = e;
        latch.countDown();
    }

    try {
        if (!latch.await(timeout, TimeUnit.SECONDS)) {
            throw new InvocationTimeoutException(this, timeout);
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e); // what to do here?
    }

    this.body = Unpooled.unmodifiableBuffer(responseBody);
}

From source file:ratpack.http.internal.ByteBufBackedTypedData.java

License:Apache License

@Override
public ByteBuf getBuffer() {
    return Unpooled.unmodifiableBuffer(byteBuf);
}

From source file:ratpack.server.internal.RequestBody.java

License:Apache License

private ByteBuf composeReceived() {
    if (received.isEmpty()) {
        return Unpooled.EMPTY_BUFFER;
    } else if (received.size() == 1) {
        return new ByteBufRef(received.remove(0));
    } else {/*from   ww w  .  j  a  va2 s  .c  om*/
        ByteBuf[] byteBufsArray = this.received.toArray(new ByteBuf[this.received.size()]);
        received.clear();
        return Unpooled.unmodifiableBuffer(byteBufsArray);
    }
}

From source file:ratpack.session.store.internal.LocalMemorySessionStoreAdapter.java

License:Apache License

@Override
public Operation store(SessionId sessionId, ByteBufAllocator bufferAllocator, ByteBuf sessionData) {
    return execControl.operation(() -> {
        ByteBuf oldValue = cache.asMap().put(sessionId.getValue(),
                Unpooled.unmodifiableBuffer(sessionData.copy()));
        if (oldValue != null) {
            oldValue.release();//from   w  w  w.j a va2s .c om
        }
    });
}

From source file:ratpack.test.handling.internal.DefaultInvocation.java

License:Apache License

public DefaultInvocation(final Request request, final Status status, final MutableHeaders responseHeaders,
        ByteBuf responseBody, Registry registry, final int timeout, Handler handler) {

    // There are definitely concurrency bugs in here around timing out
    // ideally we should prevent the stat from changing after a timeout occurs

    this.headers = new DelegatingHeaders(responseHeaders);
    this.status = status;

    ListeningExecutorService backgroundExecutor = listeningDecorator(newSingleThreadExecutor());
    ScheduledExecutorService computeExecutorService = Executors.newScheduledThreadPool(1);

    final CountDownLatch latch = new CountDownLatch(1);

    FileHttpTransmitter fileHttpTransmitter = new FileHttpTransmitter() {
        @Override//from   w w w.  j  a v a2  s  .  c  o m
        public void transmit(Background background, BasicFileAttributes basicFileAttributes, File file) {
            sentFile = file;
            latch.countDown();
        }
    };

    final EventController<RequestOutcome> eventController = new DefaultEventController<>();

    Action<Response> committer = new Action<Response>() {
        public void execute(Response response) {
            sentResponse = true;
            eventController.fire(new DefaultRequestOutcome(request, response, System.currentTimeMillis()));
            latch.countDown();
        }
    };

    Handler next = new Handler() {
        public void handle(Context context) {
            calledNext = true;
            latch.countDown();
        }
    };

    BindAddress bindAddress = new BindAddress() {
        @Override
        public int getPort() {
            return 5050;
        }

        @Override
        public String getHost() {
            return "localhost";
        }
    };

    ClientErrorHandler clientErrorHandler = new ClientErrorHandler() {
        @Override
        public void error(Context context, int statusCode) throws Exception {
            DefaultInvocation.this.clientError = statusCode;
            latch.countDown();
        }
    };

    ServerErrorHandler serverErrorHandler = new ServerErrorHandler() {
        @Override
        public void error(Context context, Exception exception) throws Exception {
            DefaultInvocation.this.exception = exception;
            latch.countDown();
        }
    };

    Registry effectiveRegistry = RegistryBuilder
            .join(RegistryBuilder.builder().add(ClientErrorHandler.class, clientErrorHandler)
                    .add(ServerErrorHandler.class, serverErrorHandler).build(), registry);

    Response response = new DefaultResponse(status, responseHeaders, responseBody, fileHttpTransmitter,
            committer);
    Context context = new DefaultContext(null, request, response, bindAddress, effectiveRegistry,
            backgroundExecutor, computeExecutorService, eventController.getRegistry(), new Handler[0], 0,
            next) {
        @Override
        public void render(Object object) throws NoSuchRendererException {
            rendered = object;
            latch.countDown();
        }
    };

    try {
        handler.handle(context);
    } catch (Exception e) {
        exception = e;
        latch.countDown();
    }

    try {
        if (!latch.await(timeout, TimeUnit.SECONDS)) {
            throw new InvocationTimeoutException(this, timeout);
        }
    } catch (InterruptedException e) {
        throw uncheck(e); // what to do here?
    }

    this.body = Unpooled.unmodifiableBuffer(responseBody);
}