/** * Stores a callback * * @param callbackId The id to store the callback with * @param commandCallbackWrapper The CommandCallbackWrapper to store * @param <E> The type of the remote endpoint identifier * @param <C> The type of the command * @param <R> The type of the result */ public <E, C, R> void store(String callbackId, CommandCallbackWrapper<E, C, R> commandCallbackWrapper) { CommandCallbackWrapper previous; if ((previous = callbacks.put(callbackId, commandCallbackWrapper)) != null) { //a previous callback with the same command ID was already found, we will cancel the callback as the command //is likely to be retried, so the previous one likely failed previous.reportResult(asCommandResultMessage(new CommandBusConnectorCommunicationException( "Command-callback cancelled, a new command with the same ID is entered into the command bus"))); } }
/** * Removes all callbacks for a given channel. Registered callbacks will receive a failure response containing a * {@link CommandBusConnectorCommunicationException}. * * @param channelId the channel identifier */ public void cancelCallbacks(A channelId) { Iterator<CommandCallbackWrapper> callbacks = this.callbacks.values().iterator(); while (callbacks.hasNext()) { CommandCallbackWrapper wrapper = callbacks.next(); if (wrapper.getChannelIdentifier().equals(channelId)) { wrapper.reportResult(asCommandResultMessage(new CommandBusConnectorCommunicationException( String.format("Connection error while waiting for a response on command %s", wrapper.getMessage().getCommandName())))); callbacks.remove(); } } }
/** * Stores a callback * * @param callbackId The id to store the callback with * @param commandCallbackWrapper The CommandCallbackWrapper to store * @param <E> The type of the remote endpoint identifier * @param <C> The type of the command * @param <R> The type of the result */ public <E, C, R> void store(String callbackId, CommandCallbackWrapper<E, C, R> commandCallbackWrapper) { CommandCallbackWrapper previous; if ((previous = callbacks.put(callbackId, commandCallbackWrapper)) != null) { //a previous callback with the same command ID was already found, we will cancel the callback as the command //is likely to be retried, so the previous one likely failed previous.reportResult(asCommandResultMessage(new CommandBusConnectorCommunicationException( "Command-callback cancelled, a new command with the same ID is entered into the command bus"))); } }
private void processReplyMessage(JGroupsReplyMessage message) { CommandCallbackWrapper callbackWrapper = callbackRepository.fetchAndRemove(message.getCommandIdentifier()); if (callbackWrapper == null) { logger.warn("Received a callback for a message that has either already received a callback, " + "or which was not sent through this node. Ignoring."); } else { //noinspection unchecked callbackWrapper.reportResult(message.getCommandResultMessage(serializer)); } }
/** * Removes all callbacks for a given channel. Registered callbacks will receive a failure response containing a * {@link CommandBusConnectorCommunicationException}. * * @param channelId the channel identifier */ public void cancelCallbacks(A channelId) { Iterator<CommandCallbackWrapper> callbacks = this.callbacks.values().iterator(); while (callbacks.hasNext()) { CommandCallbackWrapper wrapper = callbacks.next(); if (wrapper.getChannelIdentifier().equals(channelId)) { wrapper.reportResult(asCommandResultMessage(new CommandBusConnectorCommunicationException( String.format("Connection error while waiting for a response on command %s", wrapper.getMessage().getCommandName())))); callbacks.remove(); } } }