import java.io.*; import java.util.*; import wrapper.*; /**This module offers three different methods: concat, mult and fast. The method concat takes the two parameters s1 and s2, and returns s2. The method mult takes the two parameters m1 and m2, and returns res. The method fast does not take any parameters or return any results. The methods concat and mult are very slow, they take several minutes to execute. Parameters s1 and s2 are strings, m1, m2 and res are integers (represented as strings). All the parameters have preset values. */ public class TestModule1 extends CPAMMegamodule { public TestModule1(String p) {super(p);} protected void createParameters() { addParam("s1","This is "); addParam("s2","a text!"); addParam("m1","5"); addParam("m2","7"); addParam("res", "0"); } protected boolean makeEstimate(Estimates e, String methodname, ParamValueTableReader clientsettings) throws MethodNameException { if (methodname.equals("concat")) { e.feeValue = 50; e.feeProvided = true; e.timeValue = 5; e.timeAccuracy = 100; e.timeProvided = true; } else if (methodname.equals("mult")) { if (e.feeRequired) { e.feeProvided = true; e.feeValue = ( (Integer.parseInt((String)(clientsettings.get("m1"))) * (Integer.parseInt((String)(clientsettings.get("m2")))))); e.feeAccuracy = (float)e.feeValue / (float)10; } if (e.timeRequired) { e.timeProvided = true; e.timeValue = ( (Integer.parseInt((String)(clientsettings.get("m1"))) + (Integer.parseInt((String)(clientsettings.get("m2")))))); e.timeAccuracy = (float)e.timeValue / (float)10;} if (e.datavolumeRequired) { e.datavolumeValue=Integer.parseInt((String)(clientsettings.get("m2"))); e.datavolumeProvided = true; e.datavolumeAccuracy = 0.5; } else if (methodname.equals("fast")) return false; } else throw new MethodNameException("Do not know this method."); return true; } protected boolean dispatchInvocation(CPAMWrapperCallbacks inv, String methodname) { try{ if (methodname.equals("concat")) { String s1 = (String) inv.getParam("s1"); String s2 = (String) inv.getParam("s2"); Thread.sleep(30000); inv.updateInvocationProgress(49); Thread.sleep(30000); inv.updateParam("s1", new String (s1+s2), true, 100); Thread.sleep(30000); return false; } else if (methodname.equals("mult")) { int i1 = Integer.parseInt((String) inv.getParam("m1")); int i2 = Integer.parseInt((String) inv.getParam("m2")); inv.updateInvocationProgress(5); int res = 0; float acc=10; for (int i = 0; i