当前位置: 首页>>代码示例>>Java>>正文


Java ChannelPromise类代码示例

本文整理汇总了Java中io.netty.channel.ChannelPromise的典型用法代码示例。如果您正苦于以下问题:Java ChannelPromise类的具体用法?Java ChannelPromise怎么用?Java ChannelPromise使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelPromise类属于io.netty.channel包,在下文中一共展示了ChannelPromise类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: bind

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise)
    throws Exception {
  if (localAddress == slowAddr) {
    // delay binding 1 second.
    eventLoop.schedule(
        () -> {
          try {
            super.bind(ctx, localAddress, promise);
          } catch (Exception e) {
            // shouldn't happen.
          }
        },
        1,
        TimeUnit.SECONDS);
  } else {
    super.bind(ctx, localAddress, promise);
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:20,代码来源:ServerTest.java

示例2: write

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    LOGGER.info("[Client ({})] <= [Server ({})] : {}",
                connectionInfo.getClientAddr(), connectionInfo.getServerAddr(),
                msg);

    if (msg instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) msg;
        if (!response.headers().contains(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text())) {
            if (streams.isEmpty()) {
                throw new IllegalStateException("No active streams");
            }
            response.headers().add(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(),
                                   streams.poll());
        }
    }

    ctx.write(msg, promise);
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:20,代码来源:Http2FrontendHandler.java

示例3: createRpcClientRTEDuringConnectionSetup

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
protected AsyncRpcClient createRpcClientRTEDuringConnectionSetup(Configuration conf) {
  setConf(conf);
  return new AsyncRpcClient(conf, new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
          ch.pipeline().addFirst(new ChannelOutboundHandlerAdapter() {
            @Override
            public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
                throws Exception {
              promise.setFailure(new RuntimeException("Injected fault"));
            }
          });
        }
      });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:TestAsyncIPC.java

示例4: write

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
public void write ( final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise ) throws Exception
{
    if ( msg instanceof OpenResponse )
    {
        writeOpenResponse ( ctx, (OpenResponse)msg, promise );
    }
    else if ( msg instanceof SyslogResponse )
    {
        writeGenericResponse ( ctx, (AbstractGenericResponse)msg, promise );
    }
    else if ( msg instanceof ServerCloseMessage )
    {
        ctx.write ( new Frame ( 0, "serverclose", (ByteBuf)null ) );
    }
    else
    {
        super.write ( ctx, msg, promise );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:21,代码来源:FrameProcessor.java

示例5: writeOpenResponse

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
protected void writeOpenResponse ( final ChannelHandlerContext ctx, final OpenResponse msg, final ChannelPromise promise )
{
    final StringBuilder sb = new StringBuilder ();

    int i = 0;
    for ( final Map.Entry<String, String> entry : msg.getOffers ().entrySet () )
    {
        if ( i > 0 )
        {
            sb.append ( Constants.LF_STRING );
        }

        sb.append ( entry.getKey () );

        if ( entry.getValue () != null )
        {
            sb.append ( '=' );
            sb.append ( entry.getValue () );
        }
        i++;
    }

    ctx.write ( createCommonResponse ( msg.getTransactionId (), msg.getCode (), msg.getMessage (), sb ) );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:FrameProcessor.java

示例6: processFrame

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
protected void processFrame ( final ChannelHandlerContext ctx, final Frame frame, final ChannelPromise promise )
{
    final int length = frame.getData () == null ? 0 : frame.getData ().readableBytes ();

    final ByteBuf data = ctx.alloc ().buffer ();
    data.writeBytes ( String.format ( "%s", frame.getTransactionId () ).getBytes ( TXNR_CHARSET ) );
    data.writeByte ( Constants.SP );
    data.writeBytes ( frame.getCommand ().getBytes ( COMMAND_CHARSET ) );
    data.writeByte ( Constants.SP );
    data.writeBytes ( String.format ( "%s", length ).getBytes ( LENGTH_CHARSET ) );

    if ( length > 0 )
    {
        data.writeByte ( Constants.SP );
        data.writeBytes ( frame.getData () );
    }

    if ( frame.getData () != null )
    {
        frame.getData ().release ();
    }

    data.writeByte ( Constants.LF );

    ctx.write ( data );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:FrameCodec.java

示例7: handleMessageWrite

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
private void handleMessageWrite ( final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise )
{
    final ByteBuf data = encode ( ctx, msg );

    if ( data == null )
    {
        // ignore
        return;
    }

    // if the buffer is full
    if ( this.ackBuffer.isFull () )
    {
        logger.trace ( "Store message for later transmission" );
        // ... store now and re-try later
        this.messageBuffer.add ( new WriteEvent ( ctx, data, promise ) );
    }
    else
    {
        writeMessageToChannel ( ctx, data, promise );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:MessageChannel.java

示例8: writeMessageToChannel

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
private void writeMessageToChannel ( final ChannelHandlerContext ctx, final ByteBuf data, final ChannelPromise promise )
{
    final int seq = this.ackBuffer.addMessage ( data );

    if ( promise == null )
    {
        ctx.write ( new InformationTransfer ( seq, this.receiveCounter, data ) );
    }
    else
    {
        ctx.write ( new InformationTransfer ( seq, this.receiveCounter, data ), promise );
    }

    logger.trace ( "Enqueued message as {} : {}", seq, data );

    // we can stop timer #2 here ... will be restarted by receive
    this.timer2.stop ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:MessageChannel.java

示例9: write

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (msg instanceof DeferredMessage) {
        DeferredMessage defMsg = (DeferredMessage)msg;

        if (defMsg.isPreEncoded()) {
            // Write pre-encoded message.
            ctx.write(defMsg.encoded(), promise);
        } else {
            super.write(ctx, defMsg.encoded(), promise);
        }
    } else if (msg instanceof ByteBuf) {
        ctx.write(msg, promise);
    } else {
        super.write(ctx, msg, promise);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:18,代码来源:NetworkProtocolCodec.java

示例10: write

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    IMessage message = (IMessage) msg;
    if (message.getMsgId() >= 0x40 && message.getMsgId() <= 0x4F) {
        ctx.writeAndFlush(Unpooled.wrappedBuffer(tcpMsgBuilder.buildResponseMsg((BaseTcpResponseMsg) message)));
    } else if (message.getMsgId() >= 0x60 && message.getMsgId() <= 0x6F) {
        ctx.writeAndFlush(Unpooled.wrappedBuffer(tcpMsgBuilder.buildResponseMsg((BaseTcpResponseMsg) message)));
    } else if (message.getMsgId() >= -128 && message.getMsgId() <= -113) {
        ctx.writeAndFlush(Unpooled.wrappedBuffer(tcpMsgBuilder.buildResponseMsg((BaseTcpResponseMsg) message)));
    } else if (message.getMsgId() == MsgType.INITIALIZE_DEVICE_RESPONSE_CARD) {
        ctx.writeAndFlush(Unpooled.wrappedBuffer(tcpMsgBuilder.buildInitConfirmCardNumber((TcpMsgInitResponseCardNumber) message)));
    }
    if (message.getMsgId() == 0x00) {
        ctx.writeAndFlush(Unpooled.wrappedBuffer(tcpMsgBuilder.buildResponseMsg((BaseTcpResponseMsg) message)));
    }
    if (sendListener != null) {
        sendListener.send();
    }
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:20,代码来源:KyOutBoundHandler.java

示例11: write

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    SendableMsgContainer message = (SendableMsgContainer) msg;
    ByteBuf byteBuf = ctx.alloc().buffer();
    FrameMajorHeader header = message.getFrameHeader();
    byteBuf.writeByte(FrameSetting.MAJOR_FRAME_HEAD_1);
    byteBuf.writeByte(FrameSetting.MAJOR_FRAME_HEAD_2);
    byteBuf.writeByte(header.getGroupId());
    byteBuf.writeByte(header.getMsgId());
    byteBuf.writeByte(header.getDeviceId());
    byteBuf.writeByte(header.getBackupMsg());
    byteBuf.writeShort(header.getDataLength());

    List<ByteBuf> dataList = message.getDataList();
    dataList.forEach(byteBuf::writeBytes);
    ctx.writeAndFlush(byteBuf);
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:18,代码来源:MsgRecognitionOutBoundHandler.java

示例12: write

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (!(msg instanceof Packet)) {
        throw new RuntimeException("Object is not a *Packet");
    }

    Packet packet = (Packet) msg;
    int packetId = packet.getPacketInfo().id();
    int packetSize = packet.getPacketSize() + ProtocolSizer.ofVarInt(packetId);
    int bufferSize = packetSize + ProtocolSizer.ofVarInt(packetSize);

    ByteBuf unpooledByteBuf = Unpooled.buffer(bufferSize);
    PacketSerializer serializer = new PacketSerializer(unpooledByteBuf);

    UnknownPandaServer.getLogger().info("Sending packet: " + packet.getClass().getSimpleName() + " & id: 0x" + Integer.toHexString(packetId) + " & size: " + packetSize);
    serializer.writeVarInt(packetSize);
    serializer.writeVarInt(packetId);
    packet.send(serializer);

    ctx.writeAndFlush(serializer, promise);
}
 
开发者ID:dzikoysk,项目名称:UnknownPandaServer,代码行数:22,代码来源:PacketCodec.java

示例13: write

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
public void write(ChannelHandlerContext context, Object packet, ChannelPromise promise) throws Exception
{
	BaseComponent[] components = interceptor.getComponents(packet);
	if(components != null)
	{
		boolean allowed = isAllowed(components);
		boolean paused = isPaused();
		if(!paused || !allowed)
		{
			while(messageQueue.size() > 20)
				messageQueue.remove();
			messageQueue.add(components);
		}
		
		if(paused && !allowed)
			return;
	}
	
	super.write(context, packet, promise);
}
 
开发者ID:timtomtim7,项目名称:ChatMenuAPI,代码行数:21,代码来源:PlayerChatIntercept.java

示例14: write

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
{
    if (msg instanceof FMLProxyPacket)
    {
        if (side == Side.CLIENT)
        {
            //Client to server large packets are not supported to prevent client being bad.
            ctx.write(((FMLProxyPacket) msg).toC17Packet(), promise);
        }
        else
        {
            List<Packet<INetHandlerPlayClient>> parts = ((FMLProxyPacket)msg).toS3FPackets();
            for (Packet<INetHandlerPlayClient> pkt : parts)
            {
                ctx.write(pkt, promise);
            }
        }
    }
    else
    {
        ctx.write(msg, promise);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:25,代码来源:NetworkDispatcher.java

示例15: disconnect

import io.netty.channel.ChannelPromise; //导入依赖的package包/类
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
    log.info("NETTY CLIENT PIPELINE: DISCONNECT {}", remoteAddress);
    closeChannel(ctx.channel());
    super.disconnect(ctx, promise);

    if (NettyRemotingClient.this.channelEventListener != null) {
        NettyRemotingClient.this.putNettyEvent(new NettyEvent(NettyEventType.CLOSE, remoteAddress.toString(), ctx.channel()));
    }
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:12,代码来源:NettyRemotingClient.java


注:本文中的io.netty.channel.ChannelPromise类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。