use of org.jboss.netty.channel.ChannelFuture in project neo4j by neo4j.
the class BufferReusingChunkingChannelBufferTest method triggerOperationCompleteCallback.
private static ChannelBuffer triggerOperationCompleteCallback(BufferReusingChunkingChannelBuffer buffer) throws Exception {
ChannelBuffer reusedBuffer = spy(ChannelBuffers.dynamicBuffer());
ChannelFuture channelFuture = mock(ChannelFuture.class);
when(channelFuture.isDone()).thenReturn(true);
when(channelFuture.isSuccess()).thenReturn(true);
buffer.newChannelFutureListener(reusedBuffer).operationComplete(channelFuture);
return reusedBuffer;
}
use of org.jboss.netty.channel.ChannelFuture in project weave by continuuity.
the class SimpleKafkaClient method preparePublish.
@Override
public PreparePublish preparePublish(final String topic, final Compression compression) {
final Map<Integer, MessageSetEncoder> encoders = Maps.newHashMap();
return new PreparePublish() {
@Override
public PreparePublish add(byte[] payload, Object partitionKey) {
return add(ByteBuffer.wrap(payload), partitionKey);
}
@Override
public PreparePublish add(ByteBuffer payload, Object partitionKey) {
// TODO: Partition
int partition = 0;
MessageSetEncoder encoder = encoders.get(partition);
if (encoder == null) {
encoder = getEncoder(compression);
encoders.put(partition, encoder);
}
encoder.add(ChannelBuffers.wrappedBuffer(payload));
return this;
}
@Override
public ListenableFuture<?> publish() {
List<ListenableFuture<?>> futures = Lists.newArrayListWithCapacity(encoders.size());
for (Map.Entry<Integer, MessageSetEncoder> entry : encoders.entrySet()) {
futures.add(doPublish(topic, entry.getKey(), entry.getValue().finish()));
}
encoders.clear();
return Futures.allAsList(futures);
}
private ListenableFuture<?> doPublish(String topic, int partition, ChannelBuffer messageSet) {
final KafkaRequest request = KafkaRequest.createProduce(topic, partition, messageSet);
final SettableFuture<?> result = SettableFuture.create();
final ConnectionPool.ConnectResult connection = connectionPool.connect(getTopicBroker(topic, partition).getAddress());
connection.getChannelFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
try {
future.getChannel().write(request).addListener(getPublishChannelFutureListener(result, null, connection));
} catch (Exception e) {
result.setException(e);
}
}
});
return result;
}
};
}
use of org.jboss.netty.channel.ChannelFuture in project weave by continuuity.
the class ConnectionPool method connect.
ConnectResult connect(InetSocketAddress address) {
Queue<ChannelFuture> channelFutures = connections.get(address);
if (channelFutures == null) {
channelFutures = new ConcurrentLinkedQueue<ChannelFuture>();
Queue<ChannelFuture> result = connections.putIfAbsent(address, channelFutures);
channelFutures = result == null ? channelFutures : result;
}
ChannelFuture channelFuture = channelFutures.poll();
while (channelFuture != null) {
if (channelFuture.isSuccess() && channelFuture.getChannel().isConnected()) {
return new SimpleConnectResult(address, channelFuture);
}
channelFuture = channelFutures.poll();
}
channelFuture = bootstrap.connect(address);
channelFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
channelGroup.add(future.getChannel());
}
}
});
return new SimpleConnectResult(address, channelFuture);
}
use of org.jboss.netty.channel.ChannelFuture in project neo4j by neo4j.
the class ChunkingChannelBuffer method writeCurrentChunk.
private void writeCurrentChunk() {
if (!channel.isOpen() || !channel.isConnected() || !channel.isBound()) {
throw new ComException("Channel has been closed, so no need to try to write to it anymore. Client closed it?");
}
waitForClientToCatchUpOnReadingChunks();
ChannelFuture future = channel.write(buffer);
future.addListener(newChannelFutureListener(buffer));
writeAheadCounter.incrementAndGet();
}
use of org.jboss.netty.channel.ChannelFuture in project graylog2-server by Graylog2.
the class GELFHttpHandlerTest method setUp.
@Before
public void setUp() throws Exception {
ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer("{}", StandardCharsets.UTF_8);
when(headers.get(HttpHeaders.Names.CONNECTION)).thenReturn(HttpHeaders.Values.CLOSE);
when(request.getMethod()).thenReturn(HttpMethod.POST);
when(request.headers()).thenReturn(headers);
when(request.getProtocolVersion()).thenReturn(HttpVersion.HTTP_1_1);
when(request.getContent()).thenReturn(channelBuffer);
when(request.getUri()).thenReturn("/gelf");
when(ctx.getChannel()).thenReturn(mock(Channel.class));
ChannelFuture channelFuture = mock(ChannelFuture.class);
when(channel.write(any())).thenReturn(channelFuture);
when(evt.getMessage()).thenReturn(request);
when(evt.getChannel()).thenReturn(channel);
}
Aggregations