1 28 29 package com.caucho.jms.jdbc; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.jms.JMSExceptionWrapper; 33 import com.caucho.jms.session.MessageConsumerImpl; 34 import com.caucho.jms.session.SessionImpl; 35 import com.caucho.log.Log; 36 import com.caucho.util.L10N; 37 38 import javax.annotation.PostConstruct; 39 import javax.jms.JMSException ; 40 import javax.jms.Message ; 41 import javax.jms.Topic ; 42 import javax.jms.TopicSubscriber ; 43 import java.sql.SQLException ; 44 import java.util.logging.Logger ; 45 46 49 public class JdbcTopic extends JdbcDestination implements Topic { 50 static final Logger log = Log.open(JdbcTopic.class); 51 static final L10N L = new L10N(JdbcTopic.class); 52 53 private int _id; 54 55 public JdbcTopic() 56 { 57 } 58 59 62 public String getTopicName() 63 { 64 return getName(); 65 } 66 67 70 public void setTopicName(String name) 71 { 72 setName(name); 73 } 74 75 78 public boolean isTopic() 79 { 80 return true; 81 } 82 83 86 public int getId() 87 { 88 return _id; 89 } 90 91 94 @PostConstruct 95 public void init() 96 throws ConfigException, SQLException 97 { 98 if (_jdbcManager.getDataSource() == null) 99 throw new ConfigException(L.l("JdbcTopic requires a <data-source> element.")); 100 101 if (getName() == null) 102 throw new ConfigException(L.l("JdbcTopic requires a <topic-name> element.")); 103 104 _jdbcManager.init(); 105 106 _id = createDestination(getName(), true); 107 } 108 109 112 public MessageConsumerImpl createConsumer(SessionImpl session, 113 String selector, 114 boolean noLocal) 115 throws JMSException 116 { 117 return new JdbcTopicConsumer(session, selector, 118 _jdbcManager, this, noLocal); 119 } 120 121 124 public TopicSubscriber createDurableSubscriber(SessionImpl session, 125 String selector, 126 boolean noLocal, 127 String name) 128 throws JMSException 129 { 130 return new JdbcTopicConsumer(session, selector, 131 _jdbcManager, this, noLocal, name); 132 } 133 134 137 public void send(Message message) 138 throws JMSException 139 { 140 long expireTime = message.getJMSExpiration(); 141 if (expireTime <= 0) 142 expireTime = Long.MAX_VALUE / 2; 143 144 purgeExpiredMessages(); 145 146 try { 147 _jdbcManager.getJdbcMessage().send(message, _id, expireTime); 148 } catch (Exception e) { 149 throw new JMSExceptionWrapper(e); 150 } 151 152 messageAvailable(); 153 } 154 155 158 public String toString() 159 { 160 return "JdbcTopic[" + getName() + "]"; 161 } 162 } 163 164 | Popular Tags |