001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. 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 package org.apache.activemq.pool;
018
019 import javax.jms.Destination;
020 import javax.jms.JMSException;
021 import javax.jms.Message;
022 import javax.jms.MessageProducer;
023
024 import org.apache.activemq.ActiveMQMessageProducer;
025
026 /**
027 * A pooled {@link MessageProducer}
028 *
029 * @version $Revision: 1.1 $
030 */
031 public class PooledProducer implements MessageProducer {
032 private ActiveMQMessageProducer messageProducer;
033 private Destination destination;
034 private int deliveryMode;
035 private boolean disableMessageID;
036 private boolean disableMessageTimestamp;
037 private int priority;
038 private long timeToLive;
039
040 public PooledProducer(ActiveMQMessageProducer messageProducer, Destination destination) throws JMSException {
041 this.messageProducer = messageProducer;
042 this.destination = destination;
043
044 this.deliveryMode = messageProducer.getDeliveryMode();
045 this.disableMessageID = messageProducer.getDisableMessageID();
046 this.disableMessageTimestamp = messageProducer.getDisableMessageTimestamp();
047 this.priority = messageProducer.getPriority();
048 this.timeToLive = messageProducer.getTimeToLive();
049 }
050
051 public void close() throws JMSException {
052 }
053
054 public void send(Destination destination, Message message) throws JMSException {
055 send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive());
056 }
057
058 public void send(Message message) throws JMSException {
059 send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive());
060 }
061
062 public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
063 send(destination, message, deliveryMode, priority, timeToLive);
064 }
065
066 public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
067 if (destination == null) {
068 destination = this.destination;
069 }
070 ActiveMQMessageProducer messageProducer = getMessageProducer();
071
072 // just in case let only one thread send at once
073 synchronized (messageProducer) {
074 messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
075 }
076 }
077
078 public Destination getDestination() {
079 return destination;
080 }
081
082 public int getDeliveryMode() {
083 return deliveryMode;
084 }
085
086 public void setDeliveryMode(int deliveryMode) {
087 this.deliveryMode = deliveryMode;
088 }
089
090 public boolean getDisableMessageID() {
091 return disableMessageID;
092 }
093
094 public void setDisableMessageID(boolean disableMessageID) {
095 this.disableMessageID = disableMessageID;
096 }
097
098 public boolean getDisableMessageTimestamp() {
099 return disableMessageTimestamp;
100 }
101
102 public void setDisableMessageTimestamp(boolean disableMessageTimestamp) {
103 this.disableMessageTimestamp = disableMessageTimestamp;
104 }
105
106 public int getPriority() {
107 return priority;
108 }
109
110 public void setPriority(int priority) {
111 this.priority = priority;
112 }
113
114 public long getTimeToLive() {
115 return timeToLive;
116 }
117
118 public void setTimeToLive(long timeToLive) {
119 this.timeToLive = timeToLive;
120 }
121
122 // Implementation methods
123 // -------------------------------------------------------------------------
124 protected ActiveMQMessageProducer getMessageProducer() {
125 return messageProducer;
126 }
127
128 public String toString() {
129 return "PooledProducer { " + messageProducer + " }";
130 }
131
132 }