if (getState() == BusState.CONNECTED) { setBusToInitializableState(); remoteSubscribe(BuiltInServices.ServerEchoService.name()); if (!isSubscribed(DefaultErrorCallback.CLIENT_ERROR_SUBJECT)) { directSubscribe(DefaultErrorCallback.CLIENT_ERROR_SUBJECT, clientBusErrorsCallback, false); if (!isSubscribed(BuiltInServices.ClientBus.name())) { directSubscribe(BuiltInServices.ClientBus.name(), protocolCommandCallback, false); loadRpcProxies();
@Override public void configure(final Message capabilitiesMessage) { configured = true; if (!isSSESupported()) { hosed = true; unsupportedReason = UNSUPPORTED_MESSAGE_NO_SERVER_SUPPORT; logger.warn("this browser does not support SSE"); return; } this.sseEntryPoint = URL.encode(clientMessageBus.getApplicationLocation(clientMessageBus.getInServiceEntryPoint())) + "?&sse=1&clientId=" + URL.encodePathSegment(clientMessageBus.getClientId()); }
private String getWebSocketNegotiationString() { return "{\"" + MessageParts.CommandType.name() + "\":\"" + BusCommand.Associate.name() + "\", \"" + MessageParts.ConnectionSessionKey + "\":\"" + messageBus.getSessionId() + "\"" + ",\"" + MessageParts.WebSocketToken + "\":\"" + webSocketToken + "\"}"; }
private Subscription _subscribe(final String subject, final MessageCallback callback, final boolean local) { if (getState() == BusState.CONNECTING) { return _subscribeDeferred(subject, callback, local); } else { return _subscribeNow(subject, callback, local); } }
unsubscribeAll(message.get(String.class, Subject)); break; encodeAndTransmit(CommandMessage.create() .toSubject(BuiltInServices.ServerBus.name()).command(BusCommand.RemoteSubscribe) .set(PriorityProcessing, "1") setState(BusState.CONNECTED); sendAllDeferred(); InitVotes.voteFor(ClientMessageBus.class); logger.info("session expired while in state " + getState() + ": attempting to reset ..."); stop(false, new BusTransportError(transportHandler, null, new SessionExpiredException(), -1, new RetryInfo(0, 0))); init(); stop(false); if (message.hasPart(MessageParts.Reason)) { managementConsole
subscribe((String)message.getParts().get(MessageParts.ReplyTo.name()), this::signalInterceptorsAfter); if (getState().isShadowDeliverable() && shadowSubscriptions.containsKey(subject)) { deliverToSubscriptions(shadowSubscriptions, subject, message); delivered = true; else if (getState() != BusState.CONNECTED) { logger.debug("deferred: {}", message); deferredMessages.add(message); deliverToSubscriptions(subscriptions, subject, message); deliverToSubscriptions(localSubscriptions, subject, message); deliverToSubscriptions(shadowSubscriptions, subject, message); callErrorHandler(message, e);
logger.info("initializing client bus in offline mode (erraiBusRemoteCommunicationEnabled was set to false)"); InitVotes.voteFor(ClientMessageBus.class); setState(BusState.LOCAL_ONLY); return; if (!getState().isStartableState()) { logger.warn("aborting startup. bus is not in correct state. (current state: " + getState() + ")"); return; setState(BusState.CONNECTING); if (!isProperty(ChaosMonkey.DONT_REALLY_CONNECT, "true")) { final Map<String, String> properties = new HashMap<>(); properties.put("phase", "connection"); .set(ToSubject, "ServerBus") .set(PriorityProcessing, "1") .set(MessageParts.RemoteServices, getAdvertisableSubjects()) .setResource(TransportHandler.EXTRA_URI_PARMS_RESOURCE, properties)));
@Override public void handleProtocolExtension(final Message message) { switch (BusCommand.valueOf(message.getCommandType())) { case WebsocketChannelVerify: logger.info("received verification token for websocket connection"); longPollingTransport .transmit(Collections.singletonList(CommandMessage.create() .toSubject(BuiltInServices.ServerBus.name()).command(BusCommand.WebsocketChannelVerify) .copy(MessageParts.WebSocketToken, message))); break; case WebsocketChannelOpen: if (messageBus.getState() == BusState.CONNECTION_INTERRUPTED) messageBus.setState(BusState.CONNECTED); // send final message to open the channel transmitToSocket(webSocketChannel, getWebSocketNegotiationString()); longPollingTransport.stop(false); webSocketToken = message.get(String.class, MessageParts.WebSocketToken); logger.info("web socket channel successfully negotiated. comet channel deactivated. (reconnect token: " + webSocketToken + ")"); retries = 0; break; case WebsocketNegotiationFailed: hosed = true; unsupportedReason = "Negotiation Failed (Bad Key)"; disconnectSocket(webSocketChannel); webSocketChannel = null; messageBus.reconsiderTransport(); break; } }
logger.info("Bus State : " + (bus.getState())); logger.info("Wire Protocol : V3.JSON"); logger.info("Active Channel : " + (!federatedApp ? "None" : (bus.getTransportHandler()))); final TransportStatistics stats = bus.getTransportHandler().getStatistics(); final Collection<TransportHandler> allAvailableHandlers = bus.getAllAvailableHandlers(); logger.info(" > " + handler.getStatistics().getTransportDescription() + " " + (handler == bus.getTransportHandler() ? "**" : ""));
@PostConstruct private void setup() { performLoginStatusChangeActions(userCache.getUser()); final User preloadedUser = userCache.getUser(); InitVotes.waitFor(SecurityContext.class); if (User.ANONYMOUS.equals(preloadedUser)) { InitVotes.registerOneTimeDependencyCallback(ClientMessageBus.class, () -> { if (((ClientMessageBusImpl) ErraiBus.get()).getState() == BusState.CONNECTED) { initializeCacheFromServer(); } else { // Don't cause initialization to fail if remote communication is disabled InitVotes.voteFor(SecurityContext.class); } }); } else { InitVotes.voteFor(SecurityContext.class); } }
private boolean directSubscribe(final String subject, final MessageCallback callback, final boolean local, final WrappedCallbackHolder callbackHolder) { final boolean isNew = !isSubscribed(subject); final MessageCallback cb = new MessageCallback() { @Override public void callback(final Message message) { try { callback.callback(message); } catch (final Exception e) { handleCallbackError(message, e); } } }; callbackHolder.setWrappedCallback(cb); if (local) { addLocalSubscriptionEntry(subject, cb); } else { addSubscriptionEntry(subject, cb); } return isNew; }
parmsMap = new HashMap<String, String>(extraParameters); parmsMap.put("wait", "1"); serviceEntryPoint = messageBus.getInServiceEntryPoint(); waitChannel = true; serviceEntryPoint = messageBus.getOutServiceEntryPoint(); waitChannel = false; URL.encode(messageBus.getApplicationLocation(serviceEntryPoint)) + "?z=" + getNextRequestNumber() + "&clientId=" + URL.encodePathSegment(messageBus.getClientId()) + extraParmsString.toString() ); builder.setHeader("Content-Type", "application/json; charset=utf-8");
@Override public void run() { final ClientMessageBusImpl bus = (ClientMessageBusImpl) ErraiBus.get(); if (!bus.isSubscribed(CDI.CLIENT_DISPATCHER_SUBJECT)) { logger.info("declare CDI dispatch service"); bus.subscribe(CDI.CLIENT_DISPATCHER_SUBJECT, new MessageCallback() { @Override public void callback(final Message message) { switch (CDICommands.valueOf(message.getCommandType())) { case AttachRemote: CDI.activate(message.get(String.class, MessageParts.RemoteServices).split(",")); break; case RemoteSubscribe: CDI.addRemoteEventTypes(message.get(String[].class, MessageParts.Value)); break; case CDIEvent: CDI.consumeEventFromMessage(message); break; } } }); } } };
public SSEHandler(final ClientMessageBusImpl clientMessageBus) { this.clientMessageBus = clientMessageBus; this.pollingHandler = HttpPollingHandler.newNoPollingInstance(clientMessageBus); sseAgentSubscription = clientMessageBus.subscribe(SSE_AGENT_SERVICE, new MessageCallback() { @Override public void callback(final Message message) { notifyConnected(); } }); }
@Override public String getApplicationLocation(String serviceEntryPoint) { Configuration configuration = GWT.create(Configuration.class); if (configuration instanceof Configuration.NotSpecified) { throw new IllegalArgumentException("you need to implement Configuration in order to point to the server location"); } LOG.info("url end point " + configuration.getRemoteLocation()); return super.getApplicationLocation(serviceEntryPoint); } }
/** * Add a subscription for the specified subject * * @param subject * - the subject to add a subscription for * @param callback * - function called when the message is dispatched */ @Override public Subscription subscribe(final String subject, final MessageCallback callback) { return _subscribe(subject, callback, false); }
private void addSubscriptionEntry(final String subject, final MessageCallback reference) { _addCallbackEntry(subscriptions, subject, reference); }
unsubscribeAll(message.get(String.class, Subject)); break; encodeAndTransmit(CommandMessage.create() .toSubject(BuiltInServices.ServerBus.name()).command(BusCommand.RemoteSubscribe) .set(PriorityProcessing, "1") setState(BusState.CONNECTED); sendAllDeferred(); InitVotes.voteFor(ClientMessageBus.class); logger.info("session expired while in state " + getState() + ": attempting to reset ..."); stop(false, new BusTransportError(transportHandler, null, new SessionExpiredException(), -1, new RetryInfo(0, 0))); init(); stop(false); if (message.hasPart(MessageParts.Reason)) { managementConsole