Exemplo n.º 1
0
 /**
  * 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);
   }
 }
Exemplo n.º 2
0
 /**
  * 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);
   }
 }