Class MessageProducer

  • All Implemented Interfaces:
    AutoCloseable, MessageProducer
    Direct Known Subclasses:
    QueueSender, TopicPublisher

    public class MessageProducer
    extends Object
    implements MessageProducer
    Implements the 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.

    • 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
        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.
      • timestampDisabled

        private boolean timestampDisabled
        true if the time stamp is disabled.
      • identified

        private boolean identified
        true if the producer's destination is identified.
      • closed

        protected boolean closed
        true if 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
    • Method Detail

      • setDeliveryMode

        public void setDeliveryMode​(int deliveryMode)
                             throws JMSException
        API method. Sets the producer's default delivery mode.

        Delivery mode is set to PERSISTENT by default.

        Specified by:
        setDeliveryMode in interface MessageProducer
        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 JMSException
        API 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:
        setPriority in interface MessageProducer
        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 JMSException
        API 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:
        setTimeToLive in interface MessageProducer
        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 JMSException
        API 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:
        setDisableMessageTimestamp in interface MessageProducer
        Parameters:
        value - indicates if message timestamps are disabled.
        Throws:
        IllegalStateException - If the producer is closed.
        JMSException
      • getTimeToLive

        public long getTimeToLive()
                           throws JMSException
        API 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:
        getTimeToLive in interface MessageProducer
        Returns:
        the message time to live in milliseconds; zero is unlimited.
        Throws:
        IllegalStateException - If the producer is closed.
        JMSException
      • 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:
        send in interface MessageProducer
        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:
        send in interface MessageProducer
        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:
        send in interface MessageProducer
        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,
                         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:
        send in interface MessageProducer
        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:
        send in interface MessageProducer
        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:
        send in interface MessageProducer
        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 JMSException
        API 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:
        close in interface AutoCloseable
        Specified by:
        close in interface MessageProducer
        Throws:
        JMSException - Actually never thrown.
      • setDeliveryDelay

        public void setDeliveryDelay​(long deliveryDelay)
                              throws JMSException
        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. the delivery delay is set to zero by default
        Specified by:
        setDeliveryDelay in interface MessageProducer
        Parameters:
        deliveryDelay - the delivery delay in milliseconds.
        Throws:
        JMSException