This is a helper class with reusable methods for other samples or applications, particularly the QueueSample. The sample demonstrates how to get queue information and report on various queue-related objects.
Note The sample code assumes you created a session and supplied a user name and password with appropriate access privileges. The QueueHelper(VWSession, Logger) constructor sets local variables to point to its SessionHelper and Logger objects, which are initialized by the main method. The QueueHelper.main() code is as follows:
public QueueHelper(VWSession vwSession, Logger){
m_vwSession = vwSession;
m_logger = logger;
}
The following sections describe the public QueueHelper class methods.
Displays the contents of a Queue: properties of queue elements, step elements, and work objects. This method retrieves the queue information using methods displayQueueElements(...), displayStepElements(...), and displayWorkObjects(...), which are described below.
Displays the properties of a single queue element with the following steps:
Validate the input VWQueueElement as follows:
if (vwQueueElement == null){
m_logger.log("\t The queue element is null!");
return;}
Set a string array (fieldNames) to the names of the system fields as follows:
fieldNames = vwQueueElement.getSystemDefinedFieldNames();
Validate that there were system fields:
if (fieldNames == null){...}
Log the name and value of each system field:
} else {
m_logger.log("\t\tSystem Defined Fields:");
for (int i = 0; i < fieldNames.length; i++)
{
if (fieldNames[i] != null){
value = vwQueueElement.getFieldValue(fieldNames[i]);
// Display the field name and its value.
m_logger.log("\t\t\t" + fieldNames[i] + "=" + value);
}
}
}
User-defined fields are displayed in the same way that is shown above, but the field names array is set with a different method as follows:
fieldNames = vwQueueElement.getUserDefinedFieldNames();
Properties of the queue element are logged individually. For example, the queue element work object number, the work object name, and the work object tag are logged as follows:
String bvalue = vwQueueElement.getWorkObjectNumber();
m_logger.log("\t\t\t"+ "WorkObjectNumber" + "="
+ bvalue);
String svalue = vwQueueElement.getWorkObjectName();
m_logger.log("\t\t\t"+ "WorkObjectName" + "="
+ svalue);
svalue = vwQueueElement.getTag();
m_logger.log("\t\t\t"+ "Tag" + "=" + svalue);
Other queue element methods are used to get additional property values, and the results are logged (as shown above). This method uses the following queue element methods to obtain property values: getWorkClassName(), getQueueName(), getOperationName(), getLockedStatus(), and getLockedMachine().
Queries the series of all queue elements. displayQueueElements(...) performs the following steps:
The first step to query a series of all queue elements is to create a buffer for the items retrieved in each server fetch transaction with the following code:
// Set the maximum number of items to be retrieved in each
server
// fetch transaction. In this case, setting the value to 25 will require
// less memory for each fetch than the default setting (50).
vwQueue.setBufferSize(25);
Construct a queue query object and query for all elements.
qQuery = vwQueue.createQuery(null, null, null, 0, null, null, VWFetchType.FETCH_TYPE_QUEUE_ELEMENT);
Fetch the first queue element using the VWQueueQuery object. Determine is any queue elements exist.
vwQueueElement = (VWQueueElement)qQuery.next();
if (vwQueueElement == null){
m_logger.log("\t Queue elements: none");
If there are queue elements, the method uses local method displayQueueElementInfo() to display the queue element information as follows:
} else {
do {
// display the queue element information
displayQueueElementInfo(vwQueueElement);
}
Assign a new queue element with the next() method and continue the loop, if there is another element:
while ((vwQueueElement = (VWQueueElement)qQuery.next()) != null);
}
displayQueueLockStatus() (below) performs a similar query of all queue elements, but it differs by controlling the loop with the qQuery.next() method.
Displays lock status information for all workflow queue elements. The method logs queue names with the processing steps described below.
Put the queue names into string array queueNames, using QueueHelper.getQueueNames(...) and QueueHelper.getQueue(...) (described separately below), as follows:
queueNames = getQueueNames(false);
if (queueNames != null){
m_logger.log("Found " + queueNames.length + " queues (NOT including system queues):");
Display each queue name as follows:
for (int i = 0; i < queueNames.length; i++){
// Get the queue object
vwQueue = getQueue(queueNames[i]);
// Display queue name
m_logger.log("\nQueue: " + vwQueue.toString());
// Note that the queue name could also be displayed
with:
// m_logger.log("\nQueue: " + queueNames[i]);
For each queue, set the maximum number of items to be retrieved in each server fetch (query) transaction. In this case, setting the value to 25 will require less memory for each fetch than the default setting (50).
vwQueue.setBufferSize(25);
Construct a queue query object and query for all locked elements. Note that the input flag limits the returned object list to locked objects only. The query flag is read and lock, the filter expression is "F_Locked = 1", and the fetch type is the Queue Element.
qQuery = vwQueue.createQuery(null, null, null, 1, "F_Locked = 1", null, 3);
Note that this is equivalent to:
qQuery = vwQueue.createQuery(null, null, null, QUERY_READ_LOCKED, "F_Locked = 1", null, FETCH_TYPE_QUEUE_ELEMENT);
Query a series of queue elements for work object number with the VWQueueQuery.next(), VWQueueQuery.hasnext(), queueElement.getWorkObjectNumber(), and VWQueueElement.getLockedUser() methods and log the result:
if (qQuery.hasNext()){
// Display column headers for list of locked workobjects.
m_logger.log("\t WorkObject Number\t\t\tLocked User");
do {
// Fetch the next queue element using the VWQueueQuery object.
queueElement = (VWQueueElement)qQuery.next();
// Display the workobject number of each locked workobject.
m_logger.log("\t " + queueElement.getWorkObjectNumber() + "\t" + queueElement.getLockedUser());
}while (qQuery.hasNext());
} . . .
}
}
Logs all queue names with the following steps:
Get a string array of queue names:
queueNames = getQueueNames(true);
Invoke the logger.log method to log each one:
for (int i = 0; i < queueNames.length; i++){
m_logger.log("\t\t" + queueNames[i]);
}
These methods display property information for a group of queue, step, or work elements (work objects). The processing steps these methods are similar to each other. All the methods begin by setting up an iterative query of the element group as follows:
Validate the VWQueue object:
if (vwQueue == null){
m_logger.log("The queue object is null!");
return;
}
Set the maximum number of items to be retrieved in each server fetch transaction. Setting the value to 25 will require less memory for each fetch than the default setting (50).
vwQueue.setBufferSize(25);
Construct a query object for the type of object group being processed. The query object is instantiated in accordance appropriately with the last input parameter (fetchType) of the VWQueue.createQuery method as shown below:
for step elements
qQuery = vwQueue.createQuery(null, null, null, 0, null, null, VWFetchType.FETCH_TYPE_STEP_ELEMENT);
for work elements
qQuery = vwQueue.createQuery(null, null, null, 0, null, null, VWFetchType.FETCH_TYPE_WORKOBJECT);
for queue elements
qQuery = vwQueue.createQuery(null, null, null, 0, null, null, VWFetchType.FETCH_TYPE_QUEUE_ELEMENT);
Fetch the first element using the VWQueueQuery object:
vwElement = (VWStepElement)qQuery.next();
Check to see if there are any queue elements:
if (vwElement == null){
m_logger.log("\t Number of elements: none");
}
else
{
Iteratively examine each element and display appropriate properties for the element type:
do {
// Display
the queue element information with one of the following:
// displayQueueElementInfo(vwElement);
// for queue elements, or:
// displayStepElementInfo(vwElement);
// for step elements, or:
//displayWorkObjectInfo(vwElement);
// for work objects
}
// Advance to the next element with one of the following
while loop footers:
// while ((vwQueueElement = (VWQueueElement)qQuery.next()) != null); //
or
// while ((vwQueueElement = (VWStepElement)qQuery.next()) != null); //
or
// while ((vwQueueElement = (VWWorkObject)qQuery.next()) != null);
}
Return the queue object for the queueName requested, after Initializing VWQueue object (vwQueue) and setting it as follows:
vwQueue = m_vwSession.getQueue(queueName);
//( Error handling code . . . )
return vwQueue;
Returns an array of queue names and shows how to use session object flags to control what queue names are fetched, with the following processing steps:
Initialize the fetch flags variable (nflags) and a string array (queueNames)
int nFlags = VWSession.QUEUE_PROCESS | VWSession.QUEUE_USER_CENTRIC | VWSession.QUEUE_IGNORE_SECURITY;
String[] queueNames = null;
Use the passed in flag (bIncludeSystem) to optionally include system queues:
if (bIncludeSystem) nFlags |= VWSession.QUEUE_SYSTEM;
Retrieve the list of available queues with VWSession.fetchQueueNames(int)
queueNames = m_vwSession.fetchQueueNames(nFlags);
// ( error handling code . . . )
return queueNames; // (a string array)