@Override public NextAction handleWrite(FilterChainContext context) throws IOException { Connection<?> connection = context.getConnection(); GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler); try { ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // Do not need to close Object msg = context.getMessage(); codec.encode(channel, channelBuffer, msg); GrizzlyChannel.removeChannelIfDisconnected(connection); Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes()); buffer.put(channelBuffer.toByteBuffer()); buffer.flip(); buffer.allowBufferDispose(true); context.setMessage(buffer); } finally { GrizzlyChannel.removeChannelIfDisconnected(connection); } return context.getInvokeAction(); }
@Override public NextAction handleWrite(FilterChainContext context) throws IOException { Connection<?> connection = context.getConnection(); GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler); try { ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // Do not need to close Object msg = context.getMessage(); codec.encode(channel, channelBuffer, msg); GrizzlyChannel.removeChannelIfDisconnected(connection); Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes()); buffer.put(channelBuffer.toByteBuffer()); buffer.flip(); buffer.allowBufferDispose(true); context.setMessage(buffer); } finally { GrizzlyChannel.removeChannelIfDisconnected(connection); } return context.getInvokeAction(); }
private void feederFlush(final Connection c) { if (isServiceThread()) { c.getTransport().getWorkerThreadPool().execute(new Runnable() { @Override public void run() { feederFlush0(c); } }); } else { feederFlush0(c); } }
private static void block(final Connection c, final FutureImpl<Boolean> future) { try { final long writeTimeout = c.getTransport().getWriteTimeout(MILLISECONDS); if (writeTimeout != -1) { future.get(writeTimeout, MILLISECONDS); } else { future.get(); } } catch (ExecutionException e) { c.closeWithReason(Exceptions.makeIOException(e.getCause())); } catch (Exception e) { c.closeWithReason(Exceptions.makeIOException(e)); } }
@Override public Executor getThreadPoolFor(final Connection connection, final IOEvent ioEvent) { return WORKER_THREAD_EVENT_SET.contains(ioEvent) ? connection.getTransport().getWorkerThreadPool() : null; }
@Override public Executor getThreadPoolFor(final Connection connection, final IOEvent ioEvent) { return WORKER_THREAD_EVENT_SET.contains(ioEvent) ? connection.getTransport().getWorkerThreadPool() : null; }
@Override public Executor getThreadPoolFor(final Connection connection, final IOEvent ioEvent) { return WORKER_THREAD_EVENT_SET.contains(ioEvent) ? connection.getTransport().getWorkerThreadPool() : null; }
/** * @return {@link Executor}, which will be used for notifying user * registered {@link WriteHandler}. */ protected Executor getThreadPool() { if (!Threads.isService()) { return null; } final ExecutorService es = connection.getTransport().getWorkerThreadPool(); return es != null && !es.isShutdown() ? es : null; }
/** * @return {@link Executor}, which will be used for notifying user * registered {@link ReadHandler}. */ protected Executor getThreadPool() { if (!Threads.isService()) { return null; } final ExecutorService es = connection.getTransport().getWorkerThreadPool(); return es != null && !es.isShutdown() ? es : null; }
/** * @return {@link Executor}, which will be used for notifying user * registered {@link WriteHandler}. */ protected Executor getThreadPool() { if (!Threads.isService()) { return null; } final ExecutorService es = connection.getTransport().getWorkerThreadPool(); return es != null && !es.isShutdown() ? es : null; }
/** * @return {@link Executor}, which will be used for notifying user * registered {@link WriteHandler}. */ protected Executor getThreadPool() { if (!Threads.isService()) { return null; } final ExecutorService es = connection.getTransport().getWorkerThreadPool(); return es != null && !es.isShutdown() ? es : null; }
/** * @return {@link Executor}, which will be used for notifying user * registered {@link WriteHandler}. */ protected Executor getThreadPool() { if (!Threads.isService()) { return null; } final ExecutorService es = connection.getTransport().getWorkerThreadPool(); return es != null && !es.isShutdown() ? es : null; }
protected Buffer acquireBuffer(Connection connection) { Transport connectionTransport = connection.getTransport(); return connectionTransport.getMemoryManager(). allocate(DEFAULT_BUFFER_SIZE); }
@Override public void write(Connection connection, Object dstAddress, Object message, CompletionHandler completionHandler, MessageCloner messageCloner) { final Transport transport = connection.getTransport(); transport.getWriter(connection).write(connection, dstAddress, (Buffer) message, completionHandler, messageCloner); }
@Override public void read(Connection connection, CompletionHandler completionHandler) { final Transport transport = connection.getTransport(); transport.getReader(connection).read(connection, null, completionHandler); }
protected Buffer acquireBuffer(Connection connection) { Transport connectionTransport = connection.getTransport(); return connectionTransport.getMemoryManager(). allocate(DEFAULT_BUFFER_SIZE); }
@Override public Executor getExecutor(final Request request) { if (!Threads.isService()) { return null; // Execute in the current thread } return request.getContext().getConnection().getTransport().getWorkerThreadPool(); } }
@Override public Executor getExecutor(final Request request) { if (!Threads.isService()) { return null; // Execute in the current thread } return request.getContext().getConnection().getTransport().getWorkerThreadPool(); } }
@SuppressWarnings("unchecked") protected void sendRaw(byte[] rawData) { final Connection connection = protocolHandler.getConnection(); final MemoryManager mm = connection.getTransport().getMemoryManager(); final Buffer buffer = Buffers.wrap(mm, rawData); buffer.allowBufferDispose(false); connection.write(buffer); }
@Before public void setUp() { when(ctx.getConnection()).thenReturn(connection); when(connection.getTransport()).thenReturn(mock(Transport.class, RETURNS_DEEP_STUBS)); InputStream mockStream = mock(InputStream.class); handler = new ResponseStreamingCompletionHandler(ctx, request, HttpResponse.builder().entity(new InputStreamHttpEntity(mockStream)).build(), callback); }