1 18 package org.apache.activemq.pool; 19 20 import org.apache.activemq.ActiveMQMessageProducer; 21 22 import javax.jms.Destination ; 23 import javax.jms.JMSException ; 24 import javax.jms.Message ; 25 import javax.jms.MessageProducer ; 26 27 32 public class PooledProducer implements MessageProducer { 33 private ActiveMQMessageProducer messageProducer; 34 private Destination destination; 35 private int deliveryMode; 36 private boolean disableMessageID; 37 private boolean disableMessageTimestamp; 38 private int priority; 39 private long timeToLive; 40 41 public PooledProducer(ActiveMQMessageProducer messageProducer, Destination destination) throws JMSException { 42 this.messageProducer = messageProducer; 43 this.destination = destination; 44 45 this.deliveryMode = messageProducer.getDeliveryMode(); 46 this.disableMessageID = messageProducer.getDisableMessageID(); 47 this.disableMessageTimestamp = messageProducer.getDisableMessageTimestamp(); 48 this.priority = messageProducer.getPriority(); 49 this.timeToLive = messageProducer.getTimeToLive(); 50 } 51 52 public void close() throws JMSException { 53 } 54 55 public void send(Destination destination, Message message) throws JMSException { 56 send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive()); 57 } 58 59 public void send(Message message) throws JMSException { 60 send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive()); 61 } 62 63 public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { 64 send(destination, message, deliveryMode, priority, timeToLive); 65 } 66 67 public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { 68 if (destination == null) { 69 destination = this.destination; 70 } 71 ActiveMQMessageProducer messageProducer = getMessageProducer(); 72 73 synchronized (messageProducer) { 75 messageProducer.send(destination, message, deliveryMode, priority, timeToLive); 76 } 77 } 78 79 public Destination getDestination() { 80 return destination; 81 } 82 83 public int getDeliveryMode() { 84 return deliveryMode; 85 } 86 87 public void setDeliveryMode(int deliveryMode) { 88 this.deliveryMode = deliveryMode; 89 } 90 91 public boolean getDisableMessageID() { 92 return disableMessageID; 93 } 94 95 public void setDisableMessageID(boolean disableMessageID) { 96 this.disableMessageID = disableMessageID; 97 } 98 99 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 protected ActiveMQMessageProducer getMessageProducer() { 126 return messageProducer; 127 } 128 129 public String toString() { 130 return "PooledProducer { "+messageProducer+" }"; 131 } 132 133 } 134 | Popular Tags |