package atVM; import java.io.BufferedInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Collection; import mobileAgent.GeneralMobileAgent; import residenceAgent.ResidenceAgent; public class Test implements IApplication { /** * @param args */ public static void main(String[] args) { AFrame aFrame1 = new AFrame(args); ResidenceAgent ra1 = aFrame1.getResidenceAgent(); System.out.println("Residence Agent Initialized:" + ra1.getResidenceAgentName()); String appName = "test"; System.out.println("ra1.register() result: "); try { ra1.register(appName, new Test()); } catch (ApplicationExistsException e) { e.printStackTrace(); } System.out.println("ra1.getCurrentTime() result: " + ra1.getCurrentTime()); // System.out.println("ra1.getAgentList() result: " + // ra1.getAgentList()); GeneralMobileAgent ma1 = aFrame1.createMobileAgent(); System.out.println("mobile agent created: " + ma1.getId()); ma1.getApplicationSpecificMobileAgent("time", "1"); ma1.setOwner(ra1.getResidenceAgentName()); ma1.setAppName(appName); ma1.setDelay(5000); ma1.setTransitionMode("allNodes"); Collection set = new ArrayList(); ma1.setTransitionSet(set); ma1.execute(); ma1.transitToNextNode(true, true); URL myurl; try { myurl = new URL("http://192.168.1.19:8080/console/services/test"); URLConnection uc = myurl.openConnection(); byte[] buf = new byte[2048]; BufferedInputStream in = new BufferedInputStream( uc.getInputStream()); StringBuffer sb = new StringBuffer(); int c; while ((c = in.read(buf)) != -1) { sb.append(new String(buf, 0, c)); } System.out.println(sb.toString()); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // The new instance will be created at runtime, thus note that this method // currently cannot reference other properties... public void mobileAgentComeBack(String id, String data) { String[] array = data.split("#takenAwayDataSplit#"); String text = "mobile agent executing result: \n"; for (int i = 0; i < array.length; i++) { String line = array[i]; text = text + line + "\n"; } System.out.println("return result: " + text); }; }