|
SonicMQ API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Session
An Implementation of a JMS Session.
A JMS Session is a single threaded context for producing and consuming messages. Although it may allocate provider resources outside the Java virtual machine, it is considered a light-weight JMS object.
A session serves several purposes:
A session can create and service multiple message producers and consumers.
One typical use is to have a thread block on a synchronous MessageConsumer until a message arrives. The thread may then use one or more of the Session's MessageProducers.
Another typical use is to have one thread set up a Session by creating its producers and one or more asynchronous consumers. Since the JMS provider serializes execution of a Session's asynchronous consumers, they can safely share the resources of their session.
If a client desires to have one thread producing messages while others consume them, the client should use a separate Session for its producing thread.
It should be easy for most clients to partition their work naturally into Sessions. This model allows clients to start simply and incrementally add message processing complexity as their need for concurrency grows.
A session may be optionally specified as transacted. Each transacted session supports a single series of transactions. Each transaction groups a set of message sends and a set of message receives into an atomic unit of work. In effect, transactions organize a session's input message stream and output message stream into series of atomic units. When a transaction commits, its atomic unit of input is acknowledged and its associated atomic unit of output is sent. If a transaction rollback is done, its sent messages are destroyed and the session's input is automatically recovered.
The content of a transaction's input and output units is simply those messages that have been produced and consumed within the session's current transaction.
A transaction is completed using either its session's
commit
or rollback
method. The completion of a
session's current transaction automatically begins the next. The result
is that a transacted session always has a current transaction within
which its work is done.
JTS, or some other transaction monitor may be used to combine a session's transaction with transactions on other resources (databases, other JMS sessions, etc.). Since Java distributed transactions are controlled via JTA, use of the session's commit and rollback methods in this context is prohibited.
JMS does not require support for JTA; however, it does define how a provider supplies this support.
Although it is also possible for a JMS client to handle distributed transactions directly, it is unlikely that many JMS clients will do this. Support for JTA in JMS is targeted at systems vendors who will be integrating JMS into their application server products.
Session
Field Summary | |
---|---|
static int |
SINGLE_MESSAGE_ACKNOWLEDGE
If a session is created with the non-JMS SINGLE_MESSAGE_ACKNOWLEDGE mode, the acknowledge() method only acknowledges the message on which it is called. |
Fields inherited from interface javax.jms.Session |
---|
AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE, SESSION_TRANSACTED |
Method Summary | |
---|---|
void |
commit(java.lang.String transactionId)
Commit all messages done in this transaction and release any locks currently held. |
void |
commit(java.lang.String transactionId,
long lifespan)
Commit all messages done in this transaction and release any locks currently held. |
QueueBrowser |
createBrowser(Queue queue)
Creates a QueueBrowser object to peek at the messages on
the specified queue. |
QueueBrowser |
createBrowser(Queue queue,
java.lang.String messageSelector)
Creates a QueueBrowser object to peek at the messages on
the specified queue using a message selector. |
MessageConsumer |
createConsumer(Destination destination)
Creates a MessageConsumer for the specified destination. |
MessageConsumer |
createConsumer(Destination destination,
java.lang.String messageSelector)
Creates a MessageConsumer for the specified destination,
using a message selector. |
MessageConsumer |
createConsumer(Destination destination,
java.lang.String messageSelector,
boolean NoLocal)
Creates MessageConsumer for the specified destination, using a
message selector. |
TopicSubscriber |
createDurableSubscriber(Topic topic,
java.lang.String name)
Creates a durable subscriber to the specified topic. |
TopicSubscriber |
createDurableSubscriber(Topic topic,
java.lang.String name,
long timeToLive)
Create a durable Subscriber to the specified topic. |
TopicSubscriber |
createDurableSubscriber(Topic topic,
java.lang.String name,
java.lang.String messageSelector,
boolean noLocal)
Creates a durable subscriber to the specified topic, using a message selector and specifying whether messages published by its own connection should be delivered to it. |
TopicSubscriber |
createDurableSubscriber(Topic topic,
java.lang.String name,
java.lang.String messageSelector,
boolean noLocal,
long timeToLive)
Create a durable Subscriber to the specified topic. |
MultipartMessage |
createMultipartMessage()
Create a MultipartMessage. |
MultiTopic |
createMultiTopic()
Create an empty MultiTopic This facility is provided for the case in which a client is not able to retrieve a MultiTopic from an administered object store. |
MessageProducer |
createProducer(Destination destination)
Creates a MessageProducer to send messages to the specified
destination. |
Queue |
createQueue(java.lang.String queueName)
Creates a queue identity given a Queue name. |
TemporaryQueue |
createTemporaryQueue()
Creates a TemporaryQueue object. |
TemporaryQueue |
createTemporaryQueue(java.lang.String customID)
Creates a TemporaryQueue object whose name contains
the customID string. |
TemporaryTopic |
createTemporaryTopic()
Creates a TemporaryTopic object. |
Topic |
createTopic(java.lang.String topicName)
Creates a topic identity given a Topic name. |
XMLMessage |
createXMLMessage()
Create a XMLMessage. |
XMLMessage |
createXMLMessage(org.w3c.dom.Document aDocument)
Create an XMLMessage initialized by an XML Document. |
XMLMessage |
createXMLMessage(java.lang.String str)
Create an XMLMessage initialized by a String. |
int |
getAcknowledgeMode()
Returns the acknowledgement mode of the session. |
boolean |
getDurableMessageOrder()
Determines whether the option to preserve message order when reconnecting a durable subscriber has been selected. |
int |
getFlowToDisk()
Determines the setting of Flow-To-Disk Publishing property. |
boolean |
getSplitMultiTopicDelivery()
Gets whether messages with a MultiTopic destination should be delivered as a single message or split apart and delivered as a copy of the message on each topic in the MultiTopic. |
int |
getTxnBatchSize()
Returns the amount of information that will be batched on the client. |
void |
setAckBatchingEnabled(boolean enabled)
Specifies whether the batching of acknowledgments will be permitted in the session. |
void |
setDurableMessageOrder(boolean durableSubscriberMessageOrder)
Enable or disable preservation of message order for reconnecting durable subscribers. |
void |
setFlowControlDisabled(boolean disabled)
Disables or reenables publish flow control. |
void |
setFlowToDisk(int setting)
Enable or disable Flow-To-Disk Publishing. |
void |
setSplitMultiTopicDelivery(boolean value)
Sets whether messages with a MultiTopic destination should be delivered as a single message or split apart and delivered as a copy of the message on each topic in the MultiTopic. |
void |
setTxnBatchSize(int size)
Specifies the amount of information to be batched on the client. |
void |
unsubscribe(java.lang.String name)
Unsubscribes a durable subscription that has been created by a client. |
Methods inherited from interface javax.jms.Session |
---|
close, commit, createBytesMessage, createMapMessage, createMessage, createObjectMessage, createObjectMessage, createStreamMessage, createTextMessage, createTextMessage, getMessageListener, getTransacted, recover, rollback, run, setMessageListener |
Field Detail |
---|
static final int SINGLE_MESSAGE_ACKNOWLEDGE
Method Detail |
---|
XMLMessage createXMLMessage() throws JMSException
JMSException
- if JMS fails to create this message
due to some internal error.XMLMessage createXMLMessage(java.lang.String str) throws JMSException
str
- the string buffer used to initialize this message.
JMSException
- if JMS fails to create this message
due to some internal error.XMLMessage createXMLMessage(org.w3c.dom.Document aDocument) throws JMSException
aDocument
- The Document (DOM) used to initialize the message.
JMSException
- if JMS fails to create this message
due to some internal error.MultipartMessage createMultipartMessage() throws JMSException
JMSException
- if JMS fails to create this message
due to some internal error.void commit(java.lang.String transactionId) throws JMSException
transactionId
- UUID for duplicate transaction detection
JMSException
- if JMS implementation fails to commit the
the transaction due to some internal error.
TransactionRolledBackException
- if the transaction
gets rolled back due to some internal error
during commit or duplicate UUID.
java.lang.IllegalStateException
- if commit() is called on a
non-transacted sessionvoid commit(java.lang.String transactionId, long lifespan) throws JMSException
transactionId
- UUID for duplicate transaction detectionlifespan
- length of life of the UUID (in milliseconds)
JMSException
- if JMS implementation fails to commit the
the transaction due to some internal error.
TransactionRolledBackException
- if the transaction
gets rolled back due to some internal error
during commit or duplicate UUID.
java.lang.IllegalStateException
- if commit() is called on a
non-transacted sessionvoid setTxnBatchSize(int size) throws JMSException
size
- The number of bytes to batch
java.lang.IllegalStateException
- if called on a non-transacted session
JMSException
- if JMS implementation fails set the batch size due
some internal error.int getTxnBatchSize() throws JMSException
JMSException
- if JMS implementation fails to get the batch size due
some internal error.void setAckBatchingEnabled(boolean enabled) throws JMSException
enabled
-
JMSException
int getAcknowledgeMode() throws JMSException
getAcknowledgeMode
in interface Session
JMSException
- if the JMS provider fails to return the
acknowledgment mode due to some internal error.Connection.createSession(boolean, int)
MessageProducer createProducer(Destination destination) throws JMSException
MessageProducer
to send messages to the specified
destination.
A client uses a MessageProducer
object to send
messages to a destination. Since Queue
and Topic
both inherit from Destination
, they can be used in
the destination parameter to create a MessageProducer
object.
createProducer
in interface Session
destination
- the Destination
to send to,
or null if this is a producer which does not have a specified
destination.
JMSException
- if the session fails to create a MessageProducer
due to some internal error.
InvalidDestinationException
- if an invalid destination
is specified.MessageConsumer createConsumer(Destination destination) throws JMSException
MessageConsumer
for the specified destination.
Since Queue
and Topic
both inherit from Destination
, they can be used in
the destination parameter to create a MessageConsumer
.
createConsumer
in interface Session
destination
- the Destination
to access.
JMSException
- if the session fails to create a consumer
due to some internal error.
InvalidDestinationException
- if an invalid destination
is specified.MessageConsumer createConsumer(Destination destination, java.lang.String messageSelector) throws JMSException
MessageConsumer
for the specified destination,
using a message selector.
Since Queue
and Topic
both inherit from Destination
, they can be used in
the destination parameter to create a MessageConsumer
.
A client uses a MessageConsumer
object to receive
messages that have been sent to a destination.
createConsumer
in interface Session
destination
- the Destination
to accessmessageSelector
- only messages with properties matching the
message selector expression are delivered. A value of null or
an empty string indicates that there is no message selector
for the message consumer.
JMSException
- if the session fails to create a MessageConsumer
due to some internal error.
InvalidDestinationException
- if an invalid destination
is specified.
InvalidSelectorException
- if the message selector is invalid.MessageConsumer createConsumer(Destination destination, java.lang.String messageSelector, boolean NoLocal) throws JMSException
MessageConsumer
for the specified destination, using a
message selector. This method can specify whether messages published by
its own connection should be delivered to it, if the destination is a
topic.
Since Queue
and Topic
both inherit from Destination
, they can be used in
the destination parameter to create a MessageConsumer
.
A client uses a MessageConsumer
object to receive
messages that have been published to a destination.
In some cases, a connection may both publish and subscribe to a
topic. The consumer NoLocal
attribute allows a consumer
to inhibit the delivery of messages published by its own connection.
The default value for this attribute is False. The noLocal
value must be supported by destinations that are topics.
createConsumer
in interface Session
destination
- the Destination
to accessmessageSelector
- only messages with properties matching the
message selector expression are delivered. A value of null or
an empty string indicates that there is no message selector
for the message consumer.NoLocal
- - if true, and the destination is a topic,
inhibits the delivery of messages published
by its own connection. The behavior for
NoLocal
is
not specified if the destination is a queue or
a shared topic.
JMSException
- if the session fails to create a MessageConsumer
due to some internal error.
InvalidDestinationException
- if an invalid destination
is specified.
InvalidSelectorException
- if the message selector is invalid.Queue createQueue(java.lang.String queueName) throws JMSException
Queue
name.
This facility is provided for the rare cases where clients need to dynamically manipulate queue identity. It allows the creation of a queue identity with a provider-specific name. Clients that depend on this ability are not portable.
Note that this method is not for creating the physical queue.
The physical creation of queues is an administrative task and is not
to be initiated by the JMS API. The one exception is the
creation of temporary queues, which is accomplished with the
createTemporaryQueue
method.
createQueue
in interface Session
queueName
- the name of this Queue
Queue
with the given name
JMSException
- if the session fails to create a queue
due to some internal error.Topic createTopic(java.lang.String topicName) throws JMSException
Topic
name.
This facility is provided for the rare cases where clients need to dynamically manipulate topic identity. This allows the creation of a topic identity with a provider-specific name. Clients that depend on this ability are not portable.
Note that this method is not for creating the physical topic.
The physical creation of topics is an administrative task and is not
to be initiated by the JMS API. The one exception is the
creation of temporary topics, which is accomplished with the
createTemporaryTopic
method.
createTopic
in interface Session
topicName
- the name of this Topic
Topic
with the given name
JMSException
- if the session fails to create a topic
due to some internal error.MultiTopic createMultiTopic() throws JMSException
This facility is provided for the case in which a client is not able to retrieve a MultiTopic from an administered object store. Clients that use MultiTopics are not portable
JMSException
- if a session fails to create a queue
due to some JMS error.TopicSubscriber createDurableSubscriber(Topic topic, java.lang.String name) throws JMSException
If a client needs to receive all the messages published on a
topic, including the ones published while the subscriber is inactive,
it uses a durable TopicSubscriber
. The JMS provider
retains a record of this
durable subscription and insures that all messages from the topic's
publishers are retained until they are acknowledged by this
durable subscriber or they have expired.
Sessions with durable subscribers must always provide the same
client identifier. In addition, each client must specify a name that
uniquely identifies (within client identifier) each durable
subscription it creates. Only one session at a time can have a
TopicSubscriber
for a particular durable subscription.
A client can change an existing durable subscription by creating
a durable TopicSubscriber
with the same name and a new
topic and/or
message selector. Changing a durable subscriber is equivalent to
unsubscribing (deleting) the old one and creating a new one.
In some cases, a connection may both publish and subscribe to a
topic. The subscriber NoLocal
attribute allows a subscriber
to inhibit the delivery of messages published by its own connection.
The default value for this attribute is false.
createDurableSubscriber
in interface Session
topic
- the non-temporary Topic
to subscribe toname
- the name used to identify this subscription
JMSException
- if the session fails to create a subscriber
due to some internal error.
InvalidDestinationException
- if an invalid topic is specified.TopicSubscriber createDurableSubscriber(Topic topic, java.lang.String name, java.lang.String messageSelector, boolean noLocal) throws JMSException
If a client needs to receive all the messages published on a
topic, including the ones published while the subscriber is inactive,
it uses a durable TopicSubscriber
. The JMS provider
retains a record of this
durable subscription and insures that all messages from the topic's
publishers are retained until they are acknowledged by this
durable subscriber or they have expired.
Sessions with durable subscribers must always provide the same
client identifier. In addition, each client must specify a name which
uniquely identifies (within client identifier) each durable
subscription it creates. Only one session at a time can have a
TopicSubscriber
for a particular durable subscription.
An inactive durable subscriber is one that exists but
does not currently have a message consumer associated with it.
A client can change an existing durable subscription by creating
a durable TopicSubscriber
with the same name and a new
topic and/or
message selector. Changing a durable subscriber is equivalent to
unsubscribing (deleting) the old one and creating a new one.
createDurableSubscriber
in interface Session
topic
- the non-temporary Topic
to subscribe toname
- the name used to identify this subscriptionmessageSelector
- only messages with properties matching the
message selector expression are delivered. A value of null or
an empty string indicates that there is no message selector
for the message consumer.noLocal
- if set, inhibits the delivery of messages published
by its own connection. The behavior of noLocal
is
not specified if the destination is a shared topic.
JMSException
- if the session fails to create a subscriber
due to some internal error.
InvalidDestinationException
- if an invalid topic is specified.
InvalidSelectorException
- if the message selector is invalid.TopicSubscriber createDurableSubscriber(Topic topic, java.lang.String name, long timeToLive) throws JMSException
Creates a DurableSubscriber with the added ability to specify the timeToLive parameter describer as described below.
topic
- the topic to subscribe toname
- the name used to identify this subscription.timeToLive
- time in milliseconds that a DurableSubscriber
will live for after it has disconnected.
The maximum value for timeToLive is (315360000000L) 10 years
NOTE: A timeToLive value <= 0 will result in NOT setting a disconnected timeToLive.
JMSException
- if a session fails to create a subscriber
due to some JMS error.
InvalidDestinationException
- if invalid Topic specified.TopicSession
,
TopicSubscriber
TopicSubscriber createDurableSubscriber(Topic topic, java.lang.String name, java.lang.String messageSelector, boolean noLocal, long timeToLive) throws JMSException
Creates a DurableSubscriber with the added ability to specify the timeToLive parameter describer as described below.
topic
- the topic to subscribe toname
- the name used to identify this subscription.messageSelector
- only messages with properties matching the
message selector expression are delivered. This value may be null.noLocal
- if set, inhibits the delivery of messages published
by its own connection. The behavior of noLocal
is
not specified if the destination is a shared topic.timeToLive
- time in milliseconds that a DurableSubscriber
will live for after it has disconnected.
The maximum value for timeToLive is (315360000000L) 10 years
NOTE: A timeToLive value <= 0 will result in NOT setting a disconnected timeToLive.
JMSException
- if a session fails to create a subscriber
due to some JMS error or invalid selector.
InvalidDestinationException
- if invalid Topic specified.
InvalidSelectorException
- if the message selector is invalid.TopicSession
,
TopicSubscriber
QueueBrowser createBrowser(Queue queue) throws JMSException
QueueBrowser
object to peek at the messages on
the specified queue.
createBrowser
in interface Session
queue
- the queue
to access
JMSException
- if the session fails to create a browser
due to some internal error.
InvalidDestinationException
- if an invalid destination
is specifiedQueueBrowser createBrowser(Queue queue, java.lang.String messageSelector) throws JMSException
QueueBrowser
object to peek at the messages on
the specified queue using a message selector.
createBrowser
in interface Session
queue
- the queue
to accessmessageSelector
- only messages with properties matching the
message selector expression are delivered. A value of null or
an empty string indicates that there is no message selector
for the message consumer.
JMSException
- if the session fails to create a browser
due to some internal error.
InvalidDestinationException
- if an invalid destination
is specified
InvalidSelectorException
- if the message selector is invalid.TemporaryTopic createTemporaryTopic() throws JMSException
TemporaryTopic
object. Its lifetime will be that
of the Connection
unless it is deleted earlier.
createTemporaryTopic
in interface Session
JMSException
- if the session fails to create a temporary
topic due to some internal error.TemporaryQueue createTemporaryQueue() throws JMSException
TemporaryQueue
object. Its lifetime will be that
of the Connection
unless it is deleted earlier.
createTemporaryQueue
in interface Session
JMSException
- if the session fails to create a temporary
queue due to some internal error.TemporaryQueue createTemporaryQueue(java.lang.String customID) throws JMSException
TemporaryQueue
object whose name contains
the customID string. The name is otherwise constructed internally.
customID
- an application supplied string which will be contained
somewhere in the temporary queue name
JMSException
void unsubscribe(java.lang.String name) throws JMSException
This method deletes the state being maintained on behalf of the subscriber by its provider.
It is erroneous for a client to delete a durable subscription
while there is an active MessageConsumer
or TopicSubscriber
for the
subscription, or while a consumed message is part of a pending
transaction or has not been acknowledged in the session.
unsubscribe
in interface Session
name
- the name used to identify this subscription
JMSException
- if the session fails to unsubscribe to the
durable subscription due to some internal error.
InvalidDestinationException
- if an invalid subscription name
is specified.void setFlowControlDisabled(boolean disabled)
void setDurableMessageOrder(boolean durableSubscriberMessageOrder)
Enables
durableSubscriberMessageOrder
- if true, by default reconnecting durable subscribers will preserve message order)getDurableMessageOrder()
boolean getDurableMessageOrder()
setDurableMessageOrder(boolean durableSubscriberMessageOrder)
void setFlowToDisk(int setting)
setting
- 0 - use broker-side setting
1 - set the feature "on" for the session
2 - set the feature "off" for the sessiongetFlowToDisk()
,
Constants.FLOW_TO_DISK_USE_BROKER_SETTING
,
Constants.FLOW_TO_DISK_ON
,
Constants.FLOW_TO_DISK_OFF
int getFlowToDisk()
setFlowToDisk(int)
,
Constants.FLOW_TO_DISK_USE_BROKER_SETTING
,
Constants.FLOW_TO_DISK_ON
,
Constants.FLOW_TO_DISK_OFF
void setSplitMultiTopicDelivery(boolean value)
value
- Whether or not to split multi topic delivery.boolean getSplitMultiTopicDelivery()
|
SonicMQ API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |