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


Java ChannelBuffers.wrappedBuffer方法代码示例

本文整理汇总了Java中org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelBuffers.wrappedBuffer方法的具体用法?Java ChannelBuffers.wrappedBuffer怎么用?Java ChannelBuffers.wrappedBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.netty.buffer.ChannelBuffers的用法示例。


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

示例1: handleInternal

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
protected void handleInternal(ChannelHandlerContext ctx, RpcInfo info) {
  // This is just like what's done in RpcProgramMountd#handleInternal and
  // RpcProgramNfs3#handleInternal.
  RpcCall rpcCall = (RpcCall) info.header();
  final int procedure = rpcCall.getProcedure();
  if (procedure != 0) {
    boolean portMonitorSuccess = doPortMonitoring(info.remoteAddress());
    if (!portMonitorSuccess) {
      sendRejectedReply(rpcCall, info.remoteAddress(), ctx);
      return;
    }
  }
  
  resultSize = info.data().readableBytes();
  RpcAcceptedReply reply = RpcAcceptedReply.getAcceptInstance(1234,
      new VerifierNone());
  XDR out = new XDR();
  reply.write(out);
  ChannelBuffer b = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap().buffer());
  RpcResponse rsp = new RpcResponse(b, info.remoteAddress());
  RpcUtil.sendRpcResponse(ctx, rsp);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:TestFrameDecoder.java

示例2: encode

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
                        Object message) throws Exception {
    if (message instanceof SyncMessage) {
        ChannelBuffer buf = new DynamicChannelBuffer(512);
        ChannelBufferOutputStream os = new ChannelBufferOutputStream(buf);
        TCompactProtocol thriftProtocol =
                new TCompactProtocol(new TIOStreamTransport(os));
        ((SyncMessage) message).write(thriftProtocol);

        ChannelBuffer len = ChannelBuffers.buffer(4);
        len.writeInt(buf.readableBytes());
        return ChannelBuffers.wrappedBuffer(len, buf);
    }
    return message;
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:17,代码来源:ThriftFrameEncoder.java

示例3: messageReceived

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
    throws Exception {
  ChannelBuffer buf = (ChannelBuffer) e.getMessage();
  ByteBuffer b = buf.toByteBuffer().asReadOnlyBuffer();
  XDR in = new XDR(b, XDR.State.READING);

  RpcInfo info = null;
  try {
    RpcCall callHeader = RpcCall.read(in);
    ChannelBuffer dataBuffer = ChannelBuffers.wrappedBuffer(in.buffer()
        .slice());
    info = new RpcInfo(callHeader, dataBuffer, ctx, e.getChannel(),
        e.getRemoteAddress());
  } catch (Exception exc) {
    LOG.info("Malformed RPC request from " + e.getRemoteAddress());
  }

  if (info != null) {
    Channels.fireMessageReceived(ctx, info);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:RpcUtil.java

示例4: decode

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx,
        Channel channel,
        ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < 20) {
        return null;
    }

    // Swap byte order for legacy protocol
    if (buf.getUnsignedByte(buf.readerIndex()) == 0x80) {
        int length = buf.readableBytes();
        byte[] bytes = new byte[length];
        buf.getBytes(buf.readerIndex(), bytes);

        ChannelBuffer result = (ChannelBuffer) super.decode(
                ctx, channel, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes));
        if (result != null) {
            buf.skipBytes(result.readableBytes());
        }
        return result;
    }

    return super.decode(ctx, channel, buf);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:27,代码来源:TramigoFrameDecoder.java

示例5: sendAcceptedReply

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
private void sendAcceptedReply(RpcCall call, SocketAddress remoteAddress,
    AcceptState acceptState, ChannelHandlerContext ctx) {
  RpcAcceptedReply reply = RpcAcceptedReply.getInstance(call.getXid(),
      acceptState, Verifier.VERIFIER_NONE);

  XDR out = new XDR();
  reply.write(out);
  if (acceptState == AcceptState.PROG_MISMATCH) {
    out.writeInt(lowProgVersion);
    out.writeInt(highProgVersion);
  }
  ChannelBuffer b = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
      .buffer());
  RpcResponse rsp = new RpcResponse(b, remoteAddress);
  RpcUtil.sendRpcResponse(ctx, rsp);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:RpcProgram.java

示例6: writeRequested

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e)
		throws Exception {
	RpcResponse response = (RpcResponse) e.getMessage();
	ByteArrayOutputStream baos = new ByteArrayOutputStream(16384);
	//先写入标示的魔数
	baos.write(Constants.MAGIC_BYTES);
	MySerializerFactory.getInstance(Constants.DEFAULT_RPC_CODE_MODE).encodeResponse(baos, response);
	ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(baos.toByteArray());
	Channels.write(ctx, e.getFuture(), buffer);
}
 
开发者ID:zhaoshiling1017,项目名称:voyage,代码行数:12,代码来源:RpcResponseEncode.java

示例7: encode

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel ch, Object msg) throws Exception {
    com.alibaba.dubbo.remoting.buffer.ChannelBuffer buffer =
        com.alibaba.dubbo.remoting.buffer.ChannelBuffers.dynamicBuffer(1024);
    NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler);
    try {
    	codec.encode(channel, buffer, msg);
    } finally {
        NettyChannel.removeChannelIfDisconnected(ch);
    }
    return ChannelBuffers.wrappedBuffer(buffer.toByteBuffer());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:NettyCodecAdapter.java

示例8: messageReceived

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
    throws Exception {

  RpcInfo info = (RpcInfo) e.getMessage();
  RpcCall rpcCall = (RpcCall) info.header();
  final int portmapProc = rpcCall.getProcedure();
  int xid = rpcCall.getXid();
  XDR in = new XDR(info.data().toByteBuffer().asReadOnlyBuffer(),
      XDR.State.READING);
  XDR out = new XDR();

  if (portmapProc == PMAPPROC_NULL) {
    out = nullOp(xid, in, out);
  } else if (portmapProc == PMAPPROC_SET) {
    out = set(xid, in, out);
  } else if (portmapProc == PMAPPROC_UNSET) {
    out = unset(xid, in, out);
  } else if (portmapProc == PMAPPROC_DUMP) {
    out = dump(xid, in, out);
  } else if (portmapProc == PMAPPROC_GETPORT) {
    out = getport(xid, in, out);
  } else if (portmapProc == PMAPPROC_GETVERSADDR) {
    out = getport(xid, in, out);
  } else {
    LOG.info("PortmapHandler unknown rpc procedure=" + portmapProc);
    RpcAcceptedReply reply = RpcAcceptedReply.getInstance(xid,
        RpcAcceptedReply.AcceptState.PROC_UNAVAIL, new VerifierNone());
    reply.write(out);
  }

  ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
      .buffer());
  RpcResponse rsp = new RpcResponse(buf, info.remoteAddress());
  RpcUtil.sendRpcResponse(ctx, rsp);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:37,代码来源:RpcProgramPortmap.java

示例9: createDelimiter

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
private static ChannelBuffer createDelimiter(String delimiter) {
    byte[] buf = new byte[delimiter.length()];
    for (int i = 0; i < delimiter.length(); i++) {
        buf[i] = (byte) delimiter.charAt(i);
    }
    return ChannelBuffers.wrappedBuffer(buf);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:8,代码来源:CharacterDelimiterFrameDecoder.java

示例10: encode

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    Object retVal = super.encode(ctx, channel, msg);
    if (retVal instanceof CompositeChannelBuffer) {
        CompositeChannelBuffer ccb = (CompositeChannelBuffer) retVal;
        if (ccb.useGathering() != NettyUtils.DEFAULT_GATHERING) {
            List<ChannelBuffer> decompose = ccb.decompose(ccb.readerIndex(), ccb.readableBytes());
            return ChannelBuffers.wrappedBuffer(NettyUtils.DEFAULT_GATHERING,
                    decompose.toArray(new ChannelBuffer[decompose.size()]));
        }
    }
    return retVal;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:ESHttpResponseEncoder.java

示例11: exceptionCaught

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
protected void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    if (!lifecycle.started()) {
        // ignore
        return;
    }
    if (isCloseConnectionException(e.getCause())) {
        logger.trace("close connection exception caught on transport layer [{}], disconnecting from relevant node", e.getCause(), ctx.getChannel());
        // close the channel, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    } else if (isConnectException(e.getCause())) {
        logger.trace("connect exception caught on transport layer [{}]", e.getCause(), ctx.getChannel());
        // close the channel as safe measure, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    } else if (e.getCause() instanceof CancelledKeyException) {
        logger.trace("cancelled key exception caught on transport layer [{}], disconnecting from relevant node", e.getCause(), ctx.getChannel());
        // close the channel as safe measure, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    } else if (e.getCause() instanceof SizeHeaderFrameDecoder.HttpOnTransportException) {
        // in case we are able to return data, serialize the exception content and sent it back to the client
        if (ctx.getChannel().isOpen()) {
            ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(e.getCause().getMessage().getBytes(Charsets.UTF_8));
            ChannelFuture channelFuture = ctx.getChannel().write(buffer);
            channelFuture.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    future.getChannel().close();
                }
            });
        }
    } else {
        logger.warn("exception caught on transport layer [{}], closing connection", e.getCause(), ctx.getChannel());
        // close the channel, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:40,代码来源:NettyTransport.java

示例12: onNewData

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@SuppressWarnings("unused")
protected final void onNewData(final ByteBuffer data) {
    if (!mExposureSet) {
        mUiHandler.post(new Runnable() {
            @Override
            public void run() {
                if (mExposureSet)
                    return;
                setExposure();
                mExposureSet = true;
            }
        });
    }

    if (mPublisher == null)
        return;
    if (!mPublisher.hasSubscribers())
        return;

    data.order(ByteOrder.nativeOrder());
    data.rewind();

    if (mChannelBuffer == null) {
        mChannelBuffer = ChannelBuffers.wrappedBuffer(data);
    }

    mChannelBuffer.setIndex(0, mChannelBuffer.capacity());

    mCloud.getHeader().setStamp(mConnectedNode.getCurrentTime());
    mCloud.getHeader().setSeq(mSeqNum.incrementAndGet());
    mCloud.setData(mChannelBuffer);

    mPublisher.publish(mCloud);
}
 
开发者ID:nasa,项目名称:astrobee_android,代码行数:35,代码来源:MainActivity.java

示例13: sendRejectedReply

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
protected static void sendRejectedReply(RpcCall call,
    SocketAddress remoteAddress, ChannelHandlerContext ctx) {
  XDR out = new XDR();
  RpcDeniedReply reply = new RpcDeniedReply(call.getXid(),
      RpcReply.ReplyState.MSG_DENIED,
      RpcDeniedReply.RejectState.AUTH_ERROR, new VerifierNone());
  reply.write(out);
  ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
      .buffer());
  RpcResponse rsp = new RpcResponse(buf, remoteAddress);
  RpcUtil.sendRpcResponse(ctx, rsp);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:RpcProgram.java

示例14: getBuffer

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
public ChannelBuffer getBuffer(ByteBuffer nioBuffer) {
    return new NettyBackedChannelBuffer(ChannelBuffers.wrappedBuffer(nioBuffer));
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:4,代码来源:NettyBackedChannelBufferFactory.java

示例15: getBuffer

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
public ChannelBuffer getBuffer(ByteBuffer nioBuffer) {
    return new NettyBackedChannelBuffer(ChannelBuffers.wrappedBuffer(nioBuffer));
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:5,代码来源:NettyBackedChannelBufferFactory.java


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