JMS Conector demo (OC4J 10g R3)

Class MyChannel

java.lang.Object
  extended byMyChannel

class MyChannel
extends java.lang.Object

Example of using JMS 1.1 unified operations.


Field Summary
private  Connection connection
           
private  MessageConsumer consumer
           
private  MessageProducer producer
           
private  Session session
           
 
Constructor Summary
MyChannel(java.lang.String connectionFactoryName, java.lang.String destinationName)
          MyChannel constructor.
 
Method Summary
 void close()
          Close channel.
 java.io.Serializable receive()
          Receive message (wait forever).
 java.io.Serializable receive(long timeout)
          Receive message (wait a while).
 void send(java.io.Serializable obj)
          Send message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

private Connection connection

session

private Session session

producer

private MessageProducer producer

consumer

private MessageConsumer consumer
Constructor Detail

MyChannel

public MyChannel(java.lang.String connectionFactoryName,
                 java.lang.String destinationName)
          throws java.lang.Exception
MyChannel constructor.

The constructor uses the named connection factory to open a "channel" attached to the named destination. Note that JMS 1.1 features mean that this class will work correctly even if a TopicConnectionFactory is used with a Queue destination (or a QueueConnectionFactory is used with a Topic destination). And, of course, a generic ConnectionFactory will also work with both queues and topics.

Parameters:
connectionFactoryName - the logical name (<res-ref-name>) or JNDI location of a JMS connection factory.
destinationName - the logical name (<message-destination-ref-name>) or JNDI location of a JMS destination
Throws:
JMSSecurityException - if client authentication fails due to an invalid user name or password
NamingException - if there is a problem looking up the connection factory or destination
InvalidDestinationException - if the object at destinationName is not a valid destination
JMSException - if non-transacted auto-acknowledge sessions are not supported, or on a JMS internal error
java.lang.Exception
Method Detail

send

public void send(java.io.Serializable obj)
          throws JMSException
Send message.

prerequisite: channel is open

Parameters:
obj - object to be sent
Throws:
JMSException

receive

public java.io.Serializable receive()
                             throws JMSException
Receive message (wait forever).

prerequisite: channel is open

Returns:
object which was received in message, or null if no message was received
Throws:
JMSException

receive

public java.io.Serializable receive(long timeout)
                             throws JMSException
Receive message (wait a while).

prerequisite: channel is open

Parameters:
timeout - maximum time (in milliseconds) to wait for a message to arrive
Returns:
object which was received in message, or null if no message was received
Throws:
JMSException

close

public void close()
           throws JMSException
Close channel.

prerequisite: channel is open

Once a MyChannel object is closed, it may no longer be used to send or receive messages.

Throws:
JMSException

JMS Conector demo (OC4J 10g R3)

Copyright © 2006, Oracle. All rights reserved.