List of usage examples for io.netty.buffer ByteBuf readLong
public abstract long readLong();
From source file:buildcraft.core.network.serializers.SerializerLong.java
License:Minecraft Mod Public
@Override public Object read(ByteBuf data, Object o, SerializationContext context) { return new Long(data.readLong()); }
From source file:com.almuradev.guide.server.network.play.S00PageInformation.java
License:MIT License
@Override public void fromBytes(ByteBuf buf) { identifier = ByteBufUtils.readUTF8String(buf); index = buf.readInt();/* w ww.j ava 2 s . co m*/ title = ByteBufUtils.readUTF8String(buf); created = new Date(buf.readLong()); author = ByteBufUtils.readUTF8String(buf); lastModified = new Date(buf.readLong()); lastContributor = ByteBufUtils.readUTF8String(buf); contents = ByteBufUtils.readUTF8String(buf); }
From source file:com.couchbase.client.core.endpoint.dcp.DCPHandler.java
License:Apache License
@Override protected CouchbaseResponse decodeResponse(ChannelHandlerContext ctx, FullBinaryMemcacheResponse msg) throws Exception { DCPRequest request = currentRequest(); DCPResponse response = null;/*www . ja v a 2s . c o m*/ if (msg.getOpcode() == OP_STREAM_REQUEST && request instanceof StreamRequestRequest) { StreamRequestRequest streamRequest = (StreamRequestRequest) request; ByteBuf content = msg.content(); List<FailoverLogEntry> failoverLog = null; long rollbackToSequenceNumber = 0; KeyValueStatus status = KeyValueStatus.valueOf(msg.getStatus()); switch (status) { case SUCCESS: failoverLog = readFailoverLogs(content); break; case ERR_ROLLBACK: rollbackToSequenceNumber = content.readLong(); break; default: LOGGER.warn("Unexpected status of StreamRequestResponse: {} (0x{}, {})", status, Integer.toHexString(status.code()), status.description()); } response = new StreamRequestResponse(ResponseStatusConverter.fromBinary(msg.getStatus()), failoverLog, rollbackToSequenceNumber, request); connection.registerContext(request.partition(), ctx); connection.consumed(request.partition(), msg.getTotalBodyLength()); } else if (msg.getOpcode() == OP_STREAM_CLOSE && request instanceof StreamCloseRequest) { response = new StreamCloseResponse(ResponseStatusConverter.fromBinary(msg.getStatus()), request); } else if (msg.getOpcode() == OP_GET_FAILOVER_LOG && request instanceof GetFailoverLogRequest) { response = new GetFailoverLogResponse(ResponseStatusConverter.fromBinary(msg.getStatus()), readFailoverLogs(msg.content()), request); } else if (msg.getOpcode() == OP_GET_LAST_CHECKPOINT && request instanceof GetLastCheckpointRequest) { long sequenceNumber = msg.content().readLong(); response = new GetLastCheckpointResponse(ResponseStatusConverter.fromBinary(msg.getStatus()), sequenceNumber, request); } else if (msg.getOpcode() == OP_BUFFER_ACK) { KeyValueStatus status = KeyValueStatus.valueOf(msg.getStatus()); if (status != KeyValueStatus.SUCCESS) { LOGGER.warn("Unexpected status of service response (opcode={}): {} (0x{}, {})", Integer.toHexString(msg.getOpcode()), status, Integer.toHexString(status.code()), status.description()); } } else { /** * FIXME * There are two cases: * * 1) Queue is empty: * In this case outer method {@link AbstractGenericHandler#decode} picks 'null' * as a current request, and it will might lead to NPEs because it does not cover * scenario when we receive some packet without request in the queue. * * 2) Queue is not empty: * In this case we might notify about errors wrong observable in the outer method, * so we have to substitute it as soon as we detected that incoming message is not * relevant to 'current request' */ final DCPRequest oldRequest = currentRequest(); final DCPRequest dummy = new AbstractDCPRequest(connection.bucket(), null) { }; dummy.observable().subscribe(new Action1<CouchbaseResponse>() { @Override public void call(CouchbaseResponse couchbaseResponse) { // skip } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { connection.subject().onError(throwable); } }); try { currentRequest(dummy); handleDCPRequest(ctx, msg); } finally { currentRequest(oldRequest); } } if (request != null && request.partition() >= 0 && response != null) { response.partition(request.partition()); } if (response != null || request == null) { finishedDecoding(); } return response; }
From source file:com.couchbase.client.core.endpoint.dcp.DCPHandler.java
License:Apache License
/** * Handles incoming stream of DCP messages. *//*from ww w. j av a 2 s . co m*/ private void handleDCPRequest(final ChannelHandlerContext ctx, final FullBinaryMemcacheResponse msg) { DCPRequest request = null; int flags = 0; long bySeqno = 0; long revSeqno = 0; switch (msg.getOpcode()) { case OP_SNAPSHOT_MARKER: long startSequenceNumber = 0; long endSequenceNumber = 0; if (msg.getExtrasLength() > 0) { final ByteBuf extras = msg.getExtras(); startSequenceNumber = extras.readLong(); endSequenceNumber = extras.readLong(); flags = extras.readInt(); } request = new SnapshotMarkerMessage(msg.getTotalBodyLength(), msg.getStatus(), startSequenceNumber, endSequenceNumber, flags, connection.bucket()); break; case OP_MUTATION: int expiration = 0; int lockTime = 0; if (msg.getExtrasLength() > 0) { final ByteBuf extras = msg.getExtras(); bySeqno = extras.readLong(); revSeqno = extras.readLong(); flags = extras.readInt(); expiration = extras.readInt(); lockTime = extras.readInt(); } request = new MutationMessage(msg.getTotalBodyLength(), msg.getStatus(), new String(msg.getKey(), CHARSET), msg.content().retain(), expiration, bySeqno, revSeqno, flags, lockTime, msg.getCAS(), connection.bucket()); break; case OP_REMOVE: if (msg.getExtrasLength() > 0) { final ByteBuf extras = msg.getExtras(); bySeqno = extras.readLong(); revSeqno = extras.readLong(); } request = new RemoveMessage(msg.getTotalBodyLength(), msg.getStatus(), new String(msg.getKey(), CHARSET), msg.getCAS(), bySeqno, revSeqno, connection.bucket()); break; case OP_EXPIRATION: if (msg.getExtrasLength() > 0) { final ByteBuf extras = msg.getExtras(); bySeqno = extras.readLong(); revSeqno = extras.readLong(); } request = new ExpirationMessage(msg.getTotalBodyLength(), msg.getStatus(), new String(msg.getKey(), CHARSET), msg.getCAS(), bySeqno, revSeqno, connection.bucket()); break; case OP_STREAM_END: final ByteBuf extras = msg.getExtras(); StreamEndMessage.Reason reason = StreamEndMessage.Reason.valueOf(extras.readInt()); request = new StreamEndMessage(msg.getTotalBodyLength(), msg.getStatus(), reason, connection.bucket()); connection.streamClosed(request.partition(), reason); break; default: LOGGER.info("Unhandled DCP message: {}, {}", msg.getOpcode(), msg); } if (request != null) { connection.subject().onNext(request); } }
From source file:com.couchbase.client.core.endpoint.dcp.DCPHandler.java
License:Apache License
private List<FailoverLogEntry> readFailoverLogs(final ByteBuf content) { List<FailoverLogEntry> failoverLog = new ArrayList<FailoverLogEntry>(content.readableBytes() / 16); while (content.readableBytes() >= 16) { FailoverLogEntry entry = new FailoverLogEntry(content.readLong(), content.readLong()); failoverLog.add(entry);//from ww w.ja va 2 s .c o m } return failoverLog; }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandler.java
License:Apache License
private static MutationToken extractToken(String bucket, boolean seqOnMutation, boolean success, ByteBuf extras, long vbid) { if (success && seqOnMutation) { return new MutationToken(vbid, extras.readLong(), extras.readLong(), bucket); }//from www. j a v a 2 s . c o m return null; }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandler.java
License:Apache License
/** * Helper method to decode all other response messages. * * @param request the current request./*from w w w . j a v a2 s . c o m*/ * @param msg the current response message. * @param status the response status code. * @return the decoded response or null if none did match. */ private static CouchbaseResponse handleOtherResponseMessages(BinaryRequest request, FullBinaryMemcacheResponse msg, ResponseStatus status, boolean seqOnMutation, String remoteHostname) { CouchbaseResponse response = null; ByteBuf content = msg.content(); long cas = msg.getCAS(); short statusCode = msg.getStatus(); String bucket = request.bucket(); if (request instanceof UnlockRequest) { response = new UnlockResponse(status, statusCode, bucket, content, request); } else if (request instanceof TouchRequest) { response = new TouchResponse(status, statusCode, bucket, content, request); } else if (request instanceof AppendRequest) { MutationToken descr = extractToken(bucket, seqOnMutation, status.isSuccess(), msg.getExtras(), request.partition()); response = new AppendResponse(status, statusCode, cas, bucket, content, descr, request); } else if (request instanceof PrependRequest) { MutationToken descr = extractToken(bucket, seqOnMutation, status.isSuccess(), msg.getExtras(), request.partition()); response = new PrependResponse(status, statusCode, cas, bucket, content, descr, request); } else if (request instanceof KeepAliveRequest) { releaseContent(content); response = new KeepAliveResponse(status, statusCode, request); } else if (request instanceof CounterRequest) { long value = status.isSuccess() ? content.readLong() : 0; releaseContent(content); MutationToken descr = extractToken(bucket, seqOnMutation, status.isSuccess(), msg.getExtras(), request.partition()); response = new CounterResponse(status, statusCode, bucket, value, cas, descr, request); } else if (request instanceof StatRequest) { String key = new String(msg.getKey(), CHARSET); String value = content.toString(CHARSET); releaseContent(content); response = new StatResponse(status, statusCode, remoteHostname, key, value, bucket, request); } else if (request instanceof GetAllMutationTokensRequest) { // 2 bytes for partition ID, and 8 bytes for sequence number MutationToken[] mutationTokens = new MutationToken[content.readableBytes() / 10]; for (int i = 0; i < mutationTokens.length; i++) { mutationTokens[i] = new MutationToken((long) content.readShort(), 0, content.readLong(), request.bucket()); } releaseContent(content); response = new GetAllMutationTokensResponse(mutationTokens, status, statusCode, bucket, request); } else if (request instanceof ObserveRequest) { byte observed = ObserveResponse.ObserveStatus.UNKNOWN.value(); long observedCas = 0; if (status.isSuccess()) { short keyLength = content.getShort(2); observed = content.getByte(keyLength + 4); observedCas = content.getLong(keyLength + 5); } releaseContent(content); response = new ObserveResponse(status, statusCode, observed, ((ObserveRequest) request).master(), observedCas, bucket, request); } else if (request instanceof ObserveSeqnoRequest) { if (status.isSuccess()) { byte format = content.readByte(); switch (format) { case 0: response = new NoFailoverObserveSeqnoResponse(((ObserveSeqnoRequest) request).master(), content.readShort(), content.readLong(), content.readLong(), content.readLong(), status, statusCode, bucket, request); break; case 1: response = new FailoverObserveSeqnoResponse(((ObserveSeqnoRequest) request).master(), content.readShort(), content.readLong(), content.readLong(), content.readLong(), content.readLong(), content.readLong(), status, statusCode, bucket, request); break; default: throw new IllegalStateException("Unknown format for observe-seq: " + format); } } else { response = new NoFailoverObserveSeqnoResponse(((ObserveSeqnoRequest) request).master(), (short) 0, 0, 0, 0, status, statusCode, bucket, request); } releaseContent(content); } return response; }
From source file:com.crowsofwar.gorecore.util.GoreCoreByteBufUtil.java
License:Open Source License
public static UUID readUUID(ByteBuf buf) { return new UUID(buf.readLong(), buf.readLong()); }
From source file:com.ctrip.xpipe.redis.console.health.netty.EchoClientHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { ByteBuf buf = (ByteBuf) msg; System.out.println((System.nanoTime() - buf.readLong()) / 1000); }
From source file:com.datastax.driver.core.CBUtil.java
License:Apache License
public static UUID readUUID(ByteBuf cb) { long msb = cb.readLong(); long lsb = cb.readLong(); return new UUID(msb, lsb); }