本文整理汇总了Java中com.couchbase.client.deps.io.netty.buffer.Unpooled类的典型用法代码示例。如果您正苦于以下问题:Java Unpooled类的具体用法?Java Unpooled怎么用?Java Unpooled使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Unpooled类属于com.couchbase.client.deps.io.netty.buffer包,在下文中一共展示了Unpooled类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterFailoverLogResponse
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void filterFailoverLogResponse(ByteBuf buf) {
try {
Promise<ByteBuf> promise =
(Promise<ByteBuf>) dcpChannel.outstandingPromises.remove(MessageUtil.getOpaque(buf));
short vbid = dcpChannel.outstandingVbucketInfos.remove(MessageUtil.getOpaque(buf));
ByteBuf flog = Unpooled.buffer();
DcpFailoverLogResponse.init(flog);
DcpFailoverLogResponse.vbucket(flog, DcpFailoverLogResponse.vbucket(buf));
ByteBuf copiedBuf = MessageUtil.getContent(buf).copy().writeShort(vbid);
MessageUtil.setContent(copiedBuf, flog);
copiedBuf.release();
promise.setSuccess(flog);
} finally {
buf.release();
}
}
示例2: hello
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
private void hello(ChannelHandlerContext ctx, ByteBuf msg) {
connectionName = connectionNameGenerator.name();
String response = MessageUtil.getContent(msg).toString(CharsetUtil.UTF_8);
int majorVersion;
try {
majorVersion = Integer.parseInt(response.substring(0, 1));
} catch (NumberFormatException e) {
originalPromise().setFailure(
new IllegalStateException("Version returned by the server couldn't be parsed " + response, e));
ctx.close(ctx.voidPromise());
return;
}
if (majorVersion < 5) {
step = OPEN;
open(ctx);
} else {
ByteBuf request = ctx.alloc().buffer();
HelloRequest.init(request, Unpooled.copiedBuffer(connectionName, CharsetUtil.UTF_8));
ctx.writeAndFlush(request);
}
}
示例3: negotiate
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
/**
* Helper method to walk the iterator and create a new request that defines which control param
* should be negotiated right now.
*/
private void negotiate(final ChannelHandlerContext ctx) {
if (controlSettings.hasNext()) {
Map.Entry<String, String> setting = controlSettings.next();
LOGGER.debug("Negotiating DCP Control {}: {}", setting.getKey(), setting.getValue());
ByteBuf request = ctx.alloc().buffer();
DcpControlRequest.init(request);
DcpControlRequest.key(Unpooled.copiedBuffer(setting.getKey(), CharsetUtil.UTF_8), request);
DcpControlRequest.value(Unpooled.copiedBuffer(setting.getValue(), CharsetUtil.UTF_8), request);
ctx.writeAndFlush(request);
} else {
originalPromise().setSuccess();
ctx.pipeline().remove(this);
ctx.fireChannelActive();
LOGGER.debug("Negotiated all DCP Control settings against Node {}", ctx.channel().remoteAddress());
}
}
示例4: closeStream
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
public Completable closeStream(final short vbid) {
return Completable.create(new Completable.OnSubscribe() {
@Override
public void call(final CompletableSubscriber subscriber) {
if (state() != LifecycleState.CONNECTED) {
subscriber.onError(new NotConnectedException());
return;
}
LOGGER.debug("Closing Stream against {} with vbid: {}", channel.remoteAddress(), vbid);
int opaque = OPAQUE.incrementAndGet();
ChannelPromise promise = channel.newPromise();
ByteBuf buffer = Unpooled.buffer();
DcpCloseStreamRequest.init(buffer);
DcpCloseStreamRequest.vbucket(buffer, vbid);
DcpCloseStreamRequest.opaque(buffer, opaque);
outstandingPromises.put(opaque, promise);
channel.writeAndFlush(buffer);
promise.addListener(new GenericFutureListener<ChannelFuture>() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
openStreams.set(vbid, 0);
if (future.isSuccess()) {
LOGGER.debug("Closed Stream against {} with vbid: {}", channel.remoteAddress(), vbid);
subscriber.onCompleted();
} else {
LOGGER.debug("Failed close Stream against {} with vbid: {}", channel.remoteAddress(), vbid);
subscriber.onError(future.cause());
}
}
});
}
});
}
示例5: getSeqnos
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
/**
* Returns all seqnos for all vbuckets on that channel.
*/
public Single<ByteBuf> getSeqnos() {
return Single.create(new Single.OnSubscribe<ByteBuf>() {
@Override
public void call(final SingleSubscriber<? super ByteBuf> subscriber) {
if (state() != LifecycleState.CONNECTED) {
subscriber.onError(new NotConnectedException());
return;
}
int opaque = OPAQUE.incrementAndGet();
Promise<ByteBuf> promise = new DefaultPromise<ByteBuf>(channel.eventLoop());
ByteBuf buffer = Unpooled.buffer();
DcpGetPartitionSeqnosRequest.init(buffer);
DcpGetPartitionSeqnosRequest.opaque(buffer, opaque);
DcpGetPartitionSeqnosRequest.vbucketState(buffer, VbucketState.ACTIVE);
outstandingPromises.put(opaque, promise);
channel.writeAndFlush(buffer);
promise.addListener(new GenericFutureListener<Future<ByteBuf>>() {
@Override
public void operationComplete(Future<ByteBuf> future) throws Exception {
if (future.isSuccess()) {
subscriber.onSuccess(future.getNow());
} else {
subscriber.onError(future.cause());
}
}
});
}
});
}
示例6: getFailoverLog
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
public Single<ByteBuf> getFailoverLog(final short vbid) {
return Single.create(new Single.OnSubscribe<ByteBuf>() {
@Override
public void call(final SingleSubscriber<? super ByteBuf> subscriber) {
if (state() != LifecycleState.CONNECTED) {
subscriber.onError(new NotConnectedException());
return;
}
int opaque = OPAQUE.incrementAndGet();
Promise<ByteBuf> promise = new DefaultPromise<ByteBuf>(channel.eventLoop());
ByteBuf buffer = Unpooled.buffer();
DcpFailoverLogRequest.init(buffer);
DcpFailoverLogRequest.opaque(buffer, opaque);
DcpFailoverLogRequest.vbucket(buffer, vbid);
outstandingPromises.put(opaque, promise);
outstandingVbucketInfos.put(opaque, vbid);
channel.writeAndFlush(buffer);
LOGGER.debug("Asked for failover log on {} for vbid: {}", channel.remoteAddress(), vbid);
promise.addListener(new GenericFutureListener<Future<ByteBuf>>() {
@Override
public void operationComplete(Future<ByteBuf> future) throws Exception {
if (future.isSuccess()) {
LOGGER.debug("Failover log for vbid {} is {}", vbid, DcpFailoverLogResponse.toString(future.getNow()));
subscriber.onSuccess(future.getNow());
} else {
LOGGER.debug("Failed to ask for failover log on {} for vbid: {}", channel.remoteAddress(), vbid);
subscriber.onError(future.cause());
}
}
});
}
});
}
示例7: filterOpenStreamResponse
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
private boolean filterOpenStreamResponse(ChannelFlowController flowController, ByteBuf buf) {
try {
Promise<?> promise = dcpChannel.outstandingPromises.remove(MessageUtil.getOpaque(buf));
short vbid = dcpChannel.outstandingVbucketInfos.remove(MessageUtil.getOpaque(buf));
short status = MessageUtil.getStatus(buf);
switch (status) {
case 0x00:
promise.setSuccess(null);
// create a failover log message and emit
ByteBuf flog = Unpooled.buffer();
DcpFailoverLogResponse.init(flog);
DcpFailoverLogResponse.vbucket(flog, DcpOpenStreamResponse.vbucket(buf));
ByteBuf content = MessageUtil.getContent(buf).copy().writeShort(vbid);
MessageUtil.setContent(content, flog);
content.release();
controlEventHandler.onEvent(flowController, flog);
break;
case 0x23:
promise.setFailure(new RollbackException());
// create a rollback message and emit
ByteBuf rb = Unpooled.buffer();
RollbackMessage.init(rb, vbid, DcpOpenStreamResponse.rollbackSeqno(buf));
controlEventHandler.onEvent(flowController, rb);
break;
case 0x07:
promise.setFailure(new NotMyVbucketException());
break;
default:
promise.setFailure(new IllegalStateException("Unhandled Status: " + status));
}
return false;
} finally {
buf.release();
}
}
示例8: open
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
private void open(ChannelHandlerContext ctx) {
ByteBuf request = ctx.alloc().buffer();
DcpOpenConnectionRequest.init(request);
DcpOpenConnectionRequest.connectionName(request, Unpooled.copiedBuffer(connectionName, CharsetUtil.UTF_8));
ctx.writeAndFlush(request);
}
示例9: testInit
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
@Test
public void testInit() {
ByteBuf buffer = Unpooled.buffer();
assertFalse(DcpOpenConnectionRequest.is(buffer));
DcpOpenConnectionRequest.init(buffer);
assertEquals(32, buffer.writerIndex());
assertTrue(DcpOpenConnectionRequest.is(buffer));
}
示例10: testSetConnectionName
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
@Test
public void testSetConnectionName() {
ByteBuf buffer = Unpooled.buffer();
DcpOpenConnectionRequest.init(buffer);
ByteBuf name = Unpooled.copiedBuffer("name", CharsetUtil.UTF_8);
DcpOpenConnectionRequest.connectionName(buffer, name);
assertEquals("name", DcpOpenConnectionRequest.connectionName(buffer).toString(CharsetUtil.UTF_8));
}
示例11: convertRecord
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
@Override
public Iterable<TupleDocument> convertRecord(String outputSchema, GenericRecord inputRecord, WorkUnitState workUnit)
throws DataConversionException {
String key = inputRecord.get(keyField).toString();
GenericRecord data = (GenericRecord) inputRecord.get(dataRecordField);
ByteBuffer dataBytes = (ByteBuffer) data.get(valueField);
Integer flags = (Integer) data.get(flagsField);
ByteBuf buffer = Unpooled.copiedBuffer(dataBytes);
return new SingleRecordIterable<>(new TupleDocument(key, Tuple.create(buffer, flags)));
}
示例12: openStream
import com.couchbase.client.deps.io.netty.buffer.Unpooled; //导入依赖的package包/类
public Completable openStream(final short vbid, final long vbuuid, final long startSeqno, final long endSeqno,
final long snapshotStartSeqno, final long snapshotEndSeqno) {
return Completable.create(new Completable.OnSubscribe() {
@Override
public void call(final CompletableSubscriber subscriber) {
if (state() != LifecycleState.CONNECTED) {
subscriber.onError(new NotConnectedException());
return;
}
LOGGER.debug("Opening Stream against {} with vbid: {}, vbuuid: {}, startSeqno: {}, " +
"endSeqno: {}, snapshotStartSeqno: {}, snapshotEndSeqno: {}",
channel.remoteAddress(), vbid, vbuuid, startSeqno, endSeqno, snapshotStartSeqno, snapshotEndSeqno);
int opaque = OPAQUE.incrementAndGet();
ChannelPromise promise = channel.newPromise();
ByteBuf buffer = Unpooled.buffer();
DcpOpenStreamRequest.init(buffer, vbid);
DcpOpenStreamRequest.opaque(buffer, opaque);
DcpOpenStreamRequest.vbuuid(buffer, vbuuid);
DcpOpenStreamRequest.startSeqno(buffer, startSeqno);
DcpOpenStreamRequest.endSeqno(buffer, endSeqno);
DcpOpenStreamRequest.snapshotStartSeqno(buffer, snapshotStartSeqno);
DcpOpenStreamRequest.snapshotEndSeqno(buffer, snapshotEndSeqno);
outstandingPromises.put(opaque, promise);
outstandingVbucketInfos.put(opaque, vbid);
channel.writeAndFlush(buffer);
promise.addListener(new GenericFutureListener<ChannelFuture>() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
LOGGER.debug("Opened Stream against {} with vbid: {}", channel.remoteAddress(), vbid);
openStreams.set(vbid, 1);
subscriber.onCompleted();
} else {
LOGGER.debug("Failed open Stream against {} with vbid: {}", channel.remoteAddress(), vbid);
openStreams.set(vbid, 0);
subscriber.onError(future.cause());
}
}
});
}
});
}