Class ActiveMQMessageProducerSupport
- java.lang.Object
-
- org.apache.activemq.ActiveMQMessageProducerSupport
-
- All Implemented Interfaces:
AutoCloseable,javax.jms.MessageProducer,Closeable
- Direct Known Subclasses:
ActiveMQMessageProducer
public abstract class ActiveMQMessageProducerSupport extends Object implements javax.jms.MessageProducer, Closeable
A useful base class for implementing aMessageProducer
-
-
Field Summary
Fields Modifier and Type Field Description protected intdefaultDeliveryModeprotected intdefaultPriorityprotected longdefaultTimeToLiveprotected booleandisableMessageIDprotected booleandisableMessageTimestampstatic Set<String>JMS_PROPERTY_NAMES_DISALLOWEDprotected intsendTimeoutprotected ActiveMQSessionsession
-
Constructor Summary
Constructors Constructor Description ActiveMQMessageProducerSupport(ActiveMQSession session)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidcheckClosed()longgetDeliveryDelay()Gets the delivery delay value for thisMessageProducer.intgetDeliveryMode()Gets the producer's default delivery mode.booleangetDisableMessageID()Gets an indication of whether message IDs are disabled.booleangetDisableMessageTimestamp()Gets an indication of whether message timestamps are disabled.intgetPriority()Gets the producer's default priority.intgetSendTimeout()longgetTimeToLive()Gets the default length of time in milliseconds from its dispatch time that a produced message should be retained by the message system.voidsend(javax.jms.Destination destination, javax.jms.Message message)Sends a message to a destination for an unidentified message producer.voidsend(javax.jms.Message message)Sends a message using theMessageProducer's default delivery mode, priority, and time to live.voidsend(javax.jms.Message message, int deliveryMode, int priority, long timeToLive)Sends a message to the destination, specifying delivery mode, priority, and time to live.voidsetDeliveryDelay(long deliveryDelay)Gets the delivery delay associated with thisMessageProducer.voidsetDeliveryMode(int newDeliveryMode)Sets the producer's default delivery mode.voidsetDisableMessageID(boolean disableMessageID)Sets whether message IDs are disabled.voidsetDisableMessageTimestamp(boolean disableMessageTimestamp)Sets whether message timestamps are disabled.voidsetPriority(int newDefaultPriority)Sets the producer's default priority.voidsetSendTimeout(int sendTimeout)voidsetTimeToLive(long timeToLive)Sets the default length of time in milliseconds from its dispatch time that a produced message should be retained by the message system.static voidvalidateValidPropertyName(String propertyName)static voidvalidateValidPropertyValue(String propertyName, Object propertyValue)
-
-
-
Field Detail
-
session
protected ActiveMQSession session
-
disableMessageID
protected boolean disableMessageID
-
disableMessageTimestamp
protected boolean disableMessageTimestamp
-
defaultDeliveryMode
protected int defaultDeliveryMode
-
defaultPriority
protected int defaultPriority
-
defaultTimeToLive
protected long defaultTimeToLive
-
sendTimeout
protected int sendTimeout
-
-
Constructor Detail
-
ActiveMQMessageProducerSupport
public ActiveMQMessageProducerSupport(ActiveMQSession session)
-
-
Method Detail
-
setDeliveryDelay
public void setDeliveryDelay(long deliveryDelay) throws javax.jms.JMSExceptionGets the delivery delay associated with thisMessageProducer.- Specified by:
setDeliveryDelayin interfacejavax.jms.MessageProducer- Throws:
javax.jms.JMSException- if the JMS provider fails to close the producer due to some internal error.- Since:
- 2.0
-
getDeliveryDelay
public long getDeliveryDelay() throws javax.jms.JMSExceptionGets the delivery delay value for thisMessageProducer.- Specified by:
getDeliveryDelayin interfacejavax.jms.MessageProducer- Returns:
- the delivery delay for this messageProducer
- Throws:
javax.jms.JMSException- if the JMS provider fails to determine if deliver delay is disabled due to some internal error.
-
setDisableMessageID
public void setDisableMessageID(boolean disableMessageID) throws javax.jms.JMSExceptionSets whether message IDs are disabled.Since message IDs take some effort to create and increase a message's size, some JMS providers may be able to optimize message overhead if they are given a hint that the message ID is not used by an application. By calling the
setDisableMessageIDmethod on this message producer, a JMS client enables this potential optimization for all messages sent by this message producer. If the JMS provider accepts this hint, these messages must have the message ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.Message IDs are enabled by default.
- Specified by:
setDisableMessageIDin interfacejavax.jms.MessageProducer- Parameters:
disableMessageID- indicates if message IDs are disabled- Throws:
javax.jms.JMSException- if the JMS provider fails to close the producer due to some internal error.
-
getDisableMessageID
public boolean getDisableMessageID() throws javax.jms.JMSExceptionGets an indication of whether message IDs are disabled.- Specified by:
getDisableMessageIDin interfacejavax.jms.MessageProducer- Returns:
- an indication of whether message IDs are disabled
- Throws:
javax.jms.JMSException- if the JMS provider fails to determine if message IDs are disabled due to some internal error.
-
setDisableMessageTimestamp
public void setDisableMessageTimestamp(boolean disableMessageTimestamp) throws javax.jms.JMSExceptionSets whether message timestamps are disabled.Since timestamps take some effort to create and increase a message's size, some JMS providers may be able to optimize message overhead if they are given a hint that the timestamp is not used by an application. By calling the
setDisableMessageTimestampmethod on this message producer, a JMS client enables this potential optimization for all messages sent by this message producer. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint, the timestamp must be set to its normal value.Message timestamps are enabled by default.
- Specified by:
setDisableMessageTimestampin interfacejavax.jms.MessageProducer- Parameters:
disableMessageTimestamp- indicates if message timestamps are disabled- Throws:
javax.jms.JMSException- if the JMS provider fails to close the producer due to some internal error.
-
getDisableMessageTimestamp
public boolean getDisableMessageTimestamp() throws javax.jms.JMSExceptionGets an indication of whether message timestamps are disabled.- Specified by:
getDisableMessageTimestampin interfacejavax.jms.MessageProducer- Returns:
- an indication of whether message timestamps are disabled
- Throws:
javax.jms.JMSException- if the JMS provider fails to close the producer due to some internal error.
-
setDeliveryMode
public void setDeliveryMode(int newDeliveryMode) throws javax.jms.JMSExceptionSets the producer's default delivery mode.Delivery mode is set to
PERSISTENTby default.- Specified by:
setDeliveryModein interfacejavax.jms.MessageProducer- Parameters:
newDeliveryMode- the message delivery mode for this message producer; legal values areDeliveryMode.NON_PERSISTENTandDeliveryMode.PERSISTENT- Throws:
javax.jms.JMSException- if the JMS provider fails to set the delivery mode due to some internal error.- See Also:
MessageProducer.getDeliveryMode(),DeliveryMode.NON_PERSISTENT,DeliveryMode.PERSISTENT,Message.DEFAULT_DELIVERY_MODE
-
getDeliveryMode
public int getDeliveryMode() throws javax.jms.JMSExceptionGets the producer's default delivery mode.- Specified by:
getDeliveryModein interfacejavax.jms.MessageProducer- Returns:
- the message delivery mode for this message producer
- Throws:
javax.jms.JMSException- if the JMS provider fails to close the producer due to some internal error.
-
setPriority
public void setPriority(int newDefaultPriority) throws javax.jms.JMSExceptionSets the producer's default priority.The JMS API defines ten levels of priority value, with 0 as the lowest priority and 9 as the highest. Clients should consider priorities 0-4 as gradations of normal priority and priorities 5-9 as gradations of expedited priority. Priority is set to 4 by default.
- Specified by:
setPriorityin interfacejavax.jms.MessageProducer- Parameters:
newDefaultPriority- the message priority for this message producer; must be a value between 0 and 9- Throws:
javax.jms.JMSException- if the JMS provider fails to set the delivery mode due to some internal error.- See Also:
MessageProducer.getPriority(),Message.DEFAULT_PRIORITY
-
getPriority
public int getPriority() throws javax.jms.JMSExceptionGets the producer's default priority.- Specified by:
getPriorityin interfacejavax.jms.MessageProducer- Returns:
- the message priority for this message producer
- Throws:
javax.jms.JMSException- if the JMS provider fails to close the producer due to some internal error.- See Also:
MessageProducer.setPriority(int)
-
setTimeToLive
public void setTimeToLive(long timeToLive) throws javax.jms.JMSExceptionSets the default length of time in milliseconds from its dispatch time that a produced message should be retained by the message system.Time to live is set to zero by default.
- Specified by:
setTimeToLivein interfacejavax.jms.MessageProducer- Parameters:
timeToLive- the message time to live in milliseconds; zero is unlimited- Throws:
javax.jms.JMSException- if the JMS provider fails to set the time to live due to some internal error.- See Also:
MessageProducer.getTimeToLive(),Message.DEFAULT_TIME_TO_LIVE
-
getTimeToLive
public long getTimeToLive() throws javax.jms.JMSExceptionGets the default length of time in milliseconds from its dispatch time that a produced message should be retained by the message system.- Specified by:
getTimeToLivein interfacejavax.jms.MessageProducer- Returns:
- the message time to live in milliseconds; zero is unlimited
- Throws:
javax.jms.JMSException- if the JMS provider fails to get the time to live due to some internal error.- See Also:
MessageProducer.setTimeToLive(long)
-
send
public void send(javax.jms.Message message) throws javax.jms.JMSExceptionSends a message using theMessageProducer's default delivery mode, priority, and time to live.- Specified by:
sendin interfacejavax.jms.MessageProducer- Parameters:
message- the message to send- Throws:
javax.jms.JMSException- if the JMS provider fails to send the message due to some internal error.javax.jms.MessageFormatException- if an invalid message is specified.javax.jms.InvalidDestinationException- if a client uses this method with aMessageProducerwith an invalid destination.UnsupportedOperationException- if a client uses this method with aMessageProducerthat did not specify a destination at creation time.- Since:
- 1.1
- See Also:
Session.createProducer(javax.jms.Destination),MessageProducer
-
send
public void send(javax.jms.Message message, int deliveryMode, int priority, long timeToLive) throws javax.jms.JMSExceptionSends a message to the destination, specifying delivery mode, priority, and time to live.- Specified by:
sendin interfacejavax.jms.MessageProducer- Parameters:
message- the message to senddeliveryMode- the delivery mode to usepriority- the priority for this messagetimeToLive- the message's lifetime (in milliseconds)- Throws:
javax.jms.JMSException- if the JMS provider fails to send the message due to some internal error.javax.jms.MessageFormatException- if an invalid message is specified.javax.jms.InvalidDestinationException- if a client uses this method with aMessageProducerwith an invalid destination.UnsupportedOperationException- if a client uses this method with aMessageProducerthat did not specify a destination at creation time.- Since:
- 1.1
- See Also:
Session.createProducer(javax.jms.Destination)
-
send
public void send(javax.jms.Destination destination, javax.jms.Message message) throws javax.jms.JMSExceptionSends a message to a destination for an unidentified message producer. Uses theMessageProducer's default delivery mode, priority, and time to live.Typically, a message producer is assigned a destination at creation time; however, the JMS API also supports unidentified message producers, which require that the destination be supplied every time a message is sent.
- Specified by:
sendin interfacejavax.jms.MessageProducer- Parameters:
destination- the destination to send this message tomessage- the message to send- Throws:
javax.jms.JMSException- if the JMS provider fails to send the message due to some internal error.javax.jms.MessageFormatException- if an invalid message is specified.javax.jms.InvalidDestinationException- if a client uses this method with an invalid destination.UnsupportedOperationException- if a client uses this method with aMessageProducerthat specified a destination at creation time.- See Also:
Session.createProducer(javax.jms.Destination),MessageProducer
-
checkClosed
protected abstract void checkClosed() throws javax.jms.IllegalStateException- Throws:
javax.jms.IllegalStateException
-
getSendTimeout
public int getSendTimeout()
- Returns:
- the sendTimeout
-
setSendTimeout
public void setSendTimeout(int sendTimeout)
- Parameters:
sendTimeout- the sendTimeout to set
-
validateValidPropertyName
public static void validateValidPropertyName(String propertyName) throws javax.jms.IllegalStateRuntimeException
- Throws:
javax.jms.IllegalStateRuntimeException
-
-