1 package net.walend.somnifugi; 2 3 import java.util.Enumeration ; 4 5 import javax.naming.Referenceable ; 6 import javax.naming.Reference ; 7 import javax.naming.NamingException ; 8 import javax.naming.Context ; 9 10 import javax.jms.Queue ; 11 import javax.jms.Message ; 12 import javax.jms.JMSException ; 13 14 import net.walend.somnifugi.channel.Channel; 15 import net.walend.somnifugi.channel.Puttable; 16 import net.walend.somnifugi.channel.Takable; 17 import net.walend.somnifugi.channel.ChannelFactory; 18 19 24 25 public class SomniQueue 26 extends SomniDestination 27 implements Queue , Referenceable 28 { 29 private static final long serialVersionUID = 0L; 30 31 private final Channel<Message > channel; 32 33 protected SomniQueue(String name,ChannelFactory<Message > factory,Context context) 34 throws SomniNamingException 35 { 36 super(name,factory,context); 37 38 channel = factory.createChannel(name,context); 39 } 40 41 53 public String getQueueName() 54 throws JMSException 55 { 56 return getName(); 57 } 58 59 63 public String toString() 64 { 65 return getName(); 66 } 67 68 protected Puttable<Message > getPuttable() 69 { 70 return channel.getPuttable(); 71 } 72 73 protected Takable<Message > getTakable() 74 { 75 return channel.getTakable(); 76 } 77 78 Takable<Message > getTakable(SomniMessageSelector messageSelector) 79 throws SomniMessageSelectorException 80 { 81 if(!channel.supportsMessageSelectors()) 82 { 83 throw new SomniMessageSelectorException(channel.getClass().getName()+" used by "+getName()+"does not support message selectors"); 84 } 85 86 return channel.getTakable(messageSelector); 87 } 88 89 Enumeration snapShot() 90 { 91 return getTakable().snapShot(); 92 } 93 94 Enumeration snapShot(SomniMessageSelector messageSelector) 95 throws SomniMessageSelectorException 96 { 97 return getTakable().snapShot(messageSelector); 98 } 99 100 public Reference getReference() 102 throws NamingException 103 { 104 return new Reference (this.getClass().getName(),SomniQueueFactory.class.getName(),null); 105 } 106 } 107 108 128 | Popular Tags |