/* * Created on November 11, 2009 */ package cluster5.client; import java.util.List; import cluster5.server.datastorage.domain.Project; import cluster5.server.datastorage.domain.Task; public class MyClusterApplication { /** * @param args */ @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { // get instance of the cluster interface: ClusterInterface cluster = ClusterInterfaceImpl.getInstance(); boolean res = cluster.login("ibisek", "mypassword"); System.out.println("login result: " + res); if (cluster.openProject("my new cluster project")) { // create some new tasks if the project is NEW. In case our application crashed, // the tasks can still be there or running and we don't want to add more tasks at // that moment. if (cluster.getProjectStatus() == Project.Status.NEW) { // set the main class of our clustered application: cluster.setProjectMainClass(MyClusterTask.class); // here comes the list of ALL classes used by our main class: Class[] classes = { MyClusterTask.class }; cluster.setProjectLibraries(classes); Long argument = 999999999l; // number of loops to do int numTasks = 10; for (int i = 0; i < numTasks; i++) { Long taskId = cluster.createTask(argument); // you might want to store the task ID and use it for something later on.... // but don't need to. } cluster.runProject(); } // wait until all tasks have been evaluated: while (cluster.getProjectStatus() != Project.Status.FINISHED) { Thread.sleep(4000); System.out.println("Project status: " + cluster.getProjectStatus()); System.out.println(" progress: " + cluster.getProjectProgress()); } // pick up the evaluated tasks: List taskIds = cluster.listTaskIds(); for (Long taskId : taskIds) { Task task = cluster.getTask(taskId); String result = (String) task.getResult(); // we know the task returns a String System.out.println("task id: " + task.getId() + "; status: " + task.getStatus() + "\n result: " + result); } // delete all project classes, tasks and definition from the server: cluster.dropProject(); } cluster.logout(); } }