當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。