Oracle9i Supplied Java Packages Reference Release 2 (9.2) Part Number A96609-01 |
|
This chapter describes the Oracle Java interfaces and classes contained in package oracle.AQ. These are based on current PL/SQL interfaces for Oracle Advanced Queuing (AQ).
This chapter contains these sections:
The Java AQ API supports both the administrative and operational features of Oracle Advanced Queueing. In developing Java programs for messaging applications, you use JDBC to open a connection to the database and then the interfaces in oracle.AQ, which contains the Java AQ API for message queuing. You need not use only PL/SQL interfaces.
Note: If the Java classes are not-preloaded, you can load them by connecting as SYS and loading the $ORACLE_HOME/rdbms/admin/initjms.sql script. |
The Java AQ classes are located in $ORACLE_HOME/rdbms/jlib/aqapi.jar
. In Oracle9i Release 2 (9.2), rdbms/jlib/*.jar
conforms to the JMS 1.0.2b standard published by Sun Microsystems. These classes can be used with any Oracle8i or Oracle9i JDBC driver.
For JDK 1.3 you must include the following classes in the CLASSPATH:
$ORACLE_HOME/rdbms/jlib/aqapi13.jar $ORACLE_HOME/lib/jndi.jar $ORACLE_HOME/jdbc/lib/classes12.zip
For JDK 1.2 you must include the following classes in the CLASSPATH:
$ORACLE_HOME/rdbms/jlib/aqapi12.jar $ORACLE_HOME/lib/jndi.jar $ORACLE_HOME/jdbc/lib/classes12.zip
For JDK 1.1 you must include the following classes in the CLASSPATH:
$ORACLE_HOME/rdbms/jlib/aqapi11.jar $ORACLE_HOME/lib/jndi.jar $ORACLE_HOME/jdbc/lib/classes111.zip
Oracle9i Application Developer's Guide - Advanced Queuing, Appendix A contains more examples in addition to those contained in this chapter.
aqjava
An aqjava
user is set up as follows:
CONNECT sys/change_on_install AS sysdba DROP USER aqjava CASCADE; GRANT CONNECT, RESOURCE, AQ_ADMINISTRATOR_ROLE TO aqjava
IDENTIFIED BY aqjava; GRANT EXECUTE ON SYS.DBMS_AQADM TO aqjava; GRANT EXECUTE ON SYS.DBMS_AQ TO aqjava; GRANT EXECUTE ON SYS.DBMS_AQIN TO aqjava; CONNECT aqjava/aqjava
Next, set up the main class from which you will call subsequent examples and handle exceptions. The main class for the examples is named test_aqjava
.
import java.sql.*; import oracle.AQ.*; public class test_aqjava { public static void main(String args[]) { AQSession aq_sess = null; try { aq_sess = createSession(args); /* now run the test: */ runTest(aq_sess); } catch (Exception ex) { System.out.println("Exception-1: " + ex); ex.printStackTrace(); } } }
Next, create an AQ Session for the aqjava
user as shown in the previous step for AQDriverManager:
public static AQSession createSession(String args[]) { Connection db_conn; AQSession aq_sess = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); /* your actual hostname, port number, and SID will vary from what follows. Here we use 'dlsun736,' '5521,' and 'test,' respectively: */ db_conn = DriverManager.getConnection( "jdbc:oracle:thin:@dlsun736:5521:test", "aqjava", "aqjava"); System.out.println("JDBC Connection opened "); db_conn.setAutoCommit(false); /* Load the Oracle9i AQ driver: */ Class.forName("oracle.AQ.AQOracleDriver"); /* Create an AQ Session: */ aq_sess = AQDriverManager.createAQSession(db_conn); System.out.println("Successfully created AQSession "); } catch (Exception ex) { System.out.println("Exception: " + ex); ex.printStackTrace(); } return aq_sess; }
The various implementations of the Java AQ API are managed through a driver manager interface named AQDriverManager
. Both Oracle Lite and Oracle9i have an AQDriver
that is registered with the AQDriverManager
. The driver manager is used to create an AQSession
that can be used to perform messaging tasks.
When the AQDriverManager
.createAQSession
() method is invoked, it calls the appropriate AQDriver
(amongst the registered drivers) depending on the parameter passed to the createAQSession
() call.
The Oracle9i AQDriver
expects a valid JDBC connection to be passed in as a parameter to create an AQSession. Users must have the execute privilege on the DBMS_AQIN
package in order to use the AQ Java interfaces. Users can also acquire these rights through the AQ_USER_ROLE
or the AQ_ADMINSTRATOR_ROLE
. Users will also need the appropriate system and queue privileges for Oracle9i-style queue tables.
public static java.util.Vector getDrivers()
This method Returnsthe list of drivers registered with the driver manager. It Returnsa Vector of strings containing the names of the registered drivers.
public static AQSession getAQSession (java.lang.Object conn) throws AQException
This method creates an AQSession.
conn
If the user is using the AQOracleDriver
, then the object passed in must be a valid JDBC connection.
Currently Java AQ objects are not thread safe. Therefore, methods on AQSession
, AQQueueTable
, AQQueue
and other AQ objects should not be called concurrently from different threads. You can pass these objects between threads, but the program must ensure that the methods on these AQ objects are not invoked concurrently.
We recommend that multithreaded programs create a different AQSession
in each thread (using the same or a different JDBC connection) and get new queue table and queue handles using the getQueueTable
and getQueue
methods in AQSession
.
To create an AQSession
, you must first open a JDBC connection. Then you must load the AQDriver
that you need to use in the application. With Oracle9i, the driver is loaded using the Class.forName("oracle.AQ.AQOracleDriver")
command.
Note that the driver needs to be loaded only once (before the first createAQSession
call). Loading the driver multiple times will have no effect. For more information, see "Setup for oracle.AQ Examples".
Connection db_conn; /* JDBC connection */ AQSession aq_sess; /* AQSession */ /* JDBC setup and connection creation: */ Class.forName("oracle.jdbc.driver.OracleDriver"); db_conn = DriverManager.getConnection ( "jdbc:oracle:oci8:@", "aquser", "aquser"); db_conn.setAutoCommit(false); /* Load the Oracle9i AQ driver: */ Class.forName("oracle.AQ.AQOracleDriver"); /* Create an AQ Session: */ aq_sess = AQDriverManager.createAQSession(db_conn);
In general, use only the interfaces and classes that are common to both implementations. This will ensure that your applications are portable between Oracle9i and Oracle Lite AQ implementations.
Additionally, oracle.AQ classes should only be used when you need a method that is not available in the common interfaces. Note that since the AQQueue
interface extends AQQueueAdmin
, all queue administrative and operational functionality is available via AQQueue
.
public AQQueueTable createQueueTable(java.lang.String owner, java.lang.String name, AQQueueTableProperty property) throws AQException
This method creates a new queue table in a particular user's schema according to the properties specified in the AQQueueTableProperty
object passed in.
Parameter | Description |
---|---|
|
schema (user) in which to create the queue table |
|
name of the queue table |
|
queue table properties |
AQQueueTable
object
public AQQueueTable getQueueTable(java.lang.String owner, java.lang.String name)
This method is used to get a handle to an existing queue table.
Parameter | Description |
---|---|
|
schema (user) in which the queue table resides |
|
name of the queue table |
AQQueueTable
object
public AQQueue createQueue(AQQueueTable q_table, java.lang.String q_name, AQQueueProperty q_property) throws AQException
This method creates a queue in a queue_table with the specified queue properties. It uses the same schema name that was used to create the queue table.
Parameter | Description |
---|---|
|
queue table in which to create queue |
|
name of the queue to be created |
|
queue properties |
AQQueue
object
public AQQueue getQueue(java.lang.String owner, java.lang.String name)
This method can be used to get a handle to an existing queue.
Parameter | Description |
---|---|
|
schema (user) in which the queue table resides |
|
name of the queue |
AQQueue
object
public java.sql.Connection getDBConnection()
This method can be used to get the underlying JDBC connection from an AQ session object
This method is available only in the Oracle server implementation of AQSession. Hence the AQSession object must be cast to AQOracleSession before calling this method.
AQSession aq_sess; Connection db_conn =((AQOracleSession)aq_sess).getDBConnection();
public AQAgent listen(AQAgent[] agent_list, int wait_time)
This method can be used to listen to multiple queues for messages
Agent with a message available for consumption
AQException if listen failed due to time-out (ORA-25254) or another error
1. Create a queue table and a queue
With the runTest
class, called from the AQDriverManager main class, create a queue table and queue for the aqjava
user.
public static void runTest(AQSession aq_sess) throws AQException { AQQueueTableProperty qtable_prop; AQQueueProperty queue_prop; AQQueueTable q_table; AQQueue queue; /* Create a AQQueueTableProperty object (payload type - RAW): */ qtable_prop = new AQQueueTableProperty("RAW"); /* Create a queue table called aq_table1 in aqjava schema: */ q_table = aq_sess.createQueueTable ("aqjava", "aq_table1", qtable_prop); System.out.println("Successfully created aq_table1 in aqjava schema"); /* Create a new AQQueueProperty object: */ queue_prop = new AQQueueProperty(); /* Create a queue called aq_queue1 in aq_table1: */ queue = aq_sess.createQueue (q_table, "aq_queue1", queue_prop); System.out.println("Successfully created aq_queue1 in aq_table1"); }
2. Get a handle to an existing queue table and queue
public static void runTest(AQSession aq_sess) throws AQException { AQQueueTable q_table; AQQueue queue; /* Get a handle to queue table - aq_table1 in aqjava schema: */ q_table = aq_sess.getQueueTable ("aqjava", "aq_table1"); System.out.println("Successful getQueueTable"); /* Get a handle to a queue - aq_queue1 in aqjava schema: */ queue = aq_sess.getQueue ("aqjava", "aq_queue1"); System.out.println("Successful getQueue"); }
This class contains some constants used in the java AQ API.
VISIBILITY_IMMEDIATE public static final int VISIBILITY_IMMEDIATE VISIBILITY_ONCOMMIT public static final int VISIBILITY_ONCOMMIT
RAW_TYPE_PAYLOAD public static final int RAW_TYPE_PAYLOAD
OBJECT_TYPE_PAYLOAD public static final int OBJECT_TYPE_PAYLOAD
This object specifies the producer or a consumer of a message.
public AQAgent(java.lang.String name, java.lang.String address, double protocol) public AQAgent(java.lang.String name, java.lang.String address)
There are two implementations of the constructor, each of which allocates a new AQAgent
with the specified parameters.
Parameter | Description |
---|---|
|
agent name |
|
agent address |
|
agent protocol (required only in the first constructor); default is 0 |
public java.lang.String getName() throws AQException
This method gets the agent name.
public void setName(java.lang.String name) throws AQException
This method sets the agent name.
Parameter | Description |
---|---|
|
Agent name |
public java.lang.String getAddress() throws AQException
This method gets the agent address.
public void setAddress(java.lang.String address) throws AQException
This method sets the agent address.
Parameter | Description |
---|---|
|
queue at a specific destination |
public int getProtocol() throws AQException
This method gets the agent protocol.
public void setProtocol(int protocol) throws AQException
This method sets the agent protocol.
Parameter | Description |
---|---|
|
Agent protocol |
This class represents queue table properties.
public static final int NONE public static final int TRANSACTIONAL
public AQQueueTableProperty(java.lang.String p_type)
This method creates an AQQueueTableProperty
object with default property values and the specified payload type.
Parameter | Description |
---|---|
|
payload type: this is " |
public java.lang.String getPayloadType() throws AQException
This method Returns"RAW
" for raw payloads or the object type for object payloads.
public void setPayloadType(java.lang.String p_type) throws AQException
This method is used to set the payload type.
Parameter | Description |
---|---|
|
payload type: this is "RAW" for queue tables that will contain raw payloads or the object (ADT) type for queue tables that will contain structured payloads |
public void setStorageClause(java.lang.String s_clause) throws AQException
This method is used to set the storage clause to be used to create the queue table.
Parameter | Description |
---|---|
|
storage parameter: this clause is used in the ` |
public java.lang.String getSortOrder() throws AQException
This method gets the sort order that is used.
The sort order used
public void setSortOrder(java.lang.String s_order) throws AQException
This method sets the sort order to be used.
public boolean isMulticonsumerEnabled() throws AQException
This method queries whether the queues created in the table can have multiple consumers per message or not.
TRUE
if the queues created in the table can have multiple consumers per message.
FALSE
if the queues created in the table can have only one consumer per message.
public void setMultiConsumer(boolean enable) throws AQException
This method determines whether the queues created in the table can have multiple consumers per message or not.
Parameter | Description |
---|---|
|
|
public int getMessageGrouping() throws AQException
This method is used to get the message grouping behavior for the queues in this queue table.
NONE
: each message is treated individually
TRANSACTIONAL
: all messages enqueued as part of one transaction are considered part of the same group and can be dequeued as a group of related messages.
public void setMessageGrouping(int m_grouping) throws AQException
This method is used to set the message grouping behavior for queues created in this queue table.
Parameter | Description |
---|---|
|
|
public java.lang.String getComment() throws AQException
This method gets the queue table comment.
public void setComment(java.lang.String qt_comment) throws AQException
This method sets a comment.
Parameter | Description |
---|---|
|
comment |
public java.lang.String getCompatible() throws AQException
This method gets the compatible property.
public void setCompatible(java.lang.String qt_compatible) throws AQException
This method sets the compatible property.
Parameter | Description |
---|---|
|
compatible property |
public int getPrimaryInstance() throws AQException
This method gets the primary instance.
public void setPrimaryInstance(int inst) throws AQException
This method sets the primary instance.
Parameter | Description |
---|---|
|
primary instance |
public int getSecondaryInstance() throws AQException
This method gets the secondary instance.
public void setSecondaryInstance(int inst) throws AQException
This method sets the secondary instance.
Parameter | Description |
---|---|
|
secondary instance |
To run this example, first set up the test_aqjava
class as described in "Setup for oracle.AQ Examples".
1. Create a queue table property object with raw payload type
public static void runTest(AQSession aq_sess) throws AQException { AQQueueTableProperty qtable_prop; /* Create AQQueueTable Property object: */ qtable_prop = new AQQueueTableProperty("RAW"); qtable_prop.setSortOrder("PRIORITY"); }
2. Create a queue table property object with raw payload type (for 8.1 style queues)
public static void runTest(AQSession aq_sess) throws AQException { AQQueueTableProperty qtable_prop; /* Create AQQueueTable Property object: */ qtable_prop = new AQQueueTableProperty("RAW"); qtable_prop.setComment("Qtable with raw payload"); qtable_prop.setCompatible("8.1"); }
3. Create a queue table property object with "PERSON" payload type (ADT type):
public static void runTest(AQSession aq_sess) throws AQException { AQQueueTableProperty qtable_prop; qtable_prop = new AQQueueTableProperty("PERSON"); qtable_prop.setComment("Qtable with Person ADT payload"); qtable_prop.setMessageGrouping(TRANSACTIONAL); }
This class represents queue properties.
public static final int NORMAL_QUEUE public static final int EXCEPTION_QUEUE public static final int INFINITE /* infinite retention */
public AQQueueProperty()
This method creates a new AQQueueProperty
object with default property values.
public int getQueueType() throws AQException
This method gets the queue type.
NORMAL_QUEUE
or EXCEPTION_QUEUE
public void setQueueType(int q_type) throws AQException
This method is used to set the queue type.
Parameter | Description |
---|---|
|
|
public int getMaxRetries() throws AQException
This method gets the maximum retries for dequeue with REMOVE
mode.
public void setMaxRetries(int retries) throws AQException public void setMaxRetries(Integer retries) throws AQException
This method sets the maximum retries for dequeue with REMOVE
mode.
public void setRetryInterval(double interval) throws AQException public void setRetryInterval(Double interval) throws AQException
This method sets the retry interval, that is the time before this message is scheduled for processing after an application rollback. Default is 0.
Parameter | Description |
---|---|
|
retry interval; specifying |
public double getRetryInterval() throws AQException
This method gets the retry interval.
public double getRetentionTime() throws AQException
This method gets the retention time.
public void setRetentionTime(double r_time) throws AQException public void setRetentionTime(Double r_time) throws AQException
This method gets the retention time.
Parameter | |
---|---|
|
retention time; specifying |
public java.lang.String getComment() throws AQException
This method gets the queue comment.
public void setComment(java.lang.String qt_comment) throws AQException
This method sets the queue comment.
Parameter | Description |
---|---|
qt_comment |
queue comment |
To use this example, first set up the test_aqjava
class as described in the Setup for oracle.AQ Examples section on .
{ AQQueueProperty q_prop; q_prop = new AQQueueProperty(); q_prop.setRetentionTime(15); /* set retention time */ q_prop.setRetryInterval(30); /* set retry interval */ }
The AQQueueTable interface contains methods for queue table administration.
public java.lang.String getOwner() throws AQException
This method gets the queue table owner.
public java.lang.String getName() throws AQException
This method gets the queue table name.
public AQQueueTableProperty getProperty() throws AQException
This method gets the queue table properties.
AQQueueTableProperty
object
public void drop(boolean force) throws AQException
This method drops the current queue table.
Parameter | Description |
---|---|
force |
|
public void alter(java.lang.String comment, int primary_instance, int secondary_instance) throws AQException public void alter(java.lang.String comment) throws AQException
This method is used to alter queue table properties.
Parameter | Description |
---|---|
|
new comment |
|
new value for primary instance |
|
new value for secondary instance |
public AQQueue createQueue(java.lang.String queue_name, AQQueueProperty q_property) throws AQException
This method is used to create a queue in this queue table.
Parameter | Description |
---|---|
|
name of the queue to be created |
|
queue properties |
AQQueue
object
public void dropQueue(java.lang.String queue_name) throws AQException
This method is used to drop a queue in this queue table.
Parameter | Description |
---|---|
queue_name |
name of the queue to be dropped |
To run this example, first set up the test_aqjava
class as described in the "Setup for oracle.AQ Examples" section .
public static void runTest(AQSession aq_sess) throws AQException { AQQueueTableProperty qtable_prop; AQQueueProperty queue_prop; AQQueueTable q_table; AQQueue queue; /* Create a AQQueueTable property object (payload type - RAW): */ qtable_prop = new AQQueueTableProperty("RAW"); /* Create a queue table called aq_table2 in aquser schema: */ qtable = aq_sess.createQueueTable ("aquser", "aq_table2", qtable_prop); System.out.println("Successfully createQueueTable"); /* Create a new AQQueueProperty object: */ queue_prop = new AQQueueProperty(); /* Create a queue called aq_queue2 in aq_table2: */ queue = qtable.createQueue ("aq_queue2", queue_prop); System.out.println("Successful createQueue"); }
{ AQQueueTableProperty qtable_prop; AQQueueTable q_table; /*Get a handle to the queue table called aq_table2 in aquser schema: */ q_table = aq_sess.getQueueTable ("aqjava", "aq_table2"); System.out.println("Successful getQueueTable"); /* Get queue table properties: */ qtable_prop = q_table.getProperty(); /* Alter the queue table: */ q_table.alter("altered queue table"); /* Drop the queue table (and automatically drop queues inside it): */ q_table.drop(true); System.out.println("Successful drop"); }
public void start(boolean enqueue, boolean dequeue) throws AQException
This method is used to enable enqueue and dequeue on this queue.
Parameter | Description |
---|---|
|
|
|
|
public void startEnqueue() throws AQException
This method is used to enable enqueue on this queue. This is equivalent to start(TRUE,
FALSE)
public void startEnqueue() throws AQException
This method is used to enable dequeue on this queue. This is equivalent to start(FALSE,
TRUE
).
public void stop(boolean enqueue, boolean dequeue, boolean wait) throws AQException
This method is used to disable enqueue/dequeue on this queue.
public void stopEnqueue(boolean wait) throws AQException
This method is used to disable enqueue on a queue. This is equivalent to stop(TRUE,
FALSE,
wait)
.
Parameter | Description |
---|---|
|
|
public void stopDequeue(boolean wait) throws AQException
This method is used to disable dequeue on a queue. This is equivalent to stop(FALSE,
TRUE,
wait)
.
Parameter | Description |
---|---|
|
|
public void drop() throws AQException
This method is used to drop a queue
public void alterQueue(AQQueueProperty property) throws AQException
This method is used to alter queue properties
Parameter | Description |
---|---|
|
|
public void addSubscriber(AQAgent subscriber, java.lang.String rule) throws AQException
This method is used to add a subscriber for this queue.
Parameter | Description |
---|---|
|
the |
|
a conditional expression based on message properties, and the message data properties |
public void removeSubscriber(AQAgent subscriber) throws AQException
This method removes a subscriber from a queue.
Parameter | Description |
---|---|
|
the |
public void alterSubscriber(AQAgent subscriber, java.lang.String rule) throws AQException
This method alters properties for a subscriber to a queue.
Parameter | Description |
---|---|
|
the |
|
a conditional expression based on message properties, the message data properties |
public void grantQueuePrivilege(java.lang.String privilege, java.lang.String grantee, boolean grant_option) throws AQException public void grantQueuePrivilege(java.lang.String privilege, java.lang.String grantee) throws AQException
This method is used to grant queue privileges to users and roles. The method has been overloaded. The second implementation is equivalent to calling the first implementation with grant_option
=
FALSE
.
public void revokeQueuePrivilege(java.lang.String privilege, java.lang.String grantee) throws AQException
This method is used to revoke a queue privilege.
Parameter | Description |
---|---|
|
specifies the privilege to be revoked |
|
specifies the grantee(s); the grantee(s) can be a user, a role or the |
public void schedulePropagation(java.lang.String destination, java.util.Date start_time, java.lang.Double duration, java.lang.String next_time, java.lang.Double latency) throws AQException
This method is used to schedule propagation from a queue to a destination identified by a database link.
public void unschedulePropagation(java.lang.String destination) throws AQException
This method is used to unschedule a previously scheduled propagation of messages from the current queue to a destination identified by a specific database link.
Parameter | Description |
---|---|
destination |
specifies the destination database link. |
public void alterPropagationSchedule(java.lang.String destination, java.lang.Double duration, java.lang.String next_time, java.lang.Double latency) throws AQException
This method is used to alter a propagation schedule.
public void enablePropagationSchedule(java.lang.String destination) throws AQException
This method is used to enable a propagation schedule.
Parameter | Description |
---|---|
destination |
specifies the destination database link. |
public void disablePropagationSchedule(java.lang.String destination) throws AQException
This method is used to disable a propagation schedule.
Parameter | Description |
---|---|
destination |
specifies the destination database link. |
Set up the test_aqjava class. For more information, see "Setup for oracle.AQ Examples"
{ AQQueueTableProperty qtable_prop; AQQueueProperty queue_prop; AQQueueTable q_table; AQQueue queue; /* Create a AQQueueTable property object (payload type - RAW): */ qtable_prop = new AQQueueTableProperty("RAW"); qtable_prop.setCompatible("8.1"); /* Create a queue table called aq_table3 in aqjava schema: */ q_table = aq_sess.createQueueTable ("aqjava","aq_table3", qtable_prop); System.out.println("Successful createQueueTable"); /* Create a new AQQueueProperty object: */ queue_prop = new AQQueueProperty(); /* Create a queue called aq_queue3 in aq_table3: */ queue = aq_sess.createQueue (q_table, "aq_queue3", queue_prop); System.out.println("Successful createQueue"); /* Enable enqueue/dequeue on this queue: */ queue.start(); System.out.println("Successful start queue"); /* Grant enqueue_any privilege on this queue to user scott: */ queue.grantQueuePrivilege("ENQUEUE", "scott"); System.out.println("Successful grantQueuePrivilege"); }
public static void runTest(AQSession aq_sess) throws AQException { AQQueueTableProperty qtable_prop; AQQueueProperty queue_prop; AQQueueTable q_table; AQQueue queue; AQAgent subs1, subs2; /* Create a AQQueueTable property object (payload type - RAW): */ qtable_prop = new AQQueueTableProperty("RAW"); System.out.println("Successful setCompatible"); /* Set multiconsumer flag to true: */ qtable_prop.setMultiConsumer(true); /* Create a queue table called aq_table4 in aqjava schema: */ q_table = aq_sess.createQueueTable ("aqjava","aq_table4", qtable_prop); System.out.println("Successful createQueueTable"); /* Create a new AQQueueProperty object: */ queue_prop = new AQQueueProperty(); /* Create a queue called aq_queue4 in aq_table4 */ queue = aq_sess.createQueue (q_table, "aq_queue4", queue_prop); System.out.println("Successful createQueue"); /* Enable enqueue/dequeue on this queue: */ queue.start(); System.out.println("Successful start queue"); /* Add subscribers to this queue: */ subs1 = new AQAgent("GREEN", null, 0); subs2 = new AQAgent("BLUE", null, 0); queue.addSubscriber(subs1, null); /* no rule */ System.out.println("Successful addSubscriber 1"); queue.addSubscriber(subs2, "priority < 2"); /* with rule */ System.out.println("Successful addSubscriber 2"); }
This interface supports the operational interfaces of queues. AQQueue
extends AQQueueAdmin
. Hence, you can also use administrative functions through this interface.
public java.lang.String getOwner() throws AQException
This method gets the queue owner.
public java.lang.String getName() throws AQException
This method gets the queue name.
public java.lang.String getQueueTableName() throws AQException
This method gets the name of the queue table in which the queue resides.
public AQQueueProperty getProperty() throws AQException
This method is used to get the queue properties.
AQQueueProperty
object
public AQMessage createMessage() throws AQException
This method is used to create a new AQMessage
object that can be populated with data to be enqueued.
AQMessage
object
public byte[] enqueue(AQEnqueueOption enq_option, AQMessage message) throws AQException
This method is used to enqueue a message in a queue.
Parameter | Description |
---|---|
|
|
|
|
Message id of the enqueued message. The AQMessage object's messageId field is also populated after the completion of this call.
public AQMessage dequeue(AQDequeueOption deq_option) throws AQException
This method is used to dequeue a message from a queue.
Parameter | Description |
---|---|
deq_option |
|
AQMessage
, the dequeued message
public AQMessage dequeue(AQDequeueOption deq_option, java.lang.Class payload_ class) throws AQException
This method is used to dequeue a message from a queue containing Oracle object payloads. This version must be used if your program uses the SQL Data interface for mapping java classes to Oracle object types.
deq_option - AQDequeueOption object
payload_class - the payload dequeued is transformed as an object of this type. The class specified must implement the SQLData interface and correspond to the payload type defined for the queue.
AQMessage, the dequeued message
Users are also required to register all java classes that map to ADTs contained in the queue in the typeMap of the JDBC connection.
For more information on the SQLData interface and registering classes in the type map refer to the JDBC developer's guide.
public AQMessage dequeue(AQDequeueOption deq_option, oracle.sql.CustomDatumFactory payload_fact) throws AQException
This method is used to dequeue a message from a queue containing Oracle object payloads. This version must be used if your program uses the Custom Datum interface for mapping java classes to Oracle object types.
deq_option - AQDequeueOption object
payload_fact - This is the CustomDatum factory for the class that maps to the SQL ADT type of the payload in the queue. For example, if Person is the java class that maps to PERSON ADT in the database, then the CustomDatum factory for this class can be obtained using Person.getFactory()
AQMessage - the dequeued message
For more information on the CustomDatum and CustomDatumFactory interface and registering classes in the type map refer to the JDBC developer's guide.
public AQMessage dequeue(AQDequeueOption deq_option, oracle.sql.ORADataFactory payload_fact) throws AQException
This method is used to dequeue a message from a queue containing Oracle object payloads. This version must be used if your program uses the ORAData interface for mapping java classes to Oracle object types.
deq_option - AQDequeueOption object
payload_fact - This is the ORAData factory for the class that maps to the SQL ADT type of the payload in the queue. For example, if Person is the java class that maps to PERSON ADT in the database, then the ORAData factory for this class can be obtained using Person.getORADataFactory()
AQMessage - the dequeued message
For more information on the ORAData and ORADataFactory interface and registering classes in the type map refer to the JDBC developer's guide.
public AQAgent[] getSubscribers() throws AQException
This method is used to get a subscriber list for the queue.
An array of AQAgents
This class is used to specify options available for the enqueue operation.
public static final int DEVIATION_NONE public static final int DEVIATION_BEFORE public static final int DEVIATION_TOP public static final int VISIBILITY_ONCOMMIT public static final int VISIBILITY_IMMEDIATE
public AQEnqueueOption(int visibility, byte[] relative_msgid, int sequence_deviation) public AQEnqueueOption()
There are two constructors available. The first creates an object with the specified options, the second creates an object with the default options.
public int getVisibility() throws AQException
This method gets the visibility.
VISIBILITY_IMMEDIATE
or VISIBILITY_ONCOMMIT
public void setVisibility(int visibility) throws AQException
This method sets the visibility.
Parameter | Description |
---|---|
|
|
public byte[] getRelMessageId() throws AQException
This method gets the relative message id.
public int getSequenceDeviation() throws AQException
This method gets the sequence deviation.
public void setSequenceDeviation(int sequence_deviation, byte[] relative_msgid) throws AQException
This method specifies whether the message being enqueued should be dequeued before other message(s) already in the queue.
This class is used to specify the options available for the dequeue option.
public static final int NAVIGATION_FIRST_MESSAGE public static final int NAVIGATION_NEXT_TRANSACTION public static final int NAVIGATION_NEXT_MESSAGE public static final int DEQUEUE_BROWSE public static final int DEQUEUE_LOCKED public static final int DEQUEUE_REMOVE public static final int DEQUEUE_REMOVE_NODATA public static final int WAIT_FOREVER public static final int WAIT_NONE public static final int VISIBILITY_ONCOMMIT public static final int VISIBILITY_IMMEDIATE
public AQDequeueOption()
This method creates an object with the default options.
public java.lang.String getConsumerName() throws AQException
This method gets consumer name.
public void setConsumerName(java.lang.String consumer_name) throws AQException
This method sets consumer name
Parameter | Description |
---|---|
consumer_name |
Agent name |
public int getDequeueMode() throws AQException
This method gets dequeue mode.
DEQUEUE_BROWSE
, DEQUEUE_LOCKED
, DEQUEUE_REMOVE
or DEQUEUE_REMOVE_NODATA
public void setDequeueMode(int dequeue_mode) throws AQException
This method sets the dequeue mode.
Parameter | Description |
---|---|
dequeue_mode |
|
public int getNavigationMode() throws AQException
This method gets the navigation mode.
NAVIGATION_FIRST_MESSAGE
or NAVIGATION_NEXT_MESSAGE
or NAVIGATION_NEXT_TRANSACTION
public void setNavigationMode(int navigation) throws AQException
This method sets the navigation mode.
Parameter | Description |
---|---|
navigation |
|
public int getVisibility() throws AQException
This method gets the visibility.
VISIBILITY_IMMEDIATE
or VISIBILITY_ONCOMMIT
public void setVisibility(int visibility) throws AQException
This method sets the visibility.
Parameter | Description |
---|---|
|
|
public int getWaitTime() throws AQException
This method gets the wait time.
WAIT_FOREVER
or WAIT_NONE
or the actual time in seconds
public void setWaitTime(int wait_time) throws AQException
This method sets the wait time.
Parameter | Description |
---|---|
|
|
public byte[] getMessageId() throws AQException
This method gets the message id.
public void setMessageId(byte[] message_id) throws AQException
This method sets the message id.
Parameter | Description |
---|---|
|
message id |
public java.lang.String getCorrelation() throws AQException
This method gets the correlation id.
public void setCorrelation(java.lang.String correlation) throws AQException
This method sets the correlation id.
Parameter | Description |
---|---|
|
user-supplied information |
This interface contains methods for AQ messages with raw or object payloads.
public byte[] getMessageId() throws AQException
This method gets the message id.
public AQRawPayload getRawPayload() throws AQException
This method gets the raw payload
AQRawPayload
object
public void setRawPayload(AQRawPayload message_payload) throws AQException
This method sets the raw payload. It throws AQException
if this is called on messages created from object type queues.
Parameter | Description |
---|---|
message_payload |
|
public AQObjectPayload getObjectPayload() throws AQException
Get the object payload
AQObjectPayload
object
public void setObjectPayload(AQObjectPayload message_payload)
throws AQException
Set the object payload
.
Parameter | Description |
---|---|
message_payload |
AQObjectPayload object containing object user da |
public AQMessageProperty getMessageProperty() throws AQException
This method gets the message properties
AQMessageProperty
object
public void setMessageProperty(AQMessageProperty property) throws AQException
This method sets the message properties.
Parameter | Description |
---|---|
|
AQMessageProperty object |
The AQMessageProperty class contains information that is used by AQ to manage individual messages. The properties are set at enqueue time and their values are returned at dequeue time.
public static final int DELAY_NONE public static final int EXPIRATION_NEVER public static final int STATE_READY public static final int STATE_WAITING public static final int STATE_PROCESSED public static final int STATE_EXPIRED
public AQMessageProperty()
This method creates the AQMessageProperty object with default property values.
public int getPriority() throws AQException
This method gets the message priority.
public void setPriority(int priority) throws AQException
This method sets the message priority.
Parameter | Description |
---|---|
|
priority of the message; this can be any number, including negative number - a smaller number indicates a higher priority |
public int getDelay() throws AQException
This method gets the delay value.
public void setDelay(int delay) throws AQException
This method sets delay value.
Parameter | Description |
---|---|
|
the delay represents the number of seconds after which the message is available for dequeuing; with |
public int getExpiration() throws AQException
This method gets expiration value.
public void setExpiration(int expiration) throws AQException
This method sets expiration value.
Parameter | Description |
---|---|
|
the duration the message is available for dequeuing; this parameter is an offset from the delay; if |
public java.lang.String getCorrelation() throws AQException
This method gets correlation.
public void setCorrelation(java.lang.String correlation) throws AQException
This method sets correlation.
Parameter | Description |
---|---|
|
user-supplied information |
public int getAttempts() throws AQException
This method gets the number of attempts.
public java.util.Vector getRecipientList() throws AQException
This method gets the recipient list.
A vector of AQAgents
.This parameter is not returned to a consumer at dequeue time.
public void setRecipientList(java.util.Vector r_list) throws AQException
This method sets the recipient list.
Parameter | Description |
---|---|
|
vector of |
public byte[] getOrigMessageId() throws AQException
This method gets original message id.
public AQAgent getSender() throws AQException
This method gets the sender of the message.
public void setSender(AQAgent sender) throws AQException
This method sets the sender of the message.
Parameter | Description |
---|---|
sender |
AQAgent |
public java.lang.String getExceptionQueue() throws AQException
This method gets the exception queue name.
public void setExceptionQueue(java.lang.String queue) throws AQException
This method sets the exception queue name.
Parameter | Description |
---|---|
queue |
exception queue name |
public java.util.Date getEnqueueTime() throws AQException
This method gets the enqueue time.
public int getState() throws AQException
This method gets the message state.
STATE_READY
or STATE_WAITING
or STATE_PROCESSED
or STATE_EXPIRED
This object represents the raw user data that is included in AQMessage.
public int getStream(byte[] value, int len) throws AQException
This method reads some portion of the raw payload data into the specified byte array.
Parameter | Description |
---|---|
|
byte array to hold the raw data |
|
number of bytes to be read |
The number of bytes read
public byte[] getBytes() throws AQException
This method retrieves the entire raw payload data as a byte array.
byte - the raw payload as a byte array
public void setStream(byte[] value, int len) throws AQException
This method sets the value of the raw payload.
Parameter | Description |
---|---|
|
byte array containing the raw payload |
|
number of bytes to be written to the raw stream |
This object represents the structured user data (for object queues) that is included in the AQMessage
public void setPayloadData(java.lang.Object obj) throws AQException
This method is used to fill in the payload into the AQObjectPayload object
Please refer to the JDBC developer's guide for more information on SQLData, ORAData and CustomDatum interfaces
public java.lang.Object getPayloadData() throws AQException
This method is used to retrieve the message payload from the AQObjectPayload object
Object payload in message - This will depend on the SQLData class, ORADataFactory or CustomDatum Factory specified during dequeue.
public class AQException extends java.lang.RuntimeException
This exception is raised when the user encounters any error while using the Java AQ API.
This interface supports all methods supported by Java exceptions and some additional methods.
This method gets the error message.
This method gets the error number (Oracle error code).
This method gets the next exception in the chain if any.
AQOracleSQLException
extends AQException
.
When using Oracle9i AQ driver, some errors may be raised from the client side and some from the RDBMS. The Oracle9i driver raises AQOracleSQLException
for all errors that occur while performing SQL.
For sophisticated users interested in differentiating between the two types of exceptions, this interface might be useful. In general you will only use AQException
.
|
Copyright © 1996, 2002 Oracle Corporation. All Rights Reserved. |
|