Accessing TasksOnce a Task can convert external information and populate a Task, the task needs the information. In general, the information must be in XML format. Specifically, the information must support XPath queries in order to access the data. Usually, supporting XPath queries requires the data to be XML. However, when properly populated, an ordered list can also support a limited (but sufficient) subset of such queries.
While the full specification of XPath allows for traversing an XML tree, the conversion process can be performed if a particular item, or sequence of items, can be accessed. Typically, a query specifies the children elements to descend a tree. For example, given the following XML data:
Given the following functions that extract data from an XML tree: String getValue( String xpathQuery ); String[] getValues( String xpathQuery ); The data can then be retrieved with the following XPath queries: which results in:int child1 = Integer.parseInt( getValue( "/ExternalData/Parent/Child1" ) ); int child2 = Integer.parseInt( getValue( "/ExternalData/Parent/Child2" ) ); String[] child3 = getValues( "/ExternalData/Parent/Child3/Data/*" );
HTML supports transfering data from the client by using forms. Forms contain various The web client will transmit the data in a stream of name/value pairs. An important note is that HTTP sends the data in the same order as the For example, let's say a FORM page has three input fields, one hidden, one text, and one submit.
<INPUT> tag, but when also dealing with XML, it is a good habit to get into.)The above form creates a label "Number", followed by a text field five characters wide for the number, and a button that will send the data to the URL specified in the taskName=jicos.examples.external.fibonacci.Fibonacci&/ExternalRequest/Fibonacci/n=20
Before submitting the information to JICOS, the last selection to make is whether to wait for a response, or poll for an answer. For short running jobs (such as getting the Fibonacci sequence for n=10) it is better to wait for an answer. Longer running jobs (such as solving the Traveling Salesman Problem for 500 cities) might take a day or two, and losing the result because of a network partition would be disappointing. At the bottom of the form is a pull-down menu ( ) that will allow the user to wait for the response ("immediate" mode) or poll the web server ("delayed" mode) for the answer. If immediate mode is selected, then the collector will not send back a result, causing the browser to wait until the answer is computed. In delayed mode, the collector will immediately return a web page containing a URL where the answer will eventually be found. The page returned will periodically (every 60 seconds) check to see of the answer is available. Another approach would be to bookmark the URL and try back. A future enhancement will be to have the Collector send a mail message once the answer is available.
The Fibonacci sequence is used as sort of a "Hello World" program in JICOS, since it clearly demonstrates the decomposition of a Task, and the composition of an answer. The Fibonacci sequence is defined recursively as follows:
thus, F(5) =
= F(4)+F(3) = F(3)+F(2) + F(2)+F(1) = F(2)+F(1)+F(1)+F(0) + F(1)+F(0)+1 = F(1)+F(0)+1+1+1 + 1+1+1 = 1+1+1+1+1 + 1+1+1 = 8 F(6) = F(5)+F(4) = 8 + 5 = 13 F(7) = F(6)+F(5) = 13 + 8 = 21 F(8) = F(7)+F(6) = 21 + 13 = 34 F(9) = F(8)+F(7) = 34 + 21 = 55 F(10) = F(9)+F(8) = 34 + 55 = 89 ... Fibonacci.java is an example of how to extend this basic Task to support external access. Some details to note:
|