public class MessageProducer extends Object implements MessageProducer
javax.jms.MessageProducer
interface.
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.
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed
true if the producer is closed. |
private long |
deliveryDelay
Default delivery delay
|
private int |
deliveryMode
Default delivery mode.
|
protected Destination |
dest
The destination the producer sends messages to.
|
private boolean |
identified
true if the producer's destination is identified. |
private static org.objectweb.util.monolog.api.Logger |
logger |
private boolean |
messageIDDisabled
true if 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 int |
priority
Default priority.
|
protected Session |
sess
The session the producer belongs to.
|
private boolean |
timestampDisabled
true if the time stamp is disabled. |
private long |
timeToLive
Default time to live.
|
Constructor and Description |
---|
MessageProducer(Session sess,
Destination dest)
Constructs a producer.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
API method.
|
private void |
doSend(Destination dest,
Message message,
int deliveryMode,
int priority,
long timeToLive)
Actually sends a message to a given destination.
|
private void |
doSend(Destination dest,
Message message,
int deliveryMode,
int priority,
long timeToLive,
CompletionListener completionListener)
Actually sends a message to a given destination.
|
long |
getDeliveryDelay()
API 2.0
Get the delivery delay.
|
int |
getDeliveryMode()
API method.
|
Destination |
getDestination()
API method.
|
boolean |
getDisableMessageID()
API method.
|
boolean |
getDisableMessageTimestamp()
API method.
|
int |
getPriority()
API method.
|
long |
getTimeToLive()
API method.
|
void |
send(Destination dest,
Message message)
API method.
|
void |
send(Destination destination,
Message message,
CompletionListener completionListener)
API 2.0 method.
|
void |
send(Destination dest,
Message message,
int deliveryMode,
int priority,
long timeToLive)
API method.
|
void |
send(Destination destination,
Message message,
int deliveryMode,
int priority,
long timeToLive,
CompletionListener completionListener)
API 2.0 method.
|
void |
send(Message message)
API method.
|
void |
send(Message message,
CompletionListener completionListener)
API 2.0 method.
|
void |
send(Message message,
int deliveryMode,
int priority,
long timeToLive)
API method.
|
void |
send(Message message,
int deliveryMode,
int priority,
long timeToLive,
CompletionListener completionListener)
API 2.0 method.
|
void |
setDeliveryDelay(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.
|
void |
setDeliveryMode(int deliveryMode)
API method.
|
void |
setDisableMessageID(boolean value)
API method, not taken into account.
|
void |
setDisableMessageTimestamp(boolean value)
API method.
|
void |
setPriority(int priority)
API method.
|
void |
setTimeToLive(long timeToLive)
API method.
|
private int deliveryMode
private int priority
private long timeToLive
private long deliveryDelay
private boolean messageIDDisabled
true
if 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 boolean timestampDisabled
true
if the time stamp is disabled.private boolean identified
true
if the producer's destination is identified.protected boolean closed
true
if the producer is closed.protected Session sess
protected Destination dest
private static org.objectweb.util.monolog.api.Logger logger
MessageProducer(Session sess, Destination dest) throws JMSException
sess
- The session the producer belongs to.dest
- The destination the producer sends messages to.InvalidDestinationException
- if an invalid destination is specified.IllegalStateException
- If the connection is broken.JMSException
- If the creation fails for any other reason.public void setDisableMessageID(boolean value) throws JMSException
setDisableMessageID
in interface MessageProducer
value
- indicates if message IDs are disabled, not taken in account.IllegalStateException
- If the producer is closed.JMSException
public void setDeliveryMode(int deliveryMode) throws JMSException
Delivery mode is set to PERSISTENT by default.
setDeliveryMode
in interface MessageProducer
deliveryMode
- the message delivery mode for this message producer; legal values are
DeliveryMode.NON_PERSISTENT and DeliveryMode.PERSISTENT.IllegalStateException
- If the producer is closed.JMSException
- When setting an invalid delivery mode.public void setPriority(int priority) throws JMSException
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).
setPriority
in interface MessageProducer
priority
- the message priority for this message producer; must be a value
between 0 and 9.IllegalStateException
- If the producer is closed.JMSException
- When setting an invalid priority.public void setTimeToLive(long timeToLive) throws JMSException
Time to live is set to zero by default (Message.DEFAULT_TIME_TO_LIVE).
setTimeToLive
in interface MessageProducer
timeToLive
- the message time to live in milliseconds; zero is unlimited.IllegalStateException
- If the producer is closed.JMSException
public void setDisableMessageTimestamp(boolean value) throws JMSException
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.
setDisableMessageTimestamp
in interface MessageProducer
value
- indicates if message timestamps are disabled.IllegalStateException
- If the producer is closed.JMSException
public Destination getDestination() throws JMSException
getDestination
in interface MessageProducer
IllegalStateException
- If the producer is closed.JMSException
public boolean getDisableMessageID() throws JMSException
getDisableMessageID
in interface MessageProducer
IllegalStateException
- If the producer is closed.JMSException
public int getDeliveryMode() throws JMSException
getDeliveryMode
in interface MessageProducer
IllegalStateException
- If the producer is closed.JMSException
public int getPriority() throws JMSException
getPriority
in interface MessageProducer
IllegalStateException
- If the producer is closed.JMSException
public long getTimeToLive() throws JMSException
getTimeToLive
in interface MessageProducer
IllegalStateException
- If the producer is closed.JMSException
public boolean getDisableMessageTimestamp() throws JMSException
getDisableMessageTimestamp
in interface MessageProducer
IllegalStateException
- If the producer is closed.JMSException
public void send(Message message) throws JMSException
send
in interface MessageProducer
message
- the message to send.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.public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
send
in interface MessageProducer
message
- the message to send.deliveryMode
- the delivery mode to use.priority
- the priority for this message.timeToLive
- the message's lifetime in milliseconds.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.public void send(Destination dest, Message message) throws JMSException
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.
send
in interface MessageProducer
dest
- the destination to send this message to.message
- the message to send.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.public void send(Destination dest, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
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.
send
in interface MessageProducer
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.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.public void send(Message message, CompletionListener completionListener) throws JMSException
message
- the message to send.completionListener
- the completion listener (call back).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.public void send(Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener) throws JMSException
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).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.public void send(Destination destination, Message message, CompletionListener completionListener) throws JMSException
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.
dest
- the destination to send this message to.message
- the message to send.completionListener
- the completion listener (call back).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.public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener) throws JMSException
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.
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).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.public void close() throws JMSException
In order to free significant resources allocated on behalf of a MessageProducer, clients should close them when they are not needed.
close
in interface MessageProducer
JMSException
- Actually never thrown.private void doSend(Destination dest, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
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.private void doSend(Destination dest, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener completionListener) throws JMSException
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.public void setDeliveryDelay(long deliveryDelay) throws JMSException
deliveryDelay
- the delivery delay in milliseconds.if
- fail to set the delivery delay due to some internal error.JMSException
public long getDeliveryDelay() throws JMSException
if
- fail to get the delivery delay due to some internal error.JMSException
Copyright © 2016 ScalAgent D.T.. All Rights Reserved.