summaryrefslogtreecommitdiff
path: root/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java
blob: 02da284b83cb69b4763dbf50f29fa69af92256d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package org.apache.qpid.client;

import javax.jms.Destination;
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 {

	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 {
		checkPreConditions();
		delegate.send(msg, deliveryMode,priority,timeToLive);
	}

	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();
	}

	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);
	}

	public void send(Destination dest, Message msg, int deliveryMode, int priority, long timeToLive) throws JMSException {
		checkPreConditions();
		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, 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");
		}
	}
}