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

Quick Search    Search Deep

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


1   package com.ubermq.chord.jms;
2   
3   import javax.jms.*;
4   import java.util.*;
5   
6   /**
7    * A chord store command.
8    */
9   public final class ChordValueMessage
10      extends ChordMessage
11  {
12      private Object key, value;
13      private long queryId;
14  
15      /**
16       * Constructs a chord value reply message.
17       * @throws IllegalArgumentException if the message is invalid.
18       */
19      ChordValueMessage(Message m)
20      {
21          super(m);
22  
23          try
24          {
25              List l = (List) ((ObjectMessage)m).getObject();
26              this.key = l.get(0);
27              if (l.size() > 1)
28                  this.value = l.get(1);
29              else this.value = null;
30  
31              this.queryId = m.getLongProperty(ChordQueryMessage.CHORD_QUERY_ID_PROPERTY);
32          }
33          catch (Exception e) {
34              e.printStackTrace();
35              throw new IllegalArgumentException("Invalid chord value reply message.");
36          }
37      }
38  
39      /**
40       * Constructs an outgoing value command.
41       *
42       * @param session a session, used for message creation
43       * @param replyTopic the topic that the value message will be sent to
44       * @param key the key to look up
45       */
46      ChordValueMessage(Session session,
47                        long queryId,
48                        Object key,
49                        Object value)
50          throws JMSException
51      {
52          super(session.createObjectMessage(),
53                CHORD_VALUE);
54  
55          List pair = new ArrayList(2);
56          pair.add(key);
57          pair.add(value);
58  
59          ObjectMessage m = (ObjectMessage)getJMSMessage();
60          m.setObject((java.io.Serializable)pair);
61          m.setLongProperty(ChordQueryMessage.CHORD_QUERY_ID_PROPERTY, queryId);
62      }
63  
64      /**
65       * Returns the key that was queried.
66       * @return a key
67       */
68      public Object getKey()
69      {
70          return key;
71      }
72  
73      /**
74       * Returns the query identifier that this value
75       * is in response to.
76       * @return the query id
77       */
78      public long getQueryId()
79      {
80          return queryId;
81      }
82  
83      /**
84       * Returns the value that was found associated with the key,
85       * or <code>null</code> if no value was found.
86       */
87      public Object getValue()
88      {
89          return value;
90      }
91  }
92