本文整理汇总了Java中org.onosproject.store.cluster.messaging.MessagingException类的典型用法代码示例。如果您正苦于以下问题:Java MessagingException类的具体用法?Java MessagingException怎么用?Java MessagingException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessagingException类属于org.onosproject.store.cluster.messaging包,在下文中一共展示了MessagingException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendAndReceive
import org.onosproject.store.cluster.messaging.MessagingException; //导入依赖的package包/类
protected <T, U> CompletableFuture<U> sendAndReceive(MessageSubject subject, T request, MemberId memberId) {
CompletableFuture<U> future = new CompletableFuture<>();
clusterCommunicator.<T, U>sendAndReceive(
request, subject, serializer::encode, serializer::decode, NodeId.nodeId(memberId.id()))
.whenComplete((result, error) -> {
if (error == null) {
future.complete(result);
} else {
if (error instanceof CompletionException) {
error = error.getCause();
}
if (error instanceof MessagingException.NoRemoteHandler) {
error = new ConnectException(error.getMessage());
} else if (error instanceof MessagingException.RemoteHandlerFailure
|| error instanceof MessagingException.ProtocolException) {
error = new RaftException.ProtocolException(error.getMessage());
}
future.completeExceptionally(error);
}
});
return future;
}
示例2: addSubscriber
import org.onosproject.store.cluster.messaging.MessagingException; //导入依赖的package包/类
@Override
public <M, R> void addSubscriber(
MessageSubject subject,
Function<byte[], M> decoder,
Function<M, R> handler,
Function<R, byte[]> encoder,
Executor executor) {
subscribers.put(subject, message -> {
CompletableFuture<byte[]> future = new CompletableFuture<>();
executor.execute(() -> {
try {
future.complete(encoder.apply(handler.apply(decoder.apply(message))));
} catch (Exception e) {
future.completeExceptionally(new MessagingException.RemoteHandlerFailure());
}
});
return future;
});
}
示例3: dispatch
import org.onosproject.store.cluster.messaging.MessagingException; //导入依赖的package包/类
/**
* Dispatches a message to a local handler.
*
* @param message the message to dispatch
*/
private void dispatch(InternalReply message) {
if (message.preamble() != preamble) {
log.debug("Received {} with invalid preamble", message.type());
return;
}
clockService.recordEventTime(message.time());
Callback callback = completeCallback(message.id());
if (callback != null) {
if (message.status() == InternalReply.Status.OK) {
callback.complete(message.payload());
} else if (message.status() == InternalReply.Status.ERROR_NO_HANDLER) {
callback.completeExceptionally(new MessagingException.NoRemoteHandler());
} else if (message.status() == InternalReply.Status.ERROR_HANDLER_EXCEPTION) {
callback.completeExceptionally(new MessagingException.RemoteHandlerFailure());
} else if (message.status() == InternalReply.Status.PROTOCOL_EXCEPTION) {
callback.completeExceptionally(new MessagingException.ProtocolException());
}
} else {
log.debug("Received a reply for message id:[{}] "
+ "but was unable to locate the"
+ " request handle", message.id());
}
}
示例4: sendAndReceive
import org.onosproject.store.cluster.messaging.MessagingException; //导入依赖的package包/类
@Override
public <M, R> CompletableFuture<R> sendAndReceive(
M message,
MessageSubject subject,
Function<M, byte[]> encoder,
Function<byte[], R> decoder,
NodeId toNodeId) {
TestClusterCommunicationService node = nodes.get(toNodeId);
if (node == null) {
return Futures.exceptionalFuture(new MessagingException.NoRemoteHandler());
}
return node.handle(subject, encoder.apply(message)).thenApply(decoder);
}
示例5: handle
import org.onosproject.store.cluster.messaging.MessagingException; //导入依赖的package包/类
private CompletableFuture<byte[]> handle(MessageSubject subject, byte[] message) {
Function<byte[], CompletableFuture<byte[]>> subscriber = subscribers.get(subject);
if (subscriber != null) {
return subscriber.apply(message);
}
return Futures.exceptionalFuture(new MessagingException.NoRemoteHandler());
}
示例6: reply
import org.onosproject.store.cluster.messaging.MessagingException; //导入依赖的package包/类
@Override
public void reply(InternalRequest message, InternalReply.Status status, Optional<byte[]> payload) {
if (future != null) {
if (status == InternalReply.Status.OK) {
future.complete(payload.orElse(EMPTY_PAYLOAD));
} else if (status == InternalReply.Status.ERROR_NO_HANDLER) {
future.completeExceptionally(new MessagingException.NoRemoteHandler());
} else if (status == InternalReply.Status.ERROR_HANDLER_EXCEPTION) {
future.completeExceptionally(new MessagingException.RemoteHandlerFailure());
} else if (status == InternalReply.Status.PROTOCOL_EXCEPTION) {
future.completeExceptionally(new MessagingException.ProtocolException());
}
}
}