1 28 29 package com.caucho.jms.memory; 30 31 import com.caucho.jms.message.MessageImpl; 32 import com.caucho.jms.session.MessageConsumerImpl; 33 import com.caucho.jms.session.SessionImpl; 34 import com.caucho.log.Log; 35 import com.caucho.util.L10N; 36 37 import javax.jms.JMSException ; 38 import javax.jms.Topic ; 39 import javax.jms.TopicSubscriber ; 40 import java.util.logging.Logger ; 41 42 45 public class MemoryTopicConsumer extends MessageConsumerImpl 46 implements TopicSubscriber { 47 static final Logger log = Log.open(MemoryTopicConsumer.class); 48 static final L10N L = new L10N(MemoryTopicConsumer.class); 49 50 private MemoryTopic _topic; 51 private MemoryQueue _queue; 52 53 private int _consumerId; 54 55 private boolean _autoAck; 56 57 public MemoryTopicConsumer(SessionImpl session, String messageSelector, 58 MemoryTopic topic) 59 throws JMSException 60 { 61 this(session, messageSelector, topic, null); 62 } 63 64 public MemoryTopicConsumer(SessionImpl session, String messageSelector, 65 MemoryTopic topic, String name) 66 throws JMSException 67 { 68 super(session, messageSelector, topic, false); 69 70 _topic = topic; 71 72 if (session.getAcknowledgeMode() == session.AUTO_ACKNOWLEDGE || 73 session.getAcknowledgeMode() == session.DUPS_OK_ACKNOWLEDGE) 74 _autoAck = true; 75 76 if (name != null) 77 _queue = topic.createDurableSubscriber(name); 78 else 79 _queue = topic.createSubscriberQueue(); 80 81 _queue.addListener(this); 82 } 83 84 87 public Topic getTopic() 88 { 89 return _topic; 90 } 91 92 95 protected MessageImpl receiveImpl() 96 throws JMSException 97 { 98 101 return _queue.receive(_selector, 1, true); 102 } 103 104 107 public void acknowledge() 108 throws JMSException 109 { 110 if (_autoAck) 111 return; 112 } 113 114 117 public void rollback() 118 throws JMSException 119 { 120 if (_autoAck) 121 return; 122 } 123 124 127 public void close() 128 { 129 _topic.removeSubscriber(_queue); 130 } 131 132 135 public String toString() 136 { 137 return "MemoryTopicConsumer[" + _topic + "," + _consumerId + "]"; 138 } 139 } 140 141 | Popular Tags |