/** * 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); }
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; } }
/** * 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); }
/** * 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 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); } }
.toSubject(subject) .with("ErrorMessage", errorMessage) .with("AdditionalDetails", additionalDetails)
/** * 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); } }
@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); } }
.toSubject(BuiltInServices.ClientBus.name()) .command(BusCommand.WebsocketChannelOpen) .with(MessageParts.WebSocketToken, reconnectionToken)
/** * 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); }
public void send(T value, MessageCallback replyTo) { MessageBuilder.createMessage() .toSubject(toSubject) .withValue(value) .done().repliesTo(replyTo).sendNowWith(messageBus); }
public void onClick(ClickEvent clickEvent) { MessageBuilder.createMessage() .toSubject("AuthenticationService") .command(SecurityCommands.EndSession) .noErrorHandling().sendNowWith(ErraiBus.get()); } }
public void run() { createMessage() .toSubject("AuthorizationService") .with(MessageParts.ReplyTo, "AuthorizationListener") .noErrorHandling().sendNowWith(ErraiBus.get()); } };
@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); } }
/** * 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); }
public void closeTab(String instanceId) { MessageBuilder.createMessage() .toSubject(getInstanceSubject(instanceId)) .command(LayoutCommands.CloseTab) .with(LayoutParts.InstanceID, instanceId) .noErrorHandling().sendNowWith(ErraiBus.get()); }
public void onClick(ClickEvent clickEvent) { Log.debug("ToolID: "+ tool.getId()); MessageBuilder.createMessage() .toSubject(Workspace.SUBJECT) .command(LayoutCommands.ActivateTool) .with(LayoutParts.TOOL, tool.getId()) .with(LayoutParts.TOOLSET, toolSetId) .noErrorHandling() .sendNowWith(ErraiBus.get()); } }
public static Subscription subscribe(final String eventType, final AbstractCDIEventCallback<?> callback) { if (isRemoteCommunicationEnabled() && ErraiBus.get() instanceof ClientMessageBusImpl && ((ClientMessageBusImpl) ErraiBus.get()).getState().equals(BusState.CONNECTED)) { MessageBuilder.createMessage() .toSubject(CDI.SERVER_DISPATCHER_SUBJECT) .command(CDICommands.RemoteSubscribe) .with(CDIProtocol.BeanType, eventType) .with(CDIProtocol.Qualifiers, callback.getQualifiers()) .noErrorHandling().sendNowWith(ErraiBus.get()); } return subscribeLocal(eventType, callback, false); }