本文整理汇总了Java中io.atomix.catalyst.util.reference.ReferenceCounted类的典型用法代码示例。如果您正苦于以下问题:Java ReferenceCounted类的具体用法?Java ReferenceCounted怎么用?Java ReferenceCounted使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReferenceCounted类属于io.atomix.catalyst.util.reference包,在下文中一共展示了ReferenceCounted类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRequestSuccess
import io.atomix.catalyst.util.reference.ReferenceCounted; //导入依赖的package包/类
/**
* Handles a request response.
*/
private void handleRequestSuccess(long requestId, Object response, ThreadContext context) {
ByteBuf buffer = channel.alloc().buffer(10)
.writeByte(RESPONSE)
.writeLong(requestId)
.writeByte(SUCCESS);
try {
writeResponse(buffer, response, context);
} catch (SerializationException e) {
handleRequestFailure(requestId, e, context);
return;
}
channel.writeAndFlush(buffer, channel.voidPromise());
if (response instanceof ReferenceCounted) {
((ReferenceCounted) response).release();
}
}
示例2: sendRequest
import io.atomix.catalyst.util.reference.ReferenceCounted; //导入依赖的package包/类
/**
* Sends a request.
*/
private void sendRequest(Object request, ContextualFuture future) {
if (open && connection.open) {
long requestId = ++this.requestId;
futures.put(requestId, future);
connection.handleRequest(requestId, request);
} else {
future.context.executor().execute(() -> future.completeExceptionally(new ConnectException("connection closed")));
}
if (request instanceof ReferenceCounted) {
((ReferenceCounted<?>) request).release();
}
}
示例3: writeRequest
import io.atomix.catalyst.util.reference.ReferenceCounted; //导入依赖的package包/类
/**
* Writes a request to the given buffer.
*/
private ByteBuf writeRequest(ByteBuf buffer, Object request, ThreadContext context) {
context.serializer().writeObject(request, OUTPUT.get().setByteBuf(buffer));
if (request instanceof ReferenceCounted) {
((ReferenceCounted) request).release();
}
return buffer;
}
示例4: read
import io.atomix.catalyst.util.reference.ReferenceCounted; //导入依赖的package包/类
@Override
public T read(Class<T> type, BufferInput buffer, Serializer serializer) {
if (ReferenceCounted.class.isAssignableFrom(type)) {
return readReference(type, buffer, serializer);
} else {
return readObject(type, buffer, serializer);
}
}
示例5: createFactory
import io.atomix.catalyst.util.reference.ReferenceCounted; //导入依赖的package包/类
/**
* Dynamically created a reference factory for a pooled type.
*/
private ReferenceFactory<?> createFactory(final Constructor<?> constructor) {
return manager -> {
try {
return (ReferenceCounted<?>) constructor.newInstance(manager);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new SerializationException("failed to instantiate reference", e);
}
};
}