package edu.ucsb.cs.jicos.examples.asynchronouscomputing; import edu.ucsb.cs.jicos.services.*; import java.util.*; final class Application { public static void main ( String args[] ) throws Exception { // get arguments from the command line String hspDomainName = args[0]; int start = Integer.parseInt ( args[1] ); int amount = Integer.parseInt ( args[2] ); // get a reference to a Hosting Service Provider HspAgent agent = new HspAgent( hspDomainName ); Client2Hsp hsp = agent.getClient2Hsp(); // login Environment environment = new Environment( null, null ); hsp.login( environment ); /* dispatch several asynchronous Fibonacci computations * start is the 1st Fibonacci number to compute * amount is the number of Fibonacci numbers to compute * E.g. start = 5, number = 3 means compute Fibonacci numbers 5, 6, & 7 */ Task task; Map table = new HashMap(); for ( int number = start; number < start + amount; number++ ) { task = new F( number ); ResultId key = hsp.setComputation ( task ); Integer value = new Integer( number ); table.put( key, value ); } // get & print Result objects for ( int i = 0; i < amount; i++ ) { Result result = hsp.getResult(); ResultId key = result.getId(); Integer number = (Integer) table.remove( key ); Integer value = (Integer) result.getValue(); System.out.println("F( " + number + " ) = " + value ); } hsp.logout(); } }