本文整理汇总了Java中io.netty.util.concurrent.GenericFutureListener类的典型用法代码示例。如果您正苦于以下问题:Java GenericFutureListener类的具体用法?Java GenericFutureListener怎么用?Java GenericFutureListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericFutureListener类属于io.netty.util.concurrent包,在下文中一共展示了GenericFutureListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
public synchronized ListenableFuture<Void> connect ()
{
if ( this.connectFuture != null )
{
return this.connectFuture;
}
final ChannelFuture channelFuture = this.bootstrap.connect ( this.address );
this.connectFuture = SettableFuture.create ();
channelFuture.addListener ( new GenericFutureListener<ChannelFuture> () {
@Override
public void operationComplete ( final ChannelFuture future ) throws Exception
{
handleOperationComplete ( Client.this.connectFuture, future );
}
} );
return this.connectFuture;
}
示例2: setupWithTest
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
/**
* Establishes a new socket connection with connection test
*/
protected void setupWithTest() {
ChannelFuture future = boot.connect(uri.host(), port);
future.addListener(
new GenericFutureListener<ChannelFuture>() {
public void operationComplete(ChannelFuture f) {
if (f.isSuccess()) {
channel = (HTTPChannel) f.channel();
testConnection();
onTestBell.promise(onConnectBell);
} else {
onConnectBell.ring(f.cause());
}
}
});
}
示例3: kickPlayerFromServer
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
/**
* Kick a player from the server with a reason
*/
public void kickPlayerFromServer(String reason)
{
final ChatComponentText chatcomponenttext = new ChatComponentText(reason);
this.netManager.sendPacket(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener < Future <? super Void >> ()
{
public void operationComplete(Future <? super Void > p_operationComplete_1_) throws Exception
{
NetHandlerPlayServer.this.netManager.closeChannel(chatcomponenttext);
}
}, new GenericFutureListener[0]);
this.netManager.disableAutoRead();
Futures.getUnchecked(this.serverController.addScheduledTask(new Runnable()
{
public void run()
{
NetHandlerPlayServer.this.netManager.checkDisconnected();
}
}));
}
示例4: sendPacket
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
public void sendPacket(Packet packetIn)
{
if (this.isChannelOpen())
{
this.flushOutboundQueue();
this.dispatchPacket(packetIn, (GenericFutureListener <? extends Future <? super Void >> [])null);
}
else
{
this.field_181680_j.writeLock().lock();
try
{
this.outboundPacketsQueue.add(new NetworkManager.InboundHandlerTuplePacketListener(packetIn, (GenericFutureListener[])null));
}
finally
{
this.field_181680_j.writeLock().unlock();
}
}
}
示例5: RemoteConnection
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
public RemoteConnection(SocketChannel channel, String name) {
super();
this.channel = channel;
this.clientName = name;
this.writeManager = new WriteManager();
channel.pipeline().addLast(new BackPressureHandler());
channel.closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() {
public void operationComplete(Future<? super Void> future) throws Exception {
// this could possibly overrelease but it doesn't matter since we're only going to do this to ensure that we
// fail out any pending messages
writeManager.disable();
writeManager.setWritable(true);
}
});
}
示例6: kickPlayerFromServer
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
/**
* Kick a player from the server with a reason
*/
public void kickPlayerFromServer(String reason)
{
final TextComponentString textcomponentstring = new TextComponentString(reason);
this.netManager.sendPacket(new SPacketDisconnect(textcomponentstring), new GenericFutureListener < Future <? super Void >> ()
{
public void operationComplete(Future <? super Void > p_operationComplete_1_) throws Exception
{
NetHandlerPlayServer.this.netManager.closeChannel(textcomponentstring);
}
}, new GenericFutureListener[0]);
this.netManager.disableAutoRead();
Futures.getUnchecked(this.serverController.addScheduledTask(new Runnable()
{
public void run()
{
NetHandlerPlayServer.this.netManager.checkDisconnected();
}
}));
}
示例7: connectionSucceeded
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
@Override
public void connectionSucceeded(final ServerConnection connection) {
connection.getChannel().closeFuture().addListener(
new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future)
throws Exception {
for (final UserResultsListener listener : queryIdToResultsListenersMap.values()) {
listener.submissionFailed(UserException.connectionError()
.message("Connection %s closed unexpectedly. SabotNode down?",
connection.getName())
.build(logger));
if (listener instanceof BufferingResultsListener) {
// the appropriate listener will be failed by SubmissionListener#failed
logger.warn("Buffering listener failed before results were transferred to the actual listener.");
}
}
}
});
parentHandler.connectionSucceeded(connection);
}
示例8: kickWithMessage
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
private void kickWithMessage(String message)
{
final TextComponentString TextComponentString = new TextComponentString(message);
if (side == Side.CLIENT)
{
manager.closeChannel(TextComponentString);
}
else
{
manager.sendPacket(new SPacketDisconnect(TextComponentString), new GenericFutureListener<Future<? super Void>>()
{
@Override
public void operationComplete(Future<? super Void> result)
{
manager.closeChannel(TextComponentString);
}
}, (GenericFutureListener<? extends Future<? super Void>>[])null);
}
manager.channel().config().setAutoRead(false);
}
示例9: sendPacket
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
public void sendPacket(Packet<?> packetIn)
{
if (this.isChannelOpen())
{
this.flushOutboundQueue();
this.dispatchPacket(packetIn, (GenericFutureListener <? extends Future <? super Void >> [])null);
}
else
{
this.readWriteLock.writeLock().lock();
try
{
this.outboundPacketsQueue.add(new NetworkManager.InboundHandlerTuplePacketListener(packetIn, (GenericFutureListener[])null));
}
finally
{
this.readWriteLock.writeLock().unlock();
}
}
}
示例10: kickWithMessage
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
private void kickWithMessage(String message)
{
final ChatComponentText chatcomponenttext = new ChatComponentText(message);
if (side == Side.CLIENT)
{
manager.func_150718_a(chatcomponenttext);
}
else
{
manager.func_150725_a(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener<Future<?>>()
{
@Override
public void operationComplete(Future<?> result)
{
manager.func_150718_a(chatcomponenttext);
}
});
}
manager.channel().config().setAutoRead(false);
}
示例11: sendOneWayMessage
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
@Override
public void sendOneWayMessage(Message message, SendResultCallback callback) {
if (message.getMessageId() == null) {
message.assignMessageId();
}
io.netty.channel.Channel _socket = this.socket;
if (_socket == null || !_socket.isOpen()) {
callback.messageSent(message, new Exception(this + " connection is closed"));
return;
}
_socket.writeAndFlush(message).addListener(new GenericFutureListener() {
@Override
public void operationComplete(Future future) throws Exception {
if (future.isSuccess()) {
callback.messageSent(message, null);
} else {
LOGGER.log(Level.SEVERE, this + ": error " + future.cause(), future.cause());
callback.messageSent(message, future.cause());
close();
}
}
});
}
示例12: mock
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
@Test
public void finalizeChannelPipeline_should_send_event_to_metricsListener_for_successful_response_and_flush_context() throws Exception {
// given
ChannelFuture responseWriterChannelFuture = mock(ChannelFuture.class);
state.setResponseWriterFinalChunkChannelFuture(responseWriterChannelFuture);
HttpProcessingState stateSpy = spy(state);
doReturn(stateSpy).when(stateAttributeMock).get();
ChannelFuture responseWriteFutureResult = mock(ChannelFuture.class);
doReturn(true).when(responseWriteFutureResult).isSuccess();
Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isFalse();
// when
handler.finalizeChannelPipeline(ctxMock, null, stateSpy, null);
// then
ArgumentCaptor<GenericFutureListener> channelFutureListenerArgumentCaptor = ArgumentCaptor.forClass(GenericFutureListener.class);
verify(responseWriterChannelFuture).addListener(channelFutureListenerArgumentCaptor.capture());
GenericFutureListener futureListener = channelFutureListenerArgumentCaptor.getValue();
assertThat(futureListener, notNullValue());
futureListener.operationComplete(responseWriteFutureResult);
verify(metricsListenerMock).onEvent(eq(ServerMetricsEvent.RESPONSE_SENT), any(HttpProcessingState.class));
verify(ctxMock).flush();
Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isTrue();
}
示例13: finalizeChannelPipeline_should_send_event_to_metricsListener_for_failure_response_and_flush_context
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
@Test
public void finalizeChannelPipeline_should_send_event_to_metricsListener_for_failure_response_and_flush_context() throws Exception {
// given
ChannelFuture responseWriterChannelFuture = mock(ChannelFuture.class);
state.setResponseWriterFinalChunkChannelFuture(responseWriterChannelFuture);
HttpProcessingState stateSpy = spy(state);
doReturn(stateSpy).when(stateAttributeMock).get();
ChannelFuture responseWriteFutureResult = mock(ChannelFuture.class);
doReturn(false).when(responseWriteFutureResult).isSuccess();
Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isFalse();
// when
handler.finalizeChannelPipeline(ctxMock, null, stateSpy, null);
// then
ArgumentCaptor<GenericFutureListener> channelFutureListenerArgumentCaptor = ArgumentCaptor.forClass(GenericFutureListener.class);
verify(responseWriterChannelFuture).addListener(channelFutureListenerArgumentCaptor.capture());
GenericFutureListener futureListener = channelFutureListenerArgumentCaptor.getValue();
assertThat(futureListener, notNullValue());
futureListener.operationComplete(responseWriteFutureResult);
verify(metricsListenerMock).onEvent(ServerMetricsEvent.RESPONSE_WRITE_FAILED, null);
verify(ctxMock).flush();
Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isTrue();
}
示例14: verifyCloseFutureListener
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
private void verifyCloseFutureListener(GenericFutureListener closeFutureListener) throws Exception {
// If the double-check ScheduledFuture is not done then it cancels it.
reset(doubleCheckScheduledFutureMock);
doReturn(false).when(doubleCheckScheduledFutureMock).isDone();
closeFutureListener.operationComplete(null);
verify(doubleCheckScheduledFutureMock).isDone();
verify(doubleCheckScheduledFutureMock).cancel(false);
verifyNoMoreInteractions(doubleCheckScheduledFutureMock);
// And when the double-check ScheduledFuture is done, then nothing happens.
reset(doubleCheckScheduledFutureMock);
doReturn(true).when(doubleCheckScheduledFutureMock).isDone();
closeFutureListener.operationComplete(null);
verify(doubleCheckScheduledFutureMock).isDone();
verifyNoMoreInteractions(doubleCheckScheduledFutureMock);
}
示例15: doChannelActive_marks_and_schedules_double_check_timeout_if_too_many_open_channels
import io.netty.util.concurrent.GenericFutureListener; //导入依赖的package包/类
@DataProvider(value = {
"0",
"1"
})
@Test
public void doChannelActive_marks_and_schedules_double_check_timeout_if_too_many_open_channels(
int numOpenChannelsGreaterThanMax
) throws Exception {
// given
int actualOpenChannels = maxOpenChannelsThreshold + numOpenChannelsGreaterThanMax;
setActualOpenChannels(actualOpenChannels);
// when
PipelineContinuationBehavior result = handler.doChannelActive(ctxMock);
// then
assertThat(result).isEqualTo(CONTINUE);
Pair<Runnable, GenericFutureListener> futureInfoPair = extractDoubleCheckRunnableAndCloseFutureListener();
verify(tooManyOpenConnectionsAttributeMock).set(actualOpenChannels);
verifyDoubleCheckFuture(futureInfoPair.getLeft());
verifyCloseFutureListener(futureInfoPair.getRight());
verify(channelGroupMock, never()).add(channelMock);
}