Class MessageProducer
- java.lang.Object
-
- org.objectweb.joram.client.jms.MessageProducer
-
- All Implemented Interfaces:
AutoCloseable,MessageProducer
- Direct Known Subclasses:
QueueSender,TopicPublisher
public class MessageProducer extends Object implements MessageProducer
Implements thejavax.jms.MessageProducerinterface.A client uses a MessageProducer object to send messages to a destination. A MessageProducer object is created by calling the createProducer method on the session object. A message producer is normally dedicated to a unique destination.
A client also has the option of creating a message producer without supplying a unique destination. In this case, a destination must be provided with every send operation.
A client can specify a default delivery mode, priority, and time to live for messages sent by a message producer. It can also specify the delivery mode, priority, and time to live for each individual message.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanclosedtrueif the producer is closed.private longdeliveryDelayDefault delivery delayprivate intdeliveryModeDefault delivery mode.protected DestinationdestThe destination the producer sends messages to.private booleanidentifiedtrueif the producer's destination is identified.private static org.objectweb.util.monolog.api.Loggerloggerprivate booleanmessageIDDisabledtrueif the client requests not to use the message identifiers; however it is not taken into account, as our MOM needs message identifiers for managing acknowledgements.private intpriorityDefault priority.protected SessionsessThe session the producer belongs to.private booleantimestampDisabledtrueif the time stamp is disabled.private longtimeToLiveDefault time to live.
-
Constructor Summary
Constructors Constructor Description MessageProducer(Session sess, Destination dest)Constructs a producer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()API method.private voiddoSend(Destination dest, Message message, int deliveryMode, int priority, long timeToLive)Actually sends a message to a given destination.private voiddoSend(Destination dest, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener)Actually sends a message to a given destination.longgetDeliveryDelay()API 2.0 Get the delivery delay.intgetDeliveryMode()API method.DestinationgetDestination()API method.booleangetDisableMessageID()API method.booleangetDisableMessageTimestamp()API method.intgetPriority()API method.longgetTimeToLive()API method.voidsend(Destination dest, Message message)API method.voidsend(Destination dest, Message message, int deliveryMode, int priority, long timeToLive)API method.voidsend(Destination destination, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener)API 2.0 method.voidsend(Destination destination, Message message, CompletionListener completionListener)API 2.0 method.voidsend(Message message)API method.voidsend(Message message, int deliveryMode, int priority, long timeToLive)API method.voidsend(Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener)API 2.0 method.voidsend(Message message, CompletionListener completionListener)API 2.0 method.voidsetDeliveryDelay(long deliveryDelay)API 2.0 Sets the minimum length of time in milliseconds that must elapse after a message is sent before the consumer can consume this message.voidsetDeliveryMode(int deliveryMode)API method.voidsetDisableMessageID(boolean value)API method, not taken into account.voidsetDisableMessageTimestamp(boolean value)API method.voidsetPriority(int priority)API method.voidsetTimeToLive(long timeToLive)API method.
-
-
-
Field Detail
-
deliveryMode
private int deliveryMode
Default delivery mode.
-
priority
private int priority
Default priority.
-
timeToLive
private long timeToLive
Default time to live.
-
deliveryDelay
private long deliveryDelay
Default delivery delay
-
messageIDDisabled
private boolean messageIDDisabled
trueif the client requests not to use the message identifiers; however it is not taken into account, as our MOM needs message identifiers for managing acknowledgements.
-
timestampDisabled
private boolean timestampDisabled
trueif the time stamp is disabled.
-
identified
private boolean identified
trueif the producer's destination is identified.
-
closed
protected boolean closed
trueif the producer is closed.
-
sess
protected Session sess
The session the producer belongs to.
-
dest
protected Destination dest
The destination the producer sends messages to.
-
logger
private static org.objectweb.util.monolog.api.Logger logger
-
-
Constructor Detail
-
MessageProducer
MessageProducer(Session sess, Destination dest) throws JMSException
Constructs a producer.- Parameters:
sess- The session the producer belongs to.dest- The destination the producer sends messages to.- Throws:
InvalidDestinationException- if an invalid destination is specified.IllegalStateException- If the connection is broken.JMSException- If the creation fails for any other reason.
-
-
Method Detail
-
setDisableMessageID
public void setDisableMessageID(boolean value) throws JMSExceptionAPI method, not taken into account. Message IDs are always enabled.- Specified by:
setDisableMessageIDin interfaceMessageProducer- Parameters:
value- indicates if message IDs are disabled, not taken in account.- Throws:
IllegalStateException- If the producer is closed.JMSException
-
setDeliveryMode
public void setDeliveryMode(int deliveryMode) throws JMSExceptionAPI method. Sets the producer's default delivery mode.Delivery mode is set to PERSISTENT by default.
- Specified by:
setDeliveryModein interfaceMessageProducer- Parameters:
deliveryMode- the message delivery mode for this message producer; legal values are DeliveryMode.NON_PERSISTENT and DeliveryMode.PERSISTENT.- Throws:
IllegalStateException- If the producer is closed.JMSException- When setting an invalid delivery mode.
-
setPriority
public void setPriority(int priority) throws JMSExceptionAPI method. Sets 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 (Message.DEFAULT_PRIORITY).
- Specified by:
setPriorityin interfaceMessageProducer- Parameters:
priority- the message priority for this message producer; must be a value between 0 and 9.- Throws:
IllegalStateException- If the producer is closed.JMSException- When setting an invalid priority.
-
setTimeToLive
public void setTimeToLive(long timeToLive) throws JMSExceptionAPI method. Sets the default duration of time in milliseconds that a produced message should be retained by the provider.Time to live is set to zero by default (Message.DEFAULT_TIME_TO_LIVE).
- Specified by:
setTimeToLivein interfaceMessageProducer- Parameters:
timeToLive- the message time to live in milliseconds; zero is unlimited.- Throws:
IllegalStateException- If the producer is closed.JMSException
-
setDisableMessageTimestamp
public void setDisableMessageTimestamp(boolean value) throws JMSExceptionAPI method. Sets whether message timestamps are disabled.Since timestamps take some effort to create and increase a message's size, Joram optimizes message overhead if it is given a hint that the timestamp is not used by an application. By calling the setDisableMessageTimestamp method on this message producer, a JMS client enables this potential optimization for all messages sent by this message producer (the produced messages have the timestamp set to zero).
Message timestamps are enabled by default.
- Specified by:
setDisableMessageTimestampin interfaceMessageProducer- Parameters:
value- indicates if message timestamps are disabled.- Throws:
IllegalStateException- If the producer is closed.JMSException
-
getDestination
public Destination getDestination() throws JMSException
API method. Gets the destination associated with this MessageProducer.- Specified by:
getDestinationin interfaceMessageProducer- Returns:
- the destination associated with this MessageProducer.
- Throws:
IllegalStateException- If the producer is closed.JMSException
-
getDisableMessageID
public boolean getDisableMessageID() throws JMSExceptionAPI method. Gets an indication of whether message IDs are disabled, always false.- Specified by:
getDisableMessageIDin interfaceMessageProducer- Returns:
- false.
- Throws:
IllegalStateException- If the producer is closed.JMSException
-
getDeliveryMode
public int getDeliveryMode() throws JMSExceptionAPI method. Gets the producer's default delivery mode, by default Message.DEFAULT_DELIVERY_MODE.- Specified by:
getDeliveryModein interfaceMessageProducer- Returns:
- the message delivery mode for this message producer.
- Throws:
IllegalStateException- If the producer is closed.JMSException
-
getPriority
public int getPriority() throws JMSExceptionAPI method. Gets the producer's default priority, by default Message.DEFAULT_PRIORITY.- Specified by:
getPriorityin interfaceMessageProducer- Returns:
- the message priority for this message producer.
- Throws:
IllegalStateException- If the producer is closed.JMSException
-
getTimeToLive
public long getTimeToLive() throws JMSExceptionAPI method. Gets the default duration in milliseconds that a produced message should be retained by the provider, by default Message.DEFAULT_TIME_TO_LIVE.- Specified by:
getTimeToLivein interfaceMessageProducer- Returns:
- the message time to live in milliseconds; zero is unlimited.
- Throws:
IllegalStateException- If the producer is closed.JMSException
-
getDisableMessageTimestamp
public boolean getDisableMessageTimestamp() throws JMSExceptionAPI method. Gets an indication of whether message timestamps are disabled.- Specified by:
getDisableMessageTimestampin interfaceMessageProducer- Returns:
- an indication of whether message timestamps are disabled.
- Throws:
IllegalStateException- If the producer is closed.JMSException
-
send
public void send(Message message) throws JMSException
API method. Sends a message with the MessageProducer's default delivery parameters.- Specified by:
sendin interfaceMessageProducer- Parameters:
message- the message to send.- Throws:
UnsupportedOperationException- If the dest is unidentified.IllegalStateException- If the producer is closed, or if the connection is broken.JMSException- If the request fails for any other reason.
-
send
public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
API method. Sends a message to the destination with given delivery parameters.- Specified by:
sendin interfaceMessageProducer- Parameters:
message- the message to send.deliveryMode- the delivery mode to use.priority- the priority for this message.timeToLive- the message's lifetime in milliseconds.- Throws:
UnsupportedOperationException- If the dest is unidentified.IllegalStateException- If the producer is closed, or if the connection is broken.JMSException- If the request fails for any other reason.
-
send
public void send(Destination dest, Message message) throws JMSException
API method. Sends a message to a destination for an unidentified message producer using default delivery parameters.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 interfaceMessageProducer- Parameters:
dest- the destination to send this message to.message- the message to send.- Throws:
UnsupportedOperationException- When the producer did not properly identify itself.JMSSecurityException- If the user if not a WRITER on the specified destination.IllegalStateException- If the producer is closed, or if the connection is broken.JMSException- If the request fails for any other reason.
-
send
public void send(Destination dest, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
API method. Sends a message to a destination for an unidentified message producer with given delivery parameters.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 interfaceMessageProducer- Parameters:
dest- the destination to send this message to.message- the message to send.deliveryMode- the delivery mode to use.priority- the priority for this message.timeToLive- the message's lifetime in milliseconds.- Throws:
UnsupportedOperationException- When the producer did not properly identify itself.JMSSecurityException- If the user if not a WRITER on the specified destination.IllegalStateException- If the producer is closed, or if the connection is broken.JMSException- If the request fails for any other reason.
-
send
public void send(Message message, CompletionListener completionListener) throws JMSException
API 2.0 method. Sends asynchronous message with the MessageProducer's default delivery parameters.- Specified by:
sendin interfaceMessageProducer- Parameters:
message- the message to send.completionListener- the completion listener (call back).- Throws:
UnsupportedOperationException- If the dest is unidentified.IllegalStateException- If the producer is closed, or if the connection is broken.JMSException- If the request fails for any other reason.
-
send
public void send(Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener) throws JMSException
API 2.0 method. Sends asynchronous message to the destination with given delivery parameters.- Specified by:
sendin interfaceMessageProducer- Parameters:
message- the message to send.deliveryMode- the delivery mode to use.priority- the priority for this message.timeToLive- the message's lifetime in milliseconds.completionListener- the completion listener (call back).- Throws:
UnsupportedOperationException- If the dest is unidentified.IllegalStateException- If the producer is closed, or if the connection is broken.JMSException- If the request fails for any other reason.
-
send
public void send(Destination destination, Message message, CompletionListener completionListener) throws JMSException
API 2.0 method. Sends asynchronous message to a destination for an unidentified message producer using default delivery parameters.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 interfaceMessageProducer- Parameters:
dest- the destination to send this message to.message- the message to send.completionListener- the completion listener (call back).- Throws:
UnsupportedOperationException- When the producer did not properly identify itself.JMSSecurityException- If the user if not a WRITER on the specified destination.IllegalStateException- If the producer is closed, or if the connection is broken.JMSException- If the request fails for any other reason.
-
send
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener) throws JMSException
API 2.0 method. Sends asynchronous message to a destination for an unidentified message producer with given delivery parameters.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 interfaceMessageProducer- Parameters:
dest- the destination to send this message to.message- the message to send.deliveryMode- the delivery mode to use.priority- the priority for this message.timeToLive- the message's lifetime in milliseconds.completionListener- the completion listener (call back).- Throws:
UnsupportedOperationException- When the producer did not properly identify itself.JMSSecurityException- If the user if not a WRITER on the specified destination.IllegalStateException- If the producer is closed, or if the connection is broken.JMSException- If the request fails for any other reason.
-
close
public void close() throws JMSExceptionAPI method. Closes the message producer.In order to free significant resources allocated on behalf of a MessageProducer, clients should close them when they are not needed.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceMessageProducer- Throws:
JMSException- Actually never thrown.
-
doSend
private void doSend(Destination dest, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
Actually sends a message to a given destination.- Throws:
MessageFormatException- If the message to send is invalid.InvalidDestinationException- If the specified destination is invalid.IllegalStateException- If the connection is broken.JMSException- If the request fails for any other reason.
-
doSend
private void doSend(Destination dest, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener) throws JMSException
Actually sends a message to a given destination.- Throws:
MessageFormatException- If the message to send is invalid.InvalidDestinationException- If the specified destination is invalid.IllegalStateException- If the connection is broken.JMSException- If the request fails for any other reason.
-
setDeliveryDelay
public void setDeliveryDelay(long deliveryDelay) throws JMSExceptionAPI 2.0 Sets the minimum length of time in milliseconds that must elapse after a message is sent before the consumer can consume this message. the delivery delay is set to zero by default- Specified by:
setDeliveryDelayin interfaceMessageProducer- Parameters:
deliveryDelay- the delivery delay in milliseconds.- Throws:
JMSException
-
getDeliveryDelay
public long getDeliveryDelay() throws JMSExceptionAPI 2.0 Get the delivery delay.- Specified by:
getDeliveryDelayin interfaceMessageProducer- Returns:
- the delivery delay in milliseconds.
- Throws:
JMSException
-
-