This stand-alone sample demonstrates how to use the API classes to manage queue operations. Run the sample by entering a command similar to the following:
java OperationsSample username password <server name>:<port
number>/<router instance name> [queue_name] [output_file]
If no queue name is specified, the program uses the first queue with elements in the list of queueNames. If do not specify an output file name, the sample uses OperationSample.out as the default location.
Note For a detailed explanation of the command line, see the Run the sample application section of the Run the Unmodified Samples topic.
The OperationsSample code creates an instance of the SessionHelper class (sessionHelper) and the Logger class (logger). The sessionHelper.logon() method logs on to a workflow session and returns a VWSession object, vwSession. The main method then passes the vwSession object, the logger object, and the queue name, which may be null, to the sample constructor.
The following code from the OperationsSample constructor method configures and reports on queue operations.
Create default operations and queue helper objects.
operationsHelper = new OperationsHelper(vwSession, logger);
queueHelper = new QueueHelper(vwSession, logger);
Get the specified queue object with vwSession.getQueue(), if the name was not NULL.
if (queueName != null){
vwQueue = vwSession.getQueue(queueName);
} else { // ( . . . continued below)
Otherwise, use the QueueHelper.getQueueNames() method, to test for exsiting queues.
String[] queueNames = queueHelper.getQueueNames(false);
if (queueNames == null || queueNames.length == 0)
{
logger.log("No queues found.");
return;
} else {
vwQueue = vwSession.getQueue(queueNames[1]);
}
// Make sure the program has created a VWQueue object.
if (vwQueue == null){
logger.log("Unable to retrieve a queue!");
return;
} else {
logger.log("Phase 1 : Configuration\n");
Fetch a VWQueueDefinition object with VWQueueDefinition and initialize a VWOperationDefinition object.
VWQueueDefinition vwQueueDef = null;
VWOperationDefinition opDef = null;
vwQueueDef = vwQueue.fetchQueueDefinition();
Create a new operation definition with the VWQueueDefinition.createOperation() method and add some parameters to it.
opDef = vwQueueDef.createOperation("Sample Operation");
logger.log("Created new operation definition");// Add boolean parameter, sent by the operation, and not an array.
opDef.createParameter("BoolParameter", 2, 4, false);
// Add an integer parameter, returned to the operation, and not an array.
opDef.createParameter("IntParameter", 1, 1, false);
opDef.setDescription("Created by OperationsSample example application");
logger.log("Configured operation definition");
Update the system configuration queue definition, using the current queue copy and VWSystemConfiguration.updateQueueDefinition().
sysConfig = vwSession.fetchSystemConfiguration();
sysConfig.updateQueueDefinition(vwQueueDef);
Commit changes. The update is not complete until it is committed.
String[] errors = sysConfig.commit();
if (errors != null)
logger.log("Errors: ", errors);
else
logger.log("Committed configuration changes.");
Fetch a list of operations defined on this queue. Get each operation information and print it with the sample helper methods operationsHelper.getOperationDefinition() and printOperationDetails().
String[] operationNames = vwQueue.fetchOperationNames();
VWOperationDefinition vwOpDef = null;
for (int i=0;i<operationNames.length;i++){// get configuration information about each defined operation
vwOpDef = operationsHelper.getOperationDefinition(operationNames[i], vwQueue);
operationsHelper.printOperationDetails(vwOpDef);
}
}
Additional OperationsSample code performs common message and error handling.