-
To submit the job to the production network
-
To process the returned results
Since implementations of the consumer interface follow a very specific
design pattern, we built up a tool called CXTool that will help you through
this process. The CXTool comes together with the CX Toolkit v1.0, which
you have probably already download. You can run it, by typing the
following command:
> java -cp CX.jar CXTool
figure 1 - the initial panel of CXTool, after we have
loaded FibTaskSpawn which extends the CXTask superclass
Now, lets discuss briefly the process of creating a simple Consumer
implementation using the CXTool. Note that you don't have to use this tool,
but since it makes your life easier you must have a good reason not to
do so (at least, that's what the author believes!).
Defining the initial task
Usually, there is going to be an initial task that will spawn other
tasks. In this trail we have introduced two tasks, the FibTaskSpawn
and the FibTaskCombine. FibTaskSpawn spawns other tasks and it will
serve as our initial task. You can locate it using the browse button. If
the class that you are trying to load does not extend the CXTask,
or all the involved classes are not present, then the loading process will
fail. After doing a successful class loading, the task class name
and the task class path fields will get automatically the proper
values, as well as the tables of the constructors will get populated by
all the available constructors.
Defining the job attributes
Please refer to the CX API to get an explanation
of these terms. Note the the default values are
-
ProducerAllowed = true
-
ServerAllowed =false
-
Local=false
The range must be always set to an integer value, which corresponds
to the maximum number of tasks that can be spawn by another task. In case
of Fibonucci, range is 3.
Class name is the the name of the class for the initial task.
Selecting the constructor
The table of the available constructors was populated automatically
when you loaded the class. Here you can select exactly one constructor
(for instance, in figure 1 selected constructor #1). The parameters of
the constructors will have to be defined manually by editing the code after
the creation of the ConsumerImpl java file (see later)
Writing the result handling code
At the end of the computation the consumer will get notified by the
CX production network through the putResults method. Therefore, in order
to do something useful with the returned results the user must overwrite
this method. Since the skeleton of the method is already there, we will
add only a single line that prints the returned results on the screen:
System.out.println("Got
new results: "+Array.get(results[0].results,0));
Creating the ConsumerImpl
Simply press the Create button and wait for the confirmation message.
The outcome is always a file called ConsumerImpl.java. Warning: It will
overwrite previous versions of it without any notice!
Editing the ConsumerImpl
As it was mentioned previously, the only thing we have to modify in
the ConsumerImpl java source, are the parameters of the constructor. So,
in our case we have to make the following modification:
myTask = new FibTaskSpawn(int arg0) becomes
myTask = new FibTaskSpawn(5); if, for instance,
we want to evaluate Fib(5)
Compiling the ConsumerImpl
After compiling the ConsumerImpl, don't forget to execute the rmic
command:
$> javac -classpath CX.jar ConsumerImpl.java
$> rmic -classpath .;CX.jar ConsumerImpl
Otherwise the required stubs will not be created.
Note: ConsumerImpl is just the default filename for the Consumer
implmentation. It could be any other name, as well.