private void notifyMyPeers( List<PeerAddress> ownPeers, BaseNotificationMessageFactory messageFactory, PublicKey ownPublicKey) { ownPeers.remove(networkManager.getConnection().getPeer().getPeerAddress()); logger.debug("Notifying " + ownPeers.size() + " other peers of me (without myself)"); for (PeerAddress peerAddress : ownPeers) { if (peerAddress.equals(networkManager.getConnection().getPeer().getPeerAddress())) { // don't send myself logger.trace("Skipping to send a message to myself"); continue; } try { BaseDirectMessage message = messageFactory.createPrivateNotificationMessage(peerAddress); if (message == null) { logger.info("Not notifying any of the own peers because the message to be sent is null"); } else { sendDirect(message, ownPublicKey); } } catch (SendFailedException e) { // add to the unreachable list, such that the next process can cleanup those // locations context.addUnreachableLocation(peerAddress); // continue anyhow } } }
@Override protected void doExecute() throws InvalidProcessStateException { BaseNotificationMessageFactory messageFactory = context.consumeMessageFactory(); Map<String, PublicKey> userPublicKeys = context.getUserPublicKeys(); Map<String, List<PeerAddress>> locations = context.getAllLocations(); for (String user : context.consumeUsersToNotify()) { PublicKey publicKey = userPublicKeys.get(user); List<PeerAddress> peerAddresses = locations.get(user); if (user.equalsIgnoreCase(networkManager.getUserId())) { // send own peers a 'normal' notification message notifyMyPeers(peerAddresses, messageFactory, publicKey); } else { // send to the initial node of another client notifyInitialPeer(peerAddresses, messageFactory, user, publicKey); } } }