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


Java ChannelBufferInputStream.readByte方法代码示例

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


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

示例1: decode

import org.jboss.netty.buffer.ChannelBufferInputStream; //导入方法依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx,
    Channel channel, Object msg) throws Exception {
  if (!(msg instanceof ChannelBuffer)) {
    throw new IllegalStateException("decode: Got illegal message " + msg);
  }

  // Output metrics every 1/2 minute
  String metrics = byteCounter.getMetricsWindow(30000);
  if (metrics != null) {
    if (LOG.isInfoEnabled()) {
      LOG.info("decode: Server window metrics " + metrics);
    }
  }

  if (LOG.isDebugEnabled()) {
    startDecodingNanoseconds = TIME.getNanoseconds();
  }

  // Decode the request
  ChannelBuffer buffer = (ChannelBuffer) msg;
  ChannelBufferInputStream inputStream = new ChannelBufferInputStream(buffer);
  int enumValue = inputStream.readByte();
  RequestType type = RequestType.values()[enumValue];
  Class<? extends WritableRequest> writableRequestClass =
      type.getRequestClass();

  WritableRequest writableRequest =
      ReflectionUtils.newInstance(writableRequestClass, conf);
  writableRequest.readFields(inputStream);
  if (LOG.isDebugEnabled()) {
    LOG.debug("decode: Client " + writableRequest.getClientId() +
        ", requestId " + writableRequest.getRequestId() +
        ", " +  writableRequest.getType() + ", with size " +
        buffer.array().length + " took " +
        Times.getNanosSince(TIME, startDecodingNanoseconds) + " ns");
  }

  return writableRequest;
}
 
开发者ID:renato2099,项目名称:giraph-gora,代码行数:41,代码来源:RequestDecoder.java

示例2: decode

import org.jboss.netty.buffer.ChannelBufferInputStream; //导入方法依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx,
                        Channel channel, Object msg) throws Exception {
  if (!(msg instanceof ChannelBuffer)) {
    throw new IllegalStateException("decode: Got illegal message " + msg);
  }
  // Decode msg into an object whose class C implements WritableRequest:
  //  C will be either SaslTokenMessage or SaslComplete.
  //
  // 1. Convert message to a stream that can be decoded.
  ChannelBuffer buffer = (ChannelBuffer) msg;
  ChannelBufferInputStream inputStream = new ChannelBufferInputStream(buffer);
  // 2. Get first byte: message type:
  int enumValue = inputStream.readByte();
  RequestType type = RequestType.values()[enumValue];
  if (LOG.isDebugEnabled()) {
    LOG.debug("decode: Got a response of type " + type + " from server:" +
      channel.getRemoteAddress());
  }
  // 3. Create object of the type determined in step 2.
  Class<? extends WritableRequest> writableRequestClass =
    type.getRequestClass();
  WritableRequest serverResponse =
    ReflectionUtils.newInstance(writableRequestClass, conf);
  // 4. Deserialize the inputStream's contents into the newly-constructed
  // serverResponse object.
  try {
    serverResponse.readFields(inputStream);
  } catch (IOException e) {
    LOG.error("decode: Exception when trying to read server response: " + e);
  }
  // serverResponse can now be used in the next stage in pipeline.
  return serverResponse;
}
 
开发者ID:renato2099,项目名称:giraph-gora,代码行数:35,代码来源:SaslClientHandler.java

示例3: messageReceived

import org.jboss.netty.buffer.ChannelBufferInputStream; //导入方法依赖的package包/类
@Override
public void messageReceived(
    ChannelHandlerContext ctx, MessageEvent event) {
  if (!(event.getMessage() instanceof ChannelBuffer)) {
    throw new IllegalStateException("messageReceived: Got a " +
        "non-ChannelBuffer message " + event.getMessage());
  }

  ChannelBuffer buffer = (ChannelBuffer) event.getMessage();
  ChannelBufferInputStream inputStream = new ChannelBufferInputStream(buffer);
  int senderId = -1;
  long requestId = -1;
  int response = -1;
  try {
    senderId = inputStream.readInt();
    requestId = inputStream.readLong();
    response = inputStream.readByte();
    inputStream.close();
  } catch (IOException e) {
    throw new IllegalStateException(
        "messageReceived: Got IOException ", e);
  }

  // Simulate a failed response on the first response (if desired)
  if (dropFirstResponse && !ALREADY_DROPPED_FIRST_RESPONSE) {
    LOG.info("messageReceived: Simulating dropped response " + response +
        " for request " + requestId);
    setAlreadyDroppedFirstResponse();
    synchronized (workerIdOutstandingRequestMap) {
      workerIdOutstandingRequestMap.notifyAll();
    }
    return;
  }

  if (response == 1) {
    LOG.info("messageReceived: Already completed request " + requestId);
  } else if (response != 0) {
    throw new IllegalStateException(
        "messageReceived: Got illegal response " + response);
  }

  RequestInfo requestInfo = workerIdOutstandingRequestMap.remove(
      new ClientRequestId(senderId, requestId));
  if (requestInfo == null) {
    LOG.info("messageReceived: Already received response for request id = " +
        requestId);
  } else {
    if (LOG.isDebugEnabled()) {
      LOG.debug("messageReceived: Completed " + requestInfo +
          ".  Waiting on " + workerIdOutstandingRequestMap.size() +
          " requests");
    }
  }

  // Help NettyClient#waitSomeRequests() to finish faster
  synchronized (workerIdOutstandingRequestMap) {
    workerIdOutstandingRequestMap.notifyAll();
  }
}
 
开发者ID:renato2099,项目名称:giraph-gora,代码行数:60,代码来源:ResponseClientHandler.java

示例4: messageReceived

import org.jboss.netty.buffer.ChannelBufferInputStream; //导入方法依赖的package包/类
@Override
public void messageReceived(
    ChannelHandlerContext ctx, MessageEvent event) {
  if (!(event.getMessage() instanceof ChannelBuffer)) {
    throw new IllegalStateException("messageReceived: Got a " +
        "non-ChannelBuffer message " + event.getMessage());
  }

  ChannelBuffer buffer = (ChannelBuffer) event.getMessage();
  ChannelBufferInputStream inputStream = new ChannelBufferInputStream(buffer);
  int senderId = -1;
  long requestId = -1;
  int response = -1;
  try {
    senderId = inputStream.readInt();
    requestId = inputStream.readLong();
    response = inputStream.readByte();
    inputStream.close();
  } catch (IOException e) {
    throw new IllegalStateException(
        "messageReceived: Got IOException ", e);
  }

  // Simulate a failed response on the first response (if desired)
  if (dropFirstResponse && !ALREADY_DROPPED_FIRST_RESPONSE) {
    LOG.info("messageReceived: Simulating dropped response " + response +
        " for request " + requestId);
    ALREADY_DROPPED_FIRST_RESPONSE = true;
    synchronized (workerIdOutstandingRequestMap) {
      workerIdOutstandingRequestMap.notifyAll();
    }
    return;
  }

  if (response == 1) {
    LOG.info("messageReceived: Already completed request " + requestId);
  } else if (response != 0) {
    throw new IllegalStateException(
        "messageReceived: Got illegal response " + response);
  }

  RequestInfo requestInfo = workerIdOutstandingRequestMap.remove(
      new ClientRequestId(senderId, requestId));
  if (requestInfo == null) {
    LOG.info("messageReceived: Already received response for request id = " +
        requestId);
  } else {
    if (LOG.isDebugEnabled()) {
      LOG.debug("messageReceived: Completed " + requestInfo +
          ".  Waiting on " + workerIdOutstandingRequestMap.size() +
          " requests");
    }
  }

  // Help NettyClient#waitSomeRequests() to finish faster
  synchronized (workerIdOutstandingRequestMap) {
    workerIdOutstandingRequestMap.notifyAll();
  }
}
 
开发者ID:zfighter,项目名称:giraph-research,代码行数:60,代码来源:ResponseClientHandler.java


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