Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/ubermq/chord/jms/ChordNotifyMessage.java


1   package com.ubermq.chord.jms;
2   
3   import com.ubermq.chord.*;
4   import javax.jms.*;
5   
6   /**
7    * A chord notify command.
8    */
9   public final class ChordNotifyMessage
10      extends ChordMessage
11  {
12      private ChordNode node;
13      private boolean goingAway;
14  
15      /**
16       * A boolean property that signifies whether the notify message
17       * indicates a node joining, or leaving, the infrastructure.
18       */
19      private static final String CHORD_NOTIFY_GOING_AWAY_PROPERTY = "com.ubermq.chord.notify.going-away";
20  
21      ChordNotifyMessage(Session session,
22                         boolean goingAway,
23                         ChordNode node)
24          throws JMSException
25      {
26          super(session.createObjectMessage((java.io.Serializable)node),
27                ChordMessage.CHORD_NOTIFY);
28  
29          ObjectMessage m = (ObjectMessage)getJMSMessage();
30          m.setBooleanProperty(CHORD_NOTIFY_GOING_AWAY_PROPERTY, goingAway);
31      }
32  
33      /**
34       * Constructs a chord node notification message.
35       * @throws IllegalArgumentException if the message is invalid.
36       */
37      ChordNotifyMessage(Message m)
38      {
39          super(m);
40  
41          try
42          {
43              this.node = (ChordNode)((ObjectMessage)m).getObject();
44              this.goingAway = m.getBooleanProperty(CHORD_NOTIFY_GOING_AWAY_PROPERTY);
45          }
46          catch (JMSException e) {
47              throw new IllegalArgumentException("Invalid chord notify message.");
48          }
49      }
50  
51      /**
52       * Returns the node that is doing the notification.
53       * @return a node
54       */
55      public ChordNode getNode()
56      {
57          return node;
58      }
59  
60      public void execute(TopicSession session,
61                          TopicPublisher pub,
62                          ChordNodeProvider p)
63          throws JMSException
64      {
65          if (goingAway)
66              p.notifyGoingAway(node);
67          else
68              p.notify(node);
69      }
70  }
71