/** * 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(); } } }
/** * Resolve the JGroups Address of the given {@code Member}. * * @param destination The node of which to solve the Address * @return The JGroups Address of the given node * * @throws CommandBusConnectorCommunicationException when an error occurs resolving the adress */ protected Address resolveAddress(Member destination) { return destination.getConnectionEndpoint(Address.class) .orElseThrow(() -> new CommandBusConnectorCommunicationException( "The target member doesn't expose a JGroups endpoint" )); }
/** * Resolve the JGroups Address of the given {@code Member}. * * @param destination The node of which to solve the Address * @return The JGroups Address of the given node * * @throws CommandBusConnectorCommunicationException when an error occurs resolving the adress */ protected Address resolveAddress(Member destination) { return destination.getConnectionEndpoint(Address.class).orElseThrow( () -> new CommandBusConnectorCommunicationException( "The target member doesn't expose a JGroups endpoint")); }
/** * 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.fail(new CommandBusConnectorCommunicationException( "Command-callback cancelled, a new command with the same ID is entered into the command bus")); } }
/** * 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.fail(new CommandBusConnectorCommunicationException( String.format("Connection error while waiting for a response on command %s", wrapper.getMessage().getCommandName()))); callbacks.remove(); } } }
/** * 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(); } } }