com.waveset.util.jms
Class JmsWriterBase

java.lang.Object
  extended bycom.waveset.util.jms.JmsWriterBase
All Implemented Interfaces:
JmsWriter
Direct Known Subclasses:
JmsQueueWriter, JmsTopicWriter

public abstract class JmsWriterBase
extends java.lang.Object
implements JmsWriter

This abstract class defines the code that is shareable between all JmsWriter classes.


Field Summary
protected  javax.jms.Connection _connection
           
protected  javax.jms.Session _session
           
 
Constructor Summary
protected JmsWriterBase()
           
 
Method Summary
 void close()
          Inform the system that no more messaging will occur on this object.
 void commit()
          Commit all messages done in the current transaction and release any locks currently held.
 javax.jms.BytesMessage createBytesMessage()
           
 javax.jms.MapMessage createMapMessage()
           
 javax.jms.ObjectMessage createObjectMessage()
           
 javax.jms.StreamMessage createStreamMessage()
           
 javax.jms.TextMessage createTextMessage()
           
 javax.jms.TextMessage createTextMessage(java.lang.String text)
           
 boolean isTransacted()
           
 void rollback()
          Rollback all messages done in the current transaction and release any locks currently held.
protected  void setConnection(javax.jms.Connection conn)
           
protected  void setSession(javax.jms.Session session)
           
 void writeAndClose(javax.jms.Message message, java.util.Map writeOptions)
           
 void writeAndCommit(javax.jms.Message message, java.util.Map writeOptions)
          Write a message, and then immediately commit the session.
 void writeAndCommitAndClose(javax.jms.Message message, java.util.Map writeOptions)
          Write a message, commit the session, and close the connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.waveset.util.jms.JmsWriter
write
 

Field Detail

_connection

protected javax.jms.Connection _connection

_session

protected javax.jms.Session _session
Constructor Detail

JmsWriterBase

protected JmsWriterBase()
Method Detail

createTextMessage

public javax.jms.TextMessage createTextMessage()
                                        throws javax.jms.JMSException
Specified by:
createTextMessage in interface JmsWriter
Returns:
an un-initialized TextMessage. A TextMessage is used to send a message containing a String.
Throws:
javax.jms.JMSException - if JMS fails to create this message due to some internal error

createTextMessage

public javax.jms.TextMessage createTextMessage(java.lang.String text)
                                        throws javax.jms.JMSException
Specified by:
createTextMessage in interface JmsWriter
Parameters:
text - the string used to initialize this message
Returns:
an initialized TextMessage. A TextMessage is used to send a message containing a String.
Throws:
javax.jms.JMSException - if JMS fails to create this message due to some internal error.

createMapMessage

public javax.jms.MapMessage createMapMessage()
                                      throws javax.jms.JMSException
Specified by:
createMapMessage in interface JmsWriter
Returns:
a MapMessage. A MapMessage is used to send a self-defining set of name-value pairs where names are Strings and values are Java primitive types.
Throws:
javax.jms.JMSException - if JMS fails to create this message due to some internal error.

createStreamMessage

public javax.jms.StreamMessage createStreamMessage()
                                            throws javax.jms.JMSException
Specified by:
createStreamMessage in interface JmsWriter
Returns:
a StreamMessage. A StreamMessage is used to send a self-defining stream of Java primitives.
Throws:
javax.jms.JMSException - if JMS fails to create this message due to some internal error.

createObjectMessage

public javax.jms.ObjectMessage createObjectMessage()
                                            throws javax.jms.JMSException
Specified by:
createObjectMessage in interface JmsWriter
Returns:
an initialized ObjectMessage. An ObjectMessage is used to send a message that containing a serializable Java object.
Throws:
javax.jms.JMSException - if JMS fails to create this message due to some internal error.

createBytesMessage

public javax.jms.BytesMessage createBytesMessage()
                                          throws javax.jms.JMSException
Specified by:
createBytesMessage in interface JmsWriter
Returns:
a BytesMessage. A BytesMessage is used to send a message containing a stream of uninterpreted bytes.
Throws:
javax.jms.JMSException - if JMS fails to create this message due to some internal error.

close

public void close()
Description copied from interface: JmsWriter
Inform the system that no more messaging will occur on this object. All resources will be freed.

Any transacted session will be rolled back.

Do not attempt to use this object again after calling close().

Specified by:
close in interface JmsWriter

writeAndCommit

public void writeAndCommit(javax.jms.Message message,
                           java.util.Map writeOptions)
                    throws WavesetException,
                           javax.jms.JMSException
Description copied from interface: JmsWriter
Write a message, and then immediately commit the session.

NOTE: The commit will be performed only if the session is transacted.

Specified by:
writeAndCommit in interface JmsWriter
Parameters:
message - the message to be sent
writeOptions - same as described in write
Throws:
WavesetException - if illegal values are found in writeOptions map
javax.jms.JMSException - if JMS fails to send the message or to commit the transaction due to some internal error.

writeAndCommitAndClose

public void writeAndCommitAndClose(javax.jms.Message message,
                                   java.util.Map writeOptions)
                            throws WavesetException,
                                   javax.jms.JMSException
Description copied from interface: JmsWriter
Write a message, commit the session, and close the connection.

This is the most succinct way to send a message, however it does not offer you the opportunity to send multiple messages over a single connection.

NOTE: The commit will be performed only if the session is transacted.

Specified by:
writeAndCommitAndClose in interface JmsWriter
Parameters:
message - the message to be sent
writeOptions - same as described in write
Throws:
javax.jms.JMSException - if JMS fails to send the message or to commit the transaction due to some internal error.
WavesetException - if illegal values are found in writeOptions map

writeAndClose

public void writeAndClose(javax.jms.Message message,
                          java.util.Map writeOptions)
                   throws javax.jms.JMSException,
                          WavesetException
Throws:
javax.jms.JMSException
WavesetException

commit

public void commit()
            throws javax.jms.JMSException
Description copied from interface: JmsWriter
Commit all messages done in the current transaction and release any locks currently held. The commit will be performed only if the session is transacted.

Specified by:
commit in interface JmsWriter
Throws:
javax.jms.JMSException - if JMS fails to commit the session due to some internal error.

rollback

public void rollback()
              throws javax.jms.JMSException
Description copied from interface: JmsWriter
Rollback all messages done in the current transaction and release any locks currently held. The rollback will be performed only if the session is transacted.

Specified by:
rollback in interface JmsWriter
Throws:
javax.jms.JMSException - if JMS fails to rollback the session due to some internal error.

isTransacted

public boolean isTransacted()
                     throws javax.jms.JMSException
Specified by:
isTransacted in interface JmsWriter
Returns:
true if the encapsulated javax.jms.Session is in transacted mode; otherwise return false.

If this was created with "LOCAL" reliabilityMode, then it is transacted.

Throws:
javax.jms.JMSException - if JMS fails to return the transaction mode due to internal error in JMS Provider.

setConnection

protected void setConnection(javax.jms.Connection conn)

setSession

protected void setSession(javax.jms.Session session)