本文整理汇总了Java中org.jboss.netty.buffer.ChannelBufferInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelBufferInputStream.close方法的具体用法?Java ChannelBufferInputStream.close怎么用?Java ChannelBufferInputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.buffer.ChannelBufferInputStream
的用法示例。
在下文中一共展示了ChannelBufferInputStream.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入方法依赖的package包/类
/**
* Handles a prepared WebSocket API invocation
* @param asMap true if the JSON reponse is a map, false if it is an array
* @param request The prepared HTTP request so we can piggy-back on the existing RpcHandler services.
* @param response The JSONResponse to write back to
* @throws IOException thrown on IO errors
*/
protected void invoke(boolean asMap, HttpRequest request, JSONResponse response) throws IOException {
try {
JsonGenerator generator = response.writeHeader(asMap);
InvocationChannel ichannel = new InvocationChannel();
HttpQuery query = new HttpQuery(tsdb, request, ichannel);
String baseRoute = query.getQueryBaseRoute();
rpcHandler.messageReceived(null, new UpstreamMessageEvent(ichannel, request, null));
HttpResponse resp = (HttpResponse)ichannel.getWrites().get(0);
ChannelBuffer content = resp.getContent();
ChannelBufferInputStream cbis = new ChannelBufferInputStream(content);
ObjectReader reader = jsonMapper.reader();
JsonNode contentNode = reader.readTree(cbis);
cbis.close();
if(asMap) {
ObjectNode on = (ObjectNode)contentNode;
Iterator<Map.Entry<String, JsonNode>> nodeIter = on.fields();
while(nodeIter.hasNext()) {
Map.Entry<String, JsonNode> node = nodeIter.next();
generator.writeObjectField(node.getKey(), node.getValue());
}
} else {
ArrayNode an = (ArrayNode)contentNode;
for(int i = 0; i < an.size(); i++) {
generator.writeObject(an.get(i));
}
}
response.closeGenerator();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例2: 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);
}
示例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();
}
}
示例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();
}
}