001 /**
002 *
003 * Copyright 2005 Protique Ltd
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.activemq.pool;
019
020 import javax.jms.Destination;
021 import javax.jms.JMSException;
022 import javax.jms.Message;
023 import javax.jms.MessageProducer;
024
025 import org.activemq.ActiveMQMessageProducer;
026
027 /**
028 * A pooled {@link MessageProducer}
029 *
030 * @version $Revision: 1.1 $
031 */
032 public class PooledProducer implements MessageProducer {
033 private ActiveMQMessageProducer messageProducer;
034 private Destination destination;
035 private int deliveryMode;
036 private boolean disableMessageID;
037 private boolean disableMessageTimestamp;
038 private int priority;
039 private long timeToLive;
040
041 public PooledProducer(ActiveMQMessageProducer messageProducer, Destination destination) throws JMSException {
042 this.messageProducer = messageProducer;
043 this.destination = destination;
044
045 this.deliveryMode = messageProducer.getDeliveryMode();
046 this.disableMessageID = messageProducer.getDisableMessageID();
047 this.disableMessageTimestamp = messageProducer.getDisableMessageTimestamp();
048 this.priority = messageProducer.getPriority();
049 this.timeToLive = messageProducer.getTimeToLive();
050 }
051
052 public void close() throws JMSException {
053 }
054
055 public void send(Destination destination, Message message) throws JMSException {
056 send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive());
057 }
058
059 public void send(Message message) throws JMSException {
060 send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive());
061 }
062
063 public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
064 send(destination, message, deliveryMode, priority, timeToLive);
065 }
066
067 public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
068 if (destination == null) {
069 destination = this.destination;
070 }
071 ActiveMQMessageProducer messageProducer = getMessageProducer();
072
073 // just in case let only one thread send at once
074 synchronized (messageProducer) {
075 messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
076 }
077 }
078
079 public Destination getDestination() {
080 return destination;
081 }
082
083 public int getDeliveryMode() {
084 return deliveryMode;
085 }
086
087 public void setDeliveryMode(int deliveryMode) {
088 this.deliveryMode = deliveryMode;
089 }
090
091 public boolean getDisableMessageID() {
092 return disableMessageID;
093 }
094
095 public void setDisableMessageID(boolean disableMessageID) {
096 this.disableMessageID = disableMessageID;
097 }
098
099 public boolean getDisableMessageTimestamp() {
100 return disableMessageTimestamp;
101 }
102
103 public void setDisableMessageTimestamp(boolean disableMessageTimestamp) {
104 this.disableMessageTimestamp = disableMessageTimestamp;
105 }
106
107 public int getPriority() {
108 return priority;
109 }
110
111 public void setPriority(int priority) {
112 this.priority = priority;
113 }
114
115 public long getTimeToLive() {
116 return timeToLive;
117 }
118
119 public void setTimeToLive(long timeToLive) {
120 this.timeToLive = timeToLive;
121 }
122
123 // Implementation methods
124 //-------------------------------------------------------------------------
125 protected ActiveMQMessageProducer getMessageProducer() {
126 return messageProducer;
127 }
128 }