| Home >> All >> com >> ubermq >> chord >> [ jms Javadoc ] |
Source code: com/ubermq/chord/jms/ChordStoreMessage.java
1 package com.ubermq.chord.jms; 2 3 import com.ubermq.chord.*; 4 import java.util.*; 5 import javax.jms.*; 6 7 /** 8 * A chord store command. 9 */ 10 public final class ChordStoreMessage 11 extends ChordMessage 12 { 13 private Object key, value; 14 15 /** 16 * Constructs a chord store message from an incoming 17 * JMS message. <P> 18 * 19 * @throws IllegalArgumentException if the message is invalid. 20 */ 21 ChordStoreMessage(Message m) 22 { 23 super(m); 24 25 try 26 { 27 List l = (List) ((ObjectMessage)m).getObject(); 28 this.key = l.get(0); 29 this.value = l.get(1); 30 } 31 catch (JMSException e) { 32 throw new IllegalArgumentException("Invalid chord store message."); 33 } 34 } 35 36 /** 37 * Constructs an outgoing chord store command.<P> 38 * 39 * @param session a JMS session 40 * @param key the key to store the value under 41 * @param value the value to store 42 */ 43 ChordStoreMessage(Session session, 44 Object key, 45 Object value) 46 throws JMSException 47 { 48 super(session.createObjectMessage(), 49 CHORD_STORE); 50 51 this.key = key; 52 this.value = value; 53 54 List pair = new ArrayList(2); 55 pair.add(key); 56 pair.add(value); 57 58 ObjectMessage m = (ObjectMessage)getJMSMessage(); 59 m.setObject((java.io.Serializable)pair); 60 } 61 62 /** 63 * Returns the key to store the value under. 64 * @return a key 65 */ 66 public Object getKey() 67 { 68 return key; 69 } 70 71 /** 72 * Returns the value that should be stored. 73 */ 74 public Object getValue() 75 { 76 return value; 77 } 78 79 public void execute(TopicSession session, 80 TopicPublisher pub, 81 ChordNodeProvider p) 82 { 83 p.store(key, value); 84 } 85 } 86