void (DaemonClientFactory daemonClientFactory, List<byte[]> tokens) { ServiceRegistry daemonServices = getDaemonServices(daemonClientFactory); DaemonRegistry daemonRegistry = daemonServices.get(DaemonRegistry.class); DaemonConnector daemonConnector = daemonServices.get(DaemonConnector.class); IdGenerator<?> idGenerator = daemonServices.get(IdGenerator.class); List<DaemonInfo> list = new ArrayList<>(daemonRegistry.getAll()); for (byte[] token : tokens) { for (Iterator<DaemonInfo> iterator = list.iterator(); iterator.hasNext(); ) { DaemonInfo info = iterator.next(); if (Arrays.equals(info.getToken(), token)) { iterator.remove(); DaemonClientConnection connection = daemonConnector.maybeConnect(info); if (connection != null) { try { Command stopCommand = createCommand(getCommandClass(), idGenerator.generateId(), token); connection.dispatch(stopCommand); } finally { connection.stop(); } } break; } } } }