WampClient(ClientConfiguration clientConfig) { this.clientConfig = clientConfig; // Create a new stateController this.stateController = new StateController(clientConfig); }
void onSessionError(ApplicationError error, String closeReason) { boolean reconnectAllowed = !stateController.clientConfig().closeClientOnErrors(); if (!reconnectAllowed) { // Record the error that happened during the session stateController.setCloseError(error); } closeSession(error, closeReason, reconnectAllowed); }
@Override public void call() { if (stateController.currentState() != WaitingForReconnectState.this) return; // Reconnect now ConnectingState newState = new ConnectingState(stateController, nrReconnectAttempts); stateController.setState(newState); } }, stateController.clientConfig().reconnectInterval(), TimeUnit.MILLISECONDS);
@Override public void onEnter(ClientState lastState) { if (lastState instanceof InitialState) { stateController.setExternalState(new WampClient.ConnectingState()); } // Check for valid number of connects assert (nrConnectAttempts != 0); // Decrease remaining number of reconnects if it's not infinite if (nrConnectAttempts > 0) nrConnectAttempts--; // Starts an connection attempt to the router connectionController = new QueueingConnectionController(stateController.scheduler(), new ClientConnectionListener(stateController)); try { connectingCon = stateController.clientConfig().connector().connect(stateController.scheduler(), this, connectionController); } catch (Exception e) { // Catch exceptions that can happen during creating the channel // These are normally signs that something is wrong with our configuration // Therefore we don't trigger retries stateController.setCloseError(e); stateController.setExternalState(new WampClient.DisconnectedState(e)); DisconnectedState newState = new DisconnectedState(stateController, e); // This is a reentrant call to setState. However it works as onEnter is the last call in setState stateController.setState(newState); } }
@Override public void onEnter(ClientState lastState) { reconnectSubscription = stateController.rxScheduler().createWorker().schedule(new Action0() { @Override public void call() { if (stateController.currentState() != WaitingForReconnectState.this) return; // Reconnect now ConnectingState newState = new ConnectingState(stateController, nrReconnectAttempts); stateController.setState(newState); } }, stateController.clientConfig().reconnectInterval(), TimeUnit.MILLISECONDS); }
void closeSession(Throwable disconnectReason, String optCloseMessageReason, boolean reconnectAllowed) { // Send goodbye message with close reason to the remote if (optCloseMessageReason != null) { GoodbyeMessage msg = new GoodbyeMessage(null, optCloseMessageReason); connectionController.sendMessage(msg, IWampConnectionPromise.Empty); } stateController.setExternalState(new WampClient.DisconnectedState(disconnectReason)); int nrReconnectAttempts = reconnectAllowed ? stateController.clientConfig().totalNrReconnects : 0; if (nrReconnectAttempts != 0) { stateController.setExternalState(new WampClient.ConnectingState()); } clearSessionData(); WaitingForDisconnectState newState = new WaitingForDisconnectState(stateController, nrReconnectAttempts); connectionController.close(true, newState.closePromise()); stateController.setState(newState); }
/** * Is called after the low-level connection between the client and the server was established */ void sendHelloMessage() { // System.out.println("Session websocket connection established"); // Connection to the remote host was established // However the WAMP session is not established until the handshake was finished connectionController .sendMessage(new WampMessages.HelloMessage(stateController.clientConfig().realm(), stateController.clientConfig().helloDetails()), IWampConnectionPromise.Empty); }
stateController.setState(newState); List<ClientSideAuthentication> authMethods = stateController.clientConfig().authMethods(); authMethod.handleChallenge(challenge, stateController.clientConfig().objectMapper()); if (reply == null) { handleProtocolError();
@Override public void run() { if (!(stateController.currentState() instanceof SessionEstablishedState)) { resultSubject.onError(new ApplicationError(ApplicationError.NOT_CONNECTED)); return; } // Forward publish into the session SessionEstablishedState curState = (SessionEstablishedState)stateController.currentState(); curState.performPublish(topic, flags, arguments, argumentsKw, resultSubject); } });
@Override public void call() { stateController.scheduler().execute(new Runnable() { @Override public void run() {
@Override public void messageReceived(final WampMessage message) { // Remark: No need to check for connection. The controller guarantees that after close() // messages will no longer be forwarded stateController.onMessage(message); }
@Override public void transportError(final Throwable cause) { // Remark: No need to check for connection. The controller guarantees that after close() // messages will no longer be forwarded stateController.onConnectionClosed(cause); } }
/** * Closes the session.<br> * It will not be possible to open the session again with {@link #open} for safety * reasons. If a new session is required a new {@link WampClient} should be built * through the used {@link WampClientBuilder}. */ public Observable<Void> close() { stateController.initClose(); return getTerminationObservable(); }
/** * Opens the session<br> * This should be called after a subscription on {@link #statusChanged} * was installed.<br> * If the session was already opened this has no effect besides * resetting the reconnect counter.<br> * If the session was already closed through a call to {@link #close} * no new connect attempt will be performed. */ public void open() { stateController.open(); }
@Override public void onEnter(ClientState lastState) { stateController.performShutdown(); }
.observeOn(stateController.rxScheduler()) .subscribe(new Action1<Long>() { @Override
@Override public void onEnter(ClientState lastState) { if (lastState instanceof InitialState) { stateController.setExternalState(new WampClient.ConnectingState()); } // Check for valid number of connects assert (nrConnectAttempts != 0); // Decrease remaining number of reconnects if it's not infinite if (nrConnectAttempts > 0) nrConnectAttempts--; // Starts an connection attempt to the router connectionController = new QueueingConnectionController(stateController.scheduler(), new ClientConnectionListener(stateController)); try { connectingCon = stateController.clientConfig().connector().connect(stateController.scheduler(), this, connectionController); } catch (Exception e) { // Catch exceptions that can happen during creating the channel // These are normally signs that something is wrong with our configuration // Therefore we don't trigger retries stateController.setCloseError(e); stateController.setExternalState(new WampClient.DisconnectedState(e)); DisconnectedState newState = new DisconnectedState(stateController, e); // This is a reentrant call to setState. However it works as onEnter is the last call in setState stateController.setState(newState); } }
@Override public void onEnter(ClientState lastState) { reconnectSubscription = stateController.rxScheduler().createWorker().schedule(new Action0() { @Override public void call() { if (stateController.currentState() != WaitingForReconnectState.this) return; // Reconnect now ConnectingState newState = new ConnectingState(stateController, nrReconnectAttempts); stateController.setState(newState); } }, stateController.clientConfig().reconnectInterval(), TimeUnit.MILLISECONDS); }
void closeSession(Throwable disconnectReason, String optCloseMessageReason, boolean reconnectAllowed) { // Send goodbye message with close reason to the remote if (optCloseMessageReason != null) { GoodbyeMessage msg = new GoodbyeMessage(null, optCloseMessageReason); connectionController.sendMessage(msg, IWampConnectionPromise.Empty); } stateController.setExternalState(new WampClient.DisconnectedState(disconnectReason)); int nrReconnectAttempts = reconnectAllowed ? stateController.clientConfig().totalNrReconnects : 0; if (nrReconnectAttempts != 0) { stateController.setExternalState(new WampClient.ConnectingState()); } clearSessionData(); WaitingForDisconnectState newState = new WaitingForDisconnectState(stateController, nrReconnectAttempts); connectionController.close(true, newState.closePromise()); stateController.setState(newState); }
/** * Is called after the low-level connection between the client and the server was established */ void sendHelloMessage() { // System.out.println("Session websocket connection established"); // Connection to the remote host was established // However the WAMP session is not established until the handshake was finished connectionController .sendMessage(new WampMessages.HelloMessage(stateController.clientConfig().realm(), stateController.clientConfig().helloDetails()), IWampConnectionPromise.Empty); }