Interacting with the Task programmatically


In real world applications you will probably require to interact with your Task programmatically, by creating your own Task client interfaces.


Connecting to the TaskService

The TaskClient api is not too complex. The first thing you will require is connecting to the TaskService

 TaskClient client = new TaskClient(new MinaTaskClientConnector("client 1", 
                new  MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
            client.connect("", 9123);

What are MinaServer and MinaClient ? Apache MINA is a network application framework which helps users develop high performance and high scalability network applications easily.

Adjust the IP address to the machine where you have started the TaskService, which by default is bound on port 9123.

Browsing the TaskList

Once you have the TaskClient instance available, you can browse the Task assigned to a particular client. For example if we want to browse all Task assigned to user “john” using the en-UK format:

BlockingTaskSummaryResponseHandler taskSummaryResponseHandler =
               new BlockingTaskSummaryResponseHandler();

client.getTasksAssignedAsPotentialOwner("john", "en-UK", taskSummaryResponseHandler);

List<TaskSummary> tasks = taskSummaryResponseHandler.getResults();


for (TaskSummary task: tasks) {
      System.out.println(task.getId() + " " + task.getName() + " " + task.getStatus());

The method client.getTasksAssignedAsPotentialOwner will return all tasks which have a potential owner. If you want to retrieve all tasks (including also which are complete) you can use the following method:
client.getTasksOwned("john", "en-UK", taskSummaryResponseHandler);

Starting a Task

In order to start a specific taskid for the user john you would need to use the method start of the TaskClient:

BlockingTaskOperationResponseHandler responseHandler =

   new BlockingTaskOperationResponseHandler();

client.start( taskId, "john", responseHandler );


Completing a Task

In order to complete a specific taskid for the user john you would need to use the method complete of the TaskClient:

responseHandler = new BlockingTaskOperationResponseHandler();

client.complete( taskId, "john", null, responseHandler );