1 23 24 25 import org.objectweb.clif.scenario.util.isac.plugin.SampleAction; 26 import org.objectweb.clif.scenario.util.isac.util.SessionObjectAction; 27 import org.objectweb.clif.scenario.util.isac.exception.IsacRuntimeException; 28 import org.objectweb.clif.storage.api.ActionEvent; 29 import java.util.Hashtable ; 30 31 32 36 public class HelloWorldSessionObject implements SampleAction, SessionObjectAction 37 { 38 static protected final int SAY_HELLO = 0; 40 static protected final int SAY_WORLD = 1; 41 static protected final int SAY_NEXT_WORD = 2; 42 static protected final int SAY_USER_DEFINED = 3; 43 44 static protected final String USER_DEFINED_ARG = "user_string_arg"; 46 static protected final String HELLO_ARG = "hello_arg"; 47 static protected final String WORLD_ARG = "world_arg"; 48 49 boolean wordSwitch = true; 50 String hello = "Hello"; 51 String world = "World"; 52 53 59 public HelloWorldSessionObject(Hashtable params) 60 { 61 String value = (String )params.get(HELLO_ARG); 62 if (value != null && value.length() > 0) 63 { 64 hello = value; 65 } 66 value = (String )params.get(WORLD_ARG); 67 if (value != null && value.length() > 0) 68 { 69 world = value; 70 } 71 } 72 73 74 80 private HelloWorldSessionObject(HelloWorldSessionObject toClone) 81 { 82 hello = toClone.hello; 83 world = toClone.world; 84 wordSwitch = toClone.wordSwitch; 85 } 86 87 88 92 93 public ActionEvent doSample(int number, Hashtable params, ActionEvent report) 94 throws IsacRuntimeException 95 { 96 synchronized(System.out) 97 { 98 long startingTime = System.currentTimeMillis(); 99 switch (number) 100 { 101 case SAY_HELLO: 102 report.result = hello; 103 report.type = "HELLO"; 104 break; 105 case SAY_WORLD: 106 report.result = world; 107 report.type = "WORLD"; 108 break; 109 case SAY_NEXT_WORD: 110 report.result = wordSwitch ? hello : world; 111 wordSwitch = ! wordSwitch; 112 report.type = "NEXT_WORD"; 113 break; 114 case SAY_USER_DEFINED: 115 report.type = "USER_DEFINED"; 116 report.result = (String )params.get(USER_DEFINED_ARG); 117 break; 118 default: 119 report.comment = "no such sample number: " + number; 120 report.type = "ERROR"; 121 report.successful = false; 122 } 123 if (report.isSuccessful()) 124 { 125 System.out.println(report.result); 126 System.out.flush(); 127 report.duration = (int)(System.currentTimeMillis() - startingTime); 128 } 129 report.setDate(startingTime); 130 } 131 return report; 132 } 133 134 135 139 140 public Object createNewSessionObject() 141 { 142 return new HelloWorldSessionObject(this); 143 } 144 145 146 public void close() 147 { 148 } 149 150 151 public void reset() 152 { 153 } 154 } 155 | Popular Tags |