use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project neo4j by neo4j.
the class BoltProtocolV1Test method shouldNotTalkToChannelDirectlyOnFatalError.
@Test
public void shouldNotTalkToChannelDirectlyOnFatalError() throws Throwable {
// Given
Channel outputChannel = newChannelMock();
BoltStateMachine machine = mock(BoltStateMachine.class);
BoltProtocolV1 protocol = new BoltProtocolV1(new SynchronousBoltWorker(machine), outputChannel, NullLogService.getInstance());
verify(outputChannel).alloc();
// And given inbound data that'll explode when the protocol tries to interpret it
ByteBuf bomb = mock(ByteBuf.class);
doThrow(IOException.class).when(bomb).readableBytes();
// When
protocol.handle(mock(ChannelHandlerContext.class), bomb);
// Then the protocol should not mess with the channel (because it runs on the IO thread, and only the worker thread should produce writes)
verifyNoMoreInteractions(outputChannel);
// But instead make sure the state machine is shut down
verify(machine).close();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project neo4j by neo4j.
the class BoltProtocolV1Test method newChannelMock.
private static Channel newChannelMock() {
Channel channel = mock(Channel.class);
ByteBufAllocator allocator = mock(ByteBufAllocator.class, RETURNS_MOCKS);
when(channel.alloc()).thenReturn(allocator);
return channel;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project cradle by BingLau7.
the class ChannelOperationExamples method writingToChannelManyThreads.
// Channel 是线程安全的,可以在多个线程中使用它,需要注意的是,消息将会被保证按顺序发送
public static void writingToChannelManyThreads() {
// Get the channel reference from somewhere
final Channel channel = null;
// 创建持有要写数据的 ByteBuf
final ByteBuf buf = Unpooled.copiedBuffer("your data", CharsetUtil.UTF_8).retain();
// 创建将数据写到 Channel 的 Runnable
Runnable writer = new Runnable() {
@Override
public void run() {
channel.writeAndFlush(buf.duplicate());
}
};
// 获取线程池引用
Executor executor = Executors.newCachedThreadPool();
// 递交写任务给线程池以便在某个线程中执行
executor.execute(writer);
// 递交另一个写任务以便在另一个线程中执行
executor.execute(writer);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project intellij-community by JetBrains.
the class BuildManager method startListening.
private int startListening() throws Exception {
EventLoopGroup group;
BuiltInServer mainServer = StartupUtil.getServer();
boolean isOwnEventLoopGroup = !Registry.is("compiler.shared.event.group", true) || mainServer == null || mainServer.getEventLoopGroup() instanceof OioEventLoopGroup;
if (isOwnEventLoopGroup) {
group = new NioEventLoopGroup(1, ConcurrencyUtil.newNamedThreadFactory("External compiler"));
} else {
group = mainServer.getEventLoopGroup();
}
final ServerBootstrap bootstrap = serverBootstrap(group);
bootstrap.childHandler(new ChannelInitializer() {
@Override
protected void initChannel(@NotNull Channel channel) throws Exception {
channel.pipeline().addLast(myChannelRegistrar, new ProtobufVarint32FrameDecoder(), new ProtobufDecoder(CmdlineRemoteProto.Message.getDefaultInstance()), new ProtobufVarint32LengthFieldPrepender(), new ProtobufEncoder(), myMessageDispatcher);
}
});
Channel serverChannel = bootstrap.bind(InetAddress.getLoopbackAddress(), 0).syncUninterruptibly().channel();
myChannelRegistrar.setServerChannel(serverChannel, isOwnEventLoopGroup);
return ((InetSocketAddress) serverChannel.localAddress()).getPort();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project intellij-community by JetBrains.
the class BuildMessageDispatcher method sendBuildParameters.
public boolean sendBuildParameters(@NotNull final UUID preloadedSessionId, @NotNull CmdlineRemoteProto.Message.ControllerMessage params) {
boolean succeeded = false;
final SessionData sessionData = mySessionDescriptors.get(preloadedSessionId);
if (sessionData != null) {
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (sessionData) {
if (sessionData.state == SessionData.State.WAITING_PARAMS) {
sessionData.state = SessionData.State.RUNNING;
final Channel channel = sessionData.channel;
if (channel != null && channel.isActive()) {
sessionData.handler.buildStarted(preloadedSessionId);
channel.writeAndFlush(CmdlineProtoUtil.toMessage(preloadedSessionId, params));
succeeded = true;
}
} else {
if (sessionData.state == SessionData.State.INITIAL) {
sessionData.params = params;
succeeded = true;
}
}
}
}
return succeeded;
}
Aggregations