Beispiel #1
0
 /**
  * Is notified of multicast messages. These messages are sent to the group, if their direction is
  * {@link org.bundlebee.registry.net.MultiCastMessage.Direction#OUT}.
  *
  * @param multiCastMessage multiCastMessage
  */
 public void processMessage(final MultiCastMessage multiCastMessage) {
   if (Direction.OUT.equals(multiCastMessage.getDirection())) {
     this.sendToGroup(multiCastMessage);
   } else {
     if (LOG.isDebugEnabled()) {
       LOG.debug(
           "Not sending message, because its direction is not "
               + Direction.OUT
               + ", but "
               + multiCastMessage.getDirection());
     }
   }
 }
Beispiel #2
0
 /**
  * Sends a private message.
  *
  * @param message message
  * @param address address to send the message to
  * @param port port to send the message to
  * @throws IOException if sending fails
  */
 private void sendPrivateMessage(
     final MultiCastMessage message, final InetAddress address, final int port)
     throws IOException {
   privateSocket.send(toDatagramPacket(message.toString(), address, port));
   if (LOG.isDebugEnabled()) {
     LOG.debug("Sent " + message + " to " + address + ":" + port);
   }
 }
Beispiel #3
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);
   }
 }
Beispiel #4
0
 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);
     }
   }
 }
Beispiel #5
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);
   }
 }