/** * Initiates the close process.<br> * Will be called on {@link WampClient#close()} of the client */ public void initClose() { tryScheduleAction(new Runnable() { @Override public void run() { if (isCompleted) return;// Check if already closed isCompleted = true; // Initialize the close sequence // The state will try to move to the final state currentState.initClose(); } }); }
/** * Initiates the close process.<br> * Will be called on {@link WampClient#close()} of the client */ public void initClose() { tryScheduleAction(new Runnable() { @Override public void run() { if (isCompleted) return;// Check if already closed isCompleted = true; // Initialize the close sequence // The state will try to move to the final state currentState.initClose(); } }); }
/** * Initiates the close process.<br> * Will be called on {@link WampClient#close()} of the client */ public void initClose() { tryScheduleAction(new Runnable() { @Override public void run() { if (isCompleted) return;// Check if already closed isCompleted = true; // Initialize the close sequence // The state will try to move to the final state currentState.initClose(); } }); }
@Override public void connectFailed(final Throwable cause) { stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (!isCancelled) { // Try reconnect if possible, otherwise announce close if (nrConnectAttempts != 0) { // Reconnect is allowed WaitingForReconnectState nextState = new WaitingForReconnectState(stateController, nrConnectAttempts); stateController.setState(nextState); } else { stateController.setExternalState(new WampClient.DisconnectedState(cause)); DisconnectedState nextState = new DisconnectedState(stateController, cause); stateController.setState(nextState); } } else { // Connection cancel attempt was successfully cancelled. // This is the final state stateController.setExternalState(new WampClient.DisconnectedState(null)); DisconnectedState nextState = new DisconnectedState(stateController, null); stateController.setState(nextState); } } }); }
@Override public void connectFailed(final Throwable cause) { stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (!isCancelled) { // Try reconnect if possible, otherwise announce close if (nrConnectAttempts != 0) { // Reconnect is allowed WaitingForReconnectState nextState = new WaitingForReconnectState(stateController, nrConnectAttempts); stateController.setState(nextState); } else { stateController.setExternalState(new WampClient.DisconnectedState(cause)); DisconnectedState nextState = new DisconnectedState(stateController, cause); stateController.setState(nextState); } } else { // Connection cancel attempt was successfully cancelled. // This is the final state stateController.setExternalState(new WampClient.DisconnectedState(null)); DisconnectedState nextState = new DisconnectedState(stateController, null); stateController.setState(nextState); } } }); }
@Override public void connectFailed(final Throwable cause) { stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (!isCancelled) { // Try reconnect if possible, otherwise announce close if (nrConnectAttempts != 0) { // Reconnect is allowed WaitingForReconnectState nextState = new WaitingForReconnectState(stateController, nrConnectAttempts); stateController.setState(nextState); } else { stateController.setExternalState(new WampClient.DisconnectedState(cause)); DisconnectedState nextState = new DisconnectedState(stateController, cause); stateController.setState(nextState); } } else { // Connection cancel attempt was successfully cancelled. // This is the final state stateController.setExternalState(new WampClient.DisconnectedState(null)); DisconnectedState nextState = new DisconnectedState(stateController, null); stateController.setState(nextState); } } }); }
@Override public void call() { stateController.tryScheduleAction(new Runnable() { @Override public void run() {
@Override public void call() { stateController.tryScheduleAction(new Runnable() { @Override public void run() {
@Override public void connectSucceeded(final IWampConnection connection) { boolean wasScheduled = stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (!isCancelled) { // Our new channel is connected connectionController.setConnection(connection); HandshakingState newState = new HandshakingState(stateController, connectionController, nrConnectAttempts); stateController.setState(newState); } else { // We we're connected but aren't interested in the channel anymore // The client should close // Therefore we close the new channel stateController.setExternalState(new WampClient.DisconnectedState(null)); WaitingForDisconnectState newState = new WaitingForDisconnectState(stateController, nrConnectAttempts); connection.close(false, newState.closePromise()); stateController.setState(newState); } } }); if (!wasScheduled) { // If the client was closed before the connection // succeeds, close the connection connection.close(false, IWampConnectionPromise.Empty); } }
/** * Send a normal response to the request.<br> * If this is called more than once then the following invocations will * have no effect. Responses will be only sent once. * @param arguments The positional arguments to sent in the response * @param keywordArguments The keyword arguments to sent in the response */ public void reply(ArrayNode arguments, ObjectNode keywordArguments) { int replyWasSent = replySentUpdater.getAndSet(this, 1); if (replyWasSent == 1) return; final YieldMessage msg = new YieldMessage(requestId, null, arguments, keywordArguments); stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (stateController.currentState() != session) return; session.connectionController().sendMessage(msg, IWampConnectionPromise.Empty); } }); }
/** * Send a normal response to the request.<br> * If this is called more than once then the following invocations will * have no effect. Responses will be only sent once. * @param arguments The positional arguments to sent in the response * @param keywordArguments The keyword arguments to sent in the response */ public void reply(ArrayNode arguments, ObjectNode keywordArguments) { int replyWasSent = replySentUpdater.getAndSet(this, 1); if (replyWasSent == 1) return; final YieldMessage msg = new YieldMessage(requestId, null, arguments, keywordArguments); stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (stateController.currentState() != session) return; session.connectionController().sendMessage(msg, IWampConnectionPromise.Empty); } }); }
/** * Send a normal response to the request.<br> * If this is called more than once then the following invocations will * have no effect. Responses will be only sent once. * @param arguments The positional arguments to sent in the response * @param keywordArguments The keyword arguments to sent in the response */ public void reply(ArrayNode arguments, ObjectNode keywordArguments) { int replyWasSent = replySentUpdater.getAndSet(this, 1); if (replyWasSent == 1) return; final YieldMessage msg = new YieldMessage(requestId, null, arguments, keywordArguments); stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (stateController.currentState() != session) return; session.connectionController().sendMessage(msg, IWampConnectionPromise.Empty); } }); }
/** * Send an error message in response to the request.<br> * If this is called more than once then the following invocations will * have no effect. Respones will be only sent once. * @param errorUri The error message that should be sent. This must be a * valid WAMP Uri. * @param arguments The positional arguments to sent in the response * @param keywordArguments The keyword arguments to sent in the response */ public void replyError(String errorUri, ArrayNode arguments, ObjectNode keywordArguments) throws ApplicationError { int replyWasSent = replySentUpdater.getAndSet(this, 1); if (replyWasSent == 1) return; UriValidator.validate(errorUri, false); final ErrorMessage msg = new ErrorMessage(WampMessages.InvocationMessage.ID, requestId, null, errorUri, arguments, keywordArguments); stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (stateController.currentState() != session) return; session.connectionController().sendMessage(msg, IWampConnectionPromise.Empty); } }); }
/** * Send an error message in response to the request.<br> * If this is called more than once then the following invocations will * have no effect. Respones will be only sent once. * @param errorUri The error message that should be sent. This must be a * valid WAMP Uri. * @param arguments The positional arguments to sent in the response * @param keywordArguments The keyword arguments to sent in the response */ public void replyError(String errorUri, ArrayNode arguments, ObjectNode keywordArguments) throws ApplicationError { int replyWasSent = replySentUpdater.getAndSet(this, 1); if (replyWasSent == 1) return; UriValidator.validate(errorUri, false); final ErrorMessage msg = new ErrorMessage(WampMessages.InvocationMessage.ID, requestId, null, errorUri, arguments, keywordArguments); stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (stateController.currentState() != session) return; session.connectionController().sendMessage(msg, IWampConnectionPromise.Empty); } }); }
/** * Send an error message in response to the request.<br> * If this is called more than once then the following invocations will * have no effect. Respones will be only sent once. * @param errorUri The error message that should be sent. This must be a * valid WAMP Uri. * @param arguments The positional arguments to sent in the response * @param keywordArguments The keyword arguments to sent in the response */ public void replyError(String errorUri, ArrayNode arguments, ObjectNode keywordArguments) throws ApplicationError { int replyWasSent = replySentUpdater.getAndSet(this, 1); if (replyWasSent == 1) return; UriValidator.validate(errorUri, false); final ErrorMessage msg = new ErrorMessage(WampMessages.InvocationMessage.ID, requestId, null, errorUri, arguments, keywordArguments); stateController.tryScheduleAction(new Runnable() { @Override public void run() { if (stateController.currentState() != session) return; session.connectionController().sendMessage(msg, IWampConnectionPromise.Empty); } }); }
@Override public void call(final Subscriber<? super Request> subscriber) { try { UriValidator.validate(topic, clientConfig.useStrictUriValidation()); } catch (WampError e) { subscriber.onError(e); return; } boolean wasScheduled = stateController.tryScheduleAction(new Runnable() { @Override public void run() { // If the Subscriber unsubscribed in the meantime we return early if (subscriber.isUnsubscribed()) return; // Set subscription to completed if we are not connected if (!(stateController.currentState() instanceof SessionEstablishedState)) { subscriber.onCompleted(); return; } // Forward publish into the session SessionEstablishedState curState = (SessionEstablishedState) stateController.currentState(); curState.performRegisterProcedure(topic, flags, subscriber); } }); if (!wasScheduled) { subscriber.onError( new ApplicationError(ApplicationError.CLIENT_CLOSED)); } } });
boolean wasScheduled = stateController.tryScheduleAction(new Runnable() { @Override public void run() {
boolean wasScheduled = stateController.tryScheduleAction(new Runnable() { @Override public void run() {
boolean wasScheduled = stateController.tryScheduleAction(new Runnable() { @Override public void run() {