diff options
Diffstat (limited to 'java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java')
-rw-r--r-- | java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java | 264 |
1 files changed, 150 insertions, 114 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java b/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java index 02da284b83..803f2e03a4 100644 --- a/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java +++ b/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java @@ -1,138 +1,174 @@ package org.apache.qpid.client; -import javax.jms.Destination; +import javax.jms.*; import javax.jms.IllegalStateException; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageProducer; -import javax.jms.Topic; -import javax.jms.TopicPublisher; -public class TopicPublisherAdapter implements TopicPublisher { +public class TopicPublisherAdapter implements TopicPublisher +{ + + private BasicMessageProducer _delegate; + private Topic _topic; + + public TopicPublisherAdapter(BasicMessageProducer msgProducer, Topic topic) + { + _delegate = msgProducer; + _topic = topic; + } + + public Topic getTopic() throws JMSException + { + checkPreConditions(); + return _topic; + } + + public void publish(Message msg) throws JMSException + { + checkPreConditions(); + checkTopic(_topic); + _delegate.send(msg); + } + + public void publish(Topic topic, Message msg) throws JMSException + { + checkPreConditions(); + checkTopic(topic); + _delegate.send(topic, msg); + } + + public void publish(Message msg, int deliveryMode, int priority, long timeToLive) + throws JMSException + { + checkPreConditions(); + checkTopic(_topic); + _delegate.send(msg, deliveryMode, priority, timeToLive); + } - private MessageProducer delegate; - private Topic topic; - private boolean closed = false; - - public TopicPublisherAdapter(MessageProducer msgProducer, Topic topic){ - delegate = msgProducer; - this.topic = topic; - } - - public Topic getTopic() throws JMSException { - checkPreConditions(); - return topic; - } - - public void publish(Message msg) throws JMSException { - checkPreConditions(); - delegate.send(msg); - } - - public void publish(Topic topic, Message msg) throws JMSException { - checkPreConditions(); - delegate.send(topic,msg); - } - - public void publish(Message msg, int deliveryMode, int priority, long timeToLive) - throws JMSException { + public int getDeliveryMode() throws JMSException { checkPreConditions(); - delegate.send(msg, deliveryMode,priority,timeToLive); + return _delegate.getDeliveryMode(); } public void publish(Topic topic, Message msg, int deliveryMode, int priority, long timeToLive) - throws JMSException { - checkPreConditions(); - delegate.send(topic,msg, deliveryMode,priority,timeToLive); - } - - public void close() throws JMSException { - delegate.close(); - closed = true; - } - - public int getDeliveryMode() throws JMSException { - return delegate.getDeliveryMode(); - } - - public Destination getDestination() throws JMSException { - return delegate.getDestination(); - } + throws JMSException + { + checkPreConditions(); + checkTopic(topic); + _delegate.send(topic, msg, deliveryMode, priority, timeToLive); + } + + public void close() throws JMSException + { + _delegate.close(); + } public boolean getDisableMessageID() throws JMSException { - return delegate.getDisableMessageID(); - } - - public boolean getDisableMessageTimestamp() throws JMSException { - return delegate.getDisableMessageTimestamp(); - } - - public int getPriority() throws JMSException { - return delegate.getPriority(); - } - - public long getTimeToLive() throws JMSException { - return delegate.getTimeToLive(); - } - - public void send(Message msg) throws JMSException { - checkPreConditions(); - delegate.send(msg); - } - - public void send(Destination dest, Message msg) throws JMSException { - checkPreConditions(); - delegate.send(dest,msg); - } - - public void send(Message msg, int deliveryMode, int priority, long timeToLive) - throws JMSException { checkPreConditions(); - delegate.send(msg, deliveryMode,priority,timeToLive); + return _delegate.getDisableMessageID(); } - public void send(Destination dest, Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException { + public boolean getDisableMessageTimestamp() throws JMSException { checkPreConditions(); - delegate.send(dest,msg, deliveryMode,priority,timeToLive); + return _delegate.getDisableMessageTimestamp(); } - public void setDeliveryMode(int deliveryMode) throws JMSException { - checkPreConditions(); - delegate.setDeliveryMode(deliveryMode); - } - - public void setDisableMessageID(boolean disableMessageID) throws JMSException { - checkPreConditions(); - delegate.setDisableMessageID(disableMessageID); - } - - public void setDisableMessageTimestamp(boolean disableMessageTimestamp) throws JMSException { + public Destination getDestination() throws JMSException + { checkPreConditions(); - delegate.setDisableMessageTimestamp(disableMessageTimestamp); - } + return _delegate.getDestination(); + } - public void setPriority(int priority) throws JMSException { + public int getPriority() throws JMSException { checkPreConditions(); - delegate.setPriority(priority); + return _delegate.getPriority(); } - public void setTimeToLive(long timeToLive) throws JMSException { + public long getTimeToLive() throws JMSException { checkPreConditions(); - delegate.setTimeToLive(timeToLive); - } - - private void checkPreConditions() throws IllegalStateException, IllegalStateException { - if (closed){ - throw new javax.jms.IllegalStateException("Publisher is closed"); - } - - if(topic == null){ - throw new UnsupportedOperationException("Topic is null"); - } - - AMQSession session = ((BasicMessageProducer)delegate).getSession(); - if(session == null || session.isClosed()){ - throw new javax.jms.IllegalStateException("Invalid Session"); - } - } + return _delegate.getTimeToLive(); + } + + public void send(Message msg) throws JMSException + { + checkPreConditions(); + checkTopic(_topic); + _delegate.send(msg); + } + + public void send(Destination dest, Message msg) throws JMSException + { + checkPreConditions(); + checkTopic(_topic); + _delegate.send(dest, msg); + } + + public void send(Message msg, int deliveryMode, int priority, long timeToLive) + throws JMSException + { + checkPreConditions(); + checkTopic(_topic); + _delegate.send(msg, deliveryMode, priority, timeToLive); + } + + public void send(Destination dest, Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException + { + checkPreConditions(); + checkTopic(dest); + _delegate.send(dest, msg, deliveryMode, priority, timeToLive); + } + + public void setDeliveryMode(int deliveryMode) throws JMSException + { + checkPreConditions(); + _delegate.setDeliveryMode(deliveryMode); + } + + public void setDisableMessageID(boolean disableMessageID) throws JMSException + { + checkPreConditions(); + _delegate.setDisableMessageID(disableMessageID); + } + + public void setDisableMessageTimestamp(boolean disableMessageTimestamp) throws JMSException + { + checkPreConditions(); + _delegate.setDisableMessageTimestamp(disableMessageTimestamp); + } + + public void setPriority(int priority) throws JMSException + { + checkPreConditions(); + _delegate.setPriority(priority); + } + + public void setTimeToLive(long timeToLive) throws JMSException + { + checkPreConditions(); + _delegate.setTimeToLive(timeToLive); + } + + private void checkPreConditions() throws IllegalStateException + { + if (_delegate.isClosed()) + { + throw new javax.jms.IllegalStateException("Publisher is _closed"); + } + + AMQSession session = _delegate.getSession(); + if (session == null || session.isClosed()) + { + throw new javax.jms.IllegalStateException("Invalid Session"); + } + } + + private void checkTopic(Destination topic) throws InvalidDestinationException + { + if (topic == null) + { + throw new UnsupportedOperationException("Topic is null"); + } + if (!(topic instanceof Topic)) + { + throw new InvalidDestinationException("Destination " + topic + " is not a topic"); + } + } } |