This stand-alone sample demonstrates how to log the work object number and user information for locked work objects. Run the sample by entering a command similar to the following:
java MilestoneSample username password <server name>:<port
number>/<router instance name> [queue_name] [output_file]
Note For a detailed explanation of the command line, see the Run the sample application section of the Run the Unmodified Samples topic.
The MilestoneSample class contains two methods: the main(String args[]) method and the MilestoneSample(VWSession vwSession, Logger logger, String queueName) method, which is the constructor.
The main method uses common techniques for validating and defaulting argument values. The default values for the log output file and queue names are MilestoneSample.out and the first queue name in the system list of queue names, respectively. The main method constructs and passes vwSession and Logger objects to the sample constructor. Main() handles the login and logoff for the session with the login() and logoff() methods of the sample SessionHelper class. It provides workflow logging with an instance of the sample Logger class. The main method passes the session, the logger, and the user name, and the name of queue to query, which may be null.
The following code from the MilestoneSample constructor method displays the available milestones in the specified queue:
Instantiate the MilestoneHelper object, milestoneHelper. This class gets milestone defintions and prints milestone information.
milestoneHelper = new MilestoneHelper(vwSession, logger);
Instantiate the QueueHelper object, queueHelper. This class gets queue names and creates a VWQueue object.
queueHelper = new QueueHelper(vwSession, logger);
Get the specified queue object with vwSession.getQueue(), if the name is not null.
if (queueName != null){
vwQueue = vwSession.getQueue(queueName);
}
else {
Otherwise, use the QueueHelper.getQueueNames() method, to test for the existence of queues.
String[] queueNames = queueHelper.getQueueNames(false);
if (queueNames == null || queueNames.length == 0)
{
logger.log("No queues found.");
return;
}
else {
If queues are found, iteratively get queues until first queue with accessible elements is found. Create an instance of VWQueue with vwSession.getQueue(). vwQueue.fetchCount() returns the number of queues fetched.
for (int i = 0; i < queueNames.length; i++){
vwQueue = vwSession.getQueue(queueNames[i]);
if (vwQueue != null){
if (vwQueue.fetchCount() > 0)
break;
}
// Clear the queue pointer reference.
vwQueue = null;
}
}
If a queue object is retrieved, retrieve the first element and create a query object for the queue object with the API method VWQueue.createQuery().
qQuery = vwQueue.createQuery(null, null, null, 0, null, null,
VWFetchType.FETCH_TYPE_QUEUE_ELEMENT);
Attempt to retrieve the query object's first queue element.
vwQueueElement = (VWQueueElement)qQuery.next();
if (vwQueueElement == null){
logger.log("\t Queue elements: none");
}
else {
If a queue element is retrieved, log its workflow name with the logger.log() method. Obtain the name from the vwQueueElement.getWorkflowName() method. Get milestone definitions for every element, and print them using the MilestoneHelper methods getMilestoneDefinitions() and printMilestoneInfo().
do {
logger.log("\tWorkflow " + vwQueueElement.getWorkflowName());
VWMilestoneDefinition[] msd = milestoneHelper.getMilestoneDefinitions(vwQueueElement);
milestoneHelper.printMilestoneInfo(msd);
} while ((vwQueueElement = (VWQueueElement)qQuery.next()) != null);
Additional code in this method performs common cleanup and error handling.