public <T, R> T call(final RemoteCallback<R> callback, final Class<T> remoteService) { return call(callback, null, remoteService); }
@Override public void setValue(final T responseValue) { createConversation(incomingMessage) .subjectProvided() .with("MethodReply", responseValue) .noErrorHandling().reply(); } }
/** * Sends a disconnect command message to the client bus * * @param bus * - the bus responsible for sending messages for the server * @param message * - the message that has encountered the error */ public static void disconnectRemoteBus(MessageBus bus, Message message) { MessageBuilder.createConversation(message) .toSubject("ClientBus") .command(BusCommand.Disconnect) .noErrorHandling().sendNowWith(bus); }
@Override public void onSubscribe(final SubscriptionEvent event) { if (event.isLocalOnly() || event.isRemote() || event.getSubject().startsWith("local:")) return; MessageBuilder.createMessage() .toSubject(BuiltInServices.ClientBus.name()) .command(BusCommand.RemoteSubscribe) .with(MessageParts.Subject, event.getSubject()) .noErrorHandling().sendGlobalWith(ServerMessageBusImpl.this); } }
public static void sendClientError(MessageBus bus, String queueId, String errorMessage, String additionalDetails) { try { MessageBuilder.createMessage() .toSubject(DefaultErrorCallback.CLIENT_ERROR_SUBJECT) .with("ErrorMessage", errorMessage) .with("AdditionalDetails", additionalDetails) .with(MessageParts.SessionID, queueId) .flag(RoutingFlag.NonGlobalRouting) .noErrorHandling().sendNowWith(bus); } catch (RuntimeException e) { // note: this is handled this way, because this is shared server and client code. if (e.getClass().getName().equals("org.jboss.errai.bus.server.QueueUnavailableException")) { // ignore. } throw e; } }
.with(MessageParts.ErrorMessage, e.getMessage()) .with(MessageParts.AdditionalDetails, a.toString()) .with(MessageParts.Throwable, e) .noErrorHandling().sendNowWith(ErraiBus.get()); .toSubject(CLIENT_ERROR_SUBJECT) .with(MessageParts.ErrorMessage, e.getMessage()) .with(MessageParts.AdditionalDetails, a.toString()) .with(MessageParts.Throwable, e) .noErrorHandling().reply(); if (message == null) { createMessage(CLIENT_ERROR_SUBJECT) .with(MessageParts.ErrorMessage, "Null exception reference") .with(MessageParts.AdditionalDetails, "No additional details") .noErrorHandling().sendNowWith(ErraiBus.get()); .toSubject(CLIENT_ERROR_SUBJECT) .with(MessageParts.ErrorMessage, "Null exception reference") .with(MessageParts.AdditionalDetails, "No additional details") .noErrorHandling().reply();
.toSubject(subject) .with("ErrorMessage", errorMessage) .with("AdditionalDetails", additionalDetails) .with(MessageParts.ErrorTo, message.get(String.class, MessageParts.ErrorTo)) .with(MessageParts.Throwable, message.getResource(Object.class, "Exception")) .noErrorHandling().sendNowWith(bus);
protected static void invokeDefaultErrorHandlers(final Throwable throwable) { MessageBuilder.createMessage(DefaultErrorCallback.CLIENT_ERROR_SUBJECT).signalling() .with(MessageParts.Throwable, throwable).defaultErrorHandling().sendNowWith(ErraiBus.get()); } }
/** * Sends a ping request to the server. If the ping response is not received * within a reasonable time limit, notifyDisconnected() will be called. */ private void verifyConnected() { // in case we were in the middle of something already pingTimeout.cancel(); transmit(Collections.singletonList(MessageBuilder.createMessage() .toSubject("ServerEchoService") .signalling().done().repliesToSubject(SSE_AGENT_SERVICE).getMessage())); pingTimeout.schedule(2500); }
@Override public void callback(final Message message) { createConversation(message) .subjectProvided() .with("MethodReply", invokeMethodFromMessage(message)) .noErrorHandling().sendNowWith(bus); } }
public void callback(Message c) { MessageBuilder.createConversation(c) .subjectProvided().noErrorHandling() .sendNowWith(bus); } });
/** * Creates a new message for the provided subject. * * @param subject * the subject the message should be sent to * @return a <tt>MessageBuildSubject</tt> which essentially is a <tt>Message</tt>, but ensures that the user * constructs messages properly */ @SuppressWarnings({ "unchecked" }) public static MessageBuildCommand<MessageBuildSendableWithReply> createMessage(final String subject) { return new DefaultMessageBuilder(provider.get()).start().toSubject(subject); }
/** * Creates an RPC call, with no error handling. * * @param callback * The remote callback that receives the return value from the call. Cannot not be null. * @param service * The remote interface. * @param <T> * The type of the remote service. * @param <R> * The return type of the invoked method. * @return A proxy for the remote service. Methods invoked on this object will communicate with the remote service * over the message bus. */ public static <R, T> T createCall(final RemoteCallback<R> callback, final Class<T> service) { return new DefaultRemoteCallBuilder(CommandMessage.create()).call(callback, service); }
@SuppressWarnings("unchecked") public void sendRequest(final MessageBus bus, final RemoteCallSendable sendable) { if (batch != null) { batch.addRequest(sendable); } else { sendable.sendNowWith(bus); } }
/** * Creates an <tt>AbstractRemoteCallBuilder</tt> to construct a call. * * @return an instance of <tt>AbstractRemoteCallBuilder</tt> */ public static DefaultRemoteCallBuilder createCall() { return new DefaultRemoteCallBuilder(CommandMessage.create()); }
@Override public void onUnsubscribe(final SubscriptionEvent event) { if (event.isLocalOnly() || event.isRemote() || event.getSubject().startsWith("local:")) return; if (messageQueues.isEmpty()) return; MessageBuilder.createMessage() .toSubject(BuiltInServices.ClientBus.name()) .command(BusCommand.RemoteUnsubscribe) .with(MessageParts.Subject, event.getSubject()) .noErrorHandling().sendGlobalWith(ServerMessageBusImpl.this); } }
private void notifyDisconnected() { connected = false; pingTimeout.cancel(); logger.info(this + " channel disconnected."); connectedTime = -1; clientMessageBus.setState(BusState.CONNECTION_INTERRUPTED); disconnect(sseChannel); if (!stopped) { if (retries == 0) { transmit(Collections.singletonList(MessageBuilder.createMessage() .toSubject("ServerEchoService") .signalling().done().repliesToSubject(SSE_AGENT_SERVICE).getMessage())); } final int retryDelay = Math.min((retries * 1000) + 1, 10000); logger.info("attempting SSE reconnection in " + retryDelay + "ms -- attempt: " + (++retries)); new Timer() { @Override public void run() { if (!stopped) { start(); } } }.schedule(retryDelay); } }
@Override public void callback(final Message message) { invokeMethodFromMessage(message); createConversation(message) .subjectProvided() .noErrorHandling().sendNowWith(bus); } }
/** * Creates a conversational message for the provided subject. * * @param message * reference message to create conversation from * @param subject * the subject the message should be sent to * @return a <tt>MessageBuildSubject</tt> which essentially is a <tt>Message</tt>, but ensures that the user * constructs messages properly */ public static MessageBuildCommand<MessageReplySendable> createConversation(final Message message, final String subject) { final Message newMessage = provider.get(); if (newMessage instanceof HasEncoded) { return new DefaultMessageBuilder<MessageReplySendable>(new HasEncodedConvMessageWrapper(message, newMessage)) .start() .toSubject(subject); } else { return new DefaultMessageBuilder<MessageReplySendable>(new ConversationMessageWrapper(message, newMessage)) .start() .toSubject(subject); } }
/** * Creates an RPC call with error handling. * * @param callback * The remote callback that receives the return value from the call. Cannot not be null. * @param errorCallback * The error callback that receives transmission errors and exceptions thrown by the remote service. Cannot not be null. * @param service * The remote interface. * @param <T> * The type of the remote service. * @param <R> * The return type of the invoked method. * @return A proxy for the remote service. Methods invoked on this object will communicate with the remote service * over the message bus. */ public static <R, T> T createCall(final RemoteCallback<R> callback, final BusErrorCallback errorCallback, final Class<T> service) { return new DefaultRemoteCallBuilder(CommandMessage.create()).call(callback, errorCallback, service); }