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


Java ChannelBufferInputStream.readLong方法代码示例

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


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

示例1: messageReceived

import org.jboss.netty.buffer.ChannelBufferInputStream; //导入方法依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
		throws Exception {
	// wait for and interpret the response message from the
	// server
	// only the HTTP OK response is accepted i.e. 200.
	// if (LOG.isDebugEnabled()) {
	// LOG.debug("Server response received");
	// }

	// LOG.info("----------------- Server response received");

	ChannelBuffer buff = (ChannelBuffer) e.getMessage();

	ChannelBufferInputStream in = new ChannelBufferInputStream(buff);
	try {
		int status = in.readInt();

		if (status == ClientHandlerContext.STATUS_OK) {
			clientHandlerContext
					.setServerStatusCode(ClientHandlerContext.STATUS_OK);
			// only if ok copy the data over.
		} else if (status == ClientHandlerContext.STATUS_CONFLICT) {
			// when a conflict message is sent it means that the file
			// line pointer
			// is not the same as that held by the collectors
			// here we set the status to conflict and set the file line
			// pointer on the intermediate pointer to
			// that indicated by the server
			long fileLinePointer = in.readLong();
			if (fileLinePointer < 0) {
				throw new ServerException(
						"Server send 409 by fileLinePointer is not valid. Collector send pointer: "
								+ fileLinePointer
								+ ". Please check the coordination service",
						ClientHandlerContext.STATUS_CONFLICT);
			}
			clientHandlerContext
					.setServerStatusCode(ClientHandlerContext.STATUS_CONFLICT);

			clientHandlerContext.getIntermediatePointer()
					.setConflictFilePointer(fileLinePointer);
		} else {
			clientHandlerContext.setServerStatusCode(status);
		}
	} finally {
		in.close();
	}

	if (!exhanged.getAndSet(true)) {
		exchanger.exchange(clientHandlerContext, sendTimeOut,
				TimeUnit.MILLISECONDS);
	}

	super.messageReceived(ctx, e);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:57,代码来源:ClientConnectionImpl.java

示例2: 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

示例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);
    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.readLong方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。