@Override public <C> void dispatch(CommandMessage<C> command) { LoggingCallback loggingCallback = LoggingCallback.INSTANCE; if (NoOpMessageMonitor.INSTANCE.equals(messageMonitor)) { CommandMessage<? extends C> interceptedCommand = intercept(command); Optional<Member> optionalDestination = commandRouter.findDestination(interceptedCommand); if (optionalDestination.isPresent()) { Member destination = optionalDestination.get(); try { connector.send(destination, interceptedCommand); } catch (Exception e) { destination.suspect(); loggingCallback.onResult(interceptedCommand, asCommandResultMessage( new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e) )); } } else { loggingCallback.onResult(interceptedCommand, asCommandResultMessage(new NoHandlerForCommandException( format("No node known to accept [%s]", interceptedCommand.getCommandName()) ))); } } else { dispatch(command, loggingCallback); } }
/** * Updates the load factor of this node compared to other nodes registered with the {@link CommandRouter}. * * @param loadFactor the new load factor of this node */ public void updateLoadFactor(int loadFactor) { this.loadFactor = loadFactor; commandRouter.updateMembership(loadFactor, commandFilter.get()); }
CommandMessage<? extends C> interceptedCommand = intercept(command); MessageMonitor.MonitorCallback messageMonitorCallback = messageMonitor.onMessageIngested(interceptedCommand); Optional<Member> optionalDestination = commandRouter.findDestination(interceptedCommand); if (optionalDestination.isPresent()) { Member destination = optionalDestination.get();
private void updateFilter(CommandMessageFilter newFilter) { if (!commandFilter.getAndSet(newFilter).equals(newFilter)) { commandRouter.updateMembership(loadFactor, newFilter); } }
@Override public <C> void dispatch(CommandMessage<C> command) { if (NoOpMessageMonitor.INSTANCE.equals(messageMonitor)) { CommandMessage<? extends C> interceptedCommand = intercept(command); Member destination = commandRouter.findDestination(interceptedCommand) .orElseThrow(() -> new NoHandlerForCommandException( format("No node known to accept [%s]", interceptedCommand.getCommandName()))); try { connector.send(destination, interceptedCommand); } catch(Exception e) { destination.suspect(); throw new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e); } } else { dispatch(command, null); } }
/** * Updates the load factor of this node compared to other nodes registered with the {@link CommandRouter}. * * @param loadFactor the new load factor of this node */ public void updateLoadFactor(int loadFactor) { this.loadFactor = loadFactor; commandRouter.updateMembership(loadFactor, commandFilter.get()); }
@Override public <C> void dispatch(CommandMessage<C> command) { LoggingCallback loggingCallback = LoggingCallback.INSTANCE; if (NoOpMessageMonitor.INSTANCE.equals(messageMonitor)) { CommandMessage<? extends C> interceptedCommand = intercept(command); Optional<Member> optionalDestination = commandRouter.findDestination(interceptedCommand); if (optionalDestination.isPresent()) { Member destination = optionalDestination.get(); try { connector.send(destination, interceptedCommand); } catch (Exception e) { destination.suspect(); loggingCallback.onResult(interceptedCommand, asCommandResultMessage( new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e) )); } } else { loggingCallback.onResult(interceptedCommand, asCommandResultMessage(new NoHandlerForCommandException( format("No node known to accept [%s]", interceptedCommand.getCommandName()) ))); } } else { dispatch(command, loggingCallback); } }
/** * Updates the load factor of this node compared to other nodes registered with the {@link CommandRouter}. * * @param loadFactor the new load factor of this node */ public void updateLoadFactor(int loadFactor) { this.loadFactor = loadFactor; commandRouter.updateMembership(loadFactor, commandFilter.get()); }
/** * {@inheritDoc} * * @throws CommandDispatchException when an error occurs while dispatching the command to a segment */ @Override public <C, R> void dispatch(CommandMessage<C> command, CommandCallback<? super C, R> callback) { CommandMessage<? extends C> interceptedCommand = intercept(command); MessageMonitor.MonitorCallback messageMonitorCallback = messageMonitor.onMessageIngested(interceptedCommand); Member destination = commandRouter.findDestination(interceptedCommand) .orElseThrow(() -> { NoHandlerForCommandException exception = new NoHandlerForCommandException( format("No node known to accept [%s]", interceptedCommand.getCommandName())); messageMonitorCallback.reportFailure(exception); return exception; }); try { connector.send(destination, interceptedCommand, new MonitorAwareCallback<>(callback, messageMonitorCallback)); } catch(Exception e) { messageMonitorCallback.reportFailure(e); destination.suspect(); throw new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e); } }
private void updateFilter(CommandMessageFilter newFilter) { if (!commandFilter.getAndSet(newFilter).equals(newFilter)) { commandRouter.updateMembership(loadFactor, newFilter); } }
CommandMessage<? extends C> interceptedCommand = intercept(command); MessageMonitor.MonitorCallback messageMonitorCallback = messageMonitor.onMessageIngested(interceptedCommand); Optional<Member> optionalDestination = commandRouter.findDestination(interceptedCommand); if (optionalDestination.isPresent()) { Member destination = optionalDestination.get();
private void updateFilter(Predicate<CommandMessage<?>> newFilter) { if (!commandFilter.getAndSet(newFilter).equals(newFilter)) { commandRouter.updateMembership(loadFactor, newFilter); } }
if (!commandRouter.findDestination(canary).isPresent()) { logger.error("Trading-Engine isn't running. Unable to initialize data"); return false;