/** * Processes a privately received message. * * @param message message * @throws IOException if a response request fails */ private void processPrivateMessage(final String message) throws IOException { try { final MultiCastMessage multiCastMessage = new MultiCastMessage(message); if (multiCastMessage.getType() == MultiCastMessage.Type.LS) { final InetAddress address = multiCastMessage.getSenderAddress(); final int port = multiCastMessage.getSenderPort(); // sending everything to remote private port for (final MultiCastMessage mcm : ((RegistryImpl) RegistryImpl.getInstance()).getList()) { sendPrivateMessage(mcm, address, port); } } else if (multiCastMessage.getType() == MultiCastMessage.Type.HI) { final InetAddress address = multiCastMessage.getSenderAddress(); final int port = multiCastMessage.getSenderPort(); if (multiCastMessage.getNodeId() == RegistryImpl.getInstance().getNodeId()) { if (LOG.isDebugEnabled()) { LOG.debug("HI message is from this node, doing nothing."); } } else { if (lsRequestSent < maxLsRequests) { if (LOG.isDebugEnabled()) { LOG.debug("Sending ls request to " + address); } sendPrivateMessage( new MultiCastMessage(nodeId, MultiCastMessage.Type.LS, getSender()), address, port); lsRequestSent++; } else { if (LOG.isDebugEnabled()) { LOG.debug("Max ls requests already sent, doing nothing."); } } } } else { if (multiCastMessage.isValid()) { multiCastMessage.setDirection(Direction.IN); fireMessage(multiCastMessage); } } } catch (RuntimeException e) { LOG.error(BUNDLE_MARKER, "Failed to process private message: " + e.toString(), e); } }
public void sendToGroup(final MultiCastMessage multiCastMessage) { if (multiCastMessage.isValid()) { // reset ls request count, when we send HI if (multiCastMessage.getType() == MultiCastMessage.Type.HI) { lsRequestSent = 0; // make sure we have a sender set // even if the directory does not know, who we are if (multiCastMessage.getValues().getProperty(MultiCastMessage.PROPERTYKEY_SENDER) == null) { multiCastMessage .getValues() .setProperty(MultiCastMessage.PROPERTYKEY_SENDER, getSender()); } } sendToGroup(multiCastMessage.toString()); } else { if (LOG.isDebugEnabled()) { LOG.debug( BUNDLE_MARKER, "not sending message, because it is not valid: " + multiCastMessage); } } }
/** * Processes a message. * * @param message message * @throws IOException if something goes wrong */ private void processGroupMessage(final String message) throws IOException { try { final MultiCastMessage multiCastMessage = new MultiCastMessage(message); if (multiCastMessage.getType() == MultiCastMessage.Type.HI && multiCastMessage.getNodeId() != RegistryImpl.getInstance().getNodeId()) { final InetAddress address = multiCastMessage.getSenderAddress(); final int port = multiCastMessage.getSenderPort(); // we don't use datagramPacket.getAddress(), because of // http://bugs.sun.com/view_bug.do?bug_id=4717228 // -hendrik sendPrivateMessage( new MultiCastMessage(nodeId, MultiCastMessage.Type.HI, getSender()), address, port); } if (LOG.isInfoEnabled()) { LOG.info(BUNDLE_MARKER, "(NODE) processing node message: " + message); } if (multiCastMessage.isValid()) { multiCastMessage.setDirection(Direction.IN); fireMessage(multiCastMessage); } } catch (RuntimeException e) { LOG.error(BUNDLE_MARKER, "Failed to process group message: " + e.toString(), e); } }