1 31 package org.objectweb.proactive.ext.implicit; 32 33 import org.objectweb.proactive.core.UniqueID; 34 import org.objectweb.proactive.core.body.request.BlockingRequestQueueImpl; 35 import org.objectweb.proactive.core.body.request.Request; 36 import org.objectweb.proactive.core.mop.MOP; 37 38 public class ImplicitService extends BlockingRequestQueueImpl implements Implicit { 39 40 43 transient protected java.util.Hashtable shortcuts; 44 45 48 public final static java.util.Hashtable shortcutsTables = new java.util.Hashtable (); 49 50 51 54 protected java.util.Hashtable sync; 55 56 public ImplicitService(UniqueID id) { 57 super(id); 58 sync = new java.util.Hashtable (); 59 } 60 61 62 73 public void forbid(String shortcut, String condition) throws InvalidAssociateDeclaration { 74 java.lang.reflect.Method cond; 75 System.out.println("ImplicitBody: forbid() for " + shortcut); 76 77 if (this.shortcuts == null) { 78 this.setShortcutsTable(); 80 } 81 82 84 if (!(this.shortcuts.containsKey(shortcut))) { 85 throw new InvalidAssociateDeclaration("No shortcut " + shortcut + " defined"); 86 } 87 88 cond = null; 91 95 if (!(cond.getReturnType().equals(java.lang.Boolean.TYPE))) { 96 throw new InvalidAssociateDeclaration("Method " + condition + " does not return a boolean as expected"); 97 } 98 99 this.sync.put(shortcut, cond); 101 103 return; 104 } 105 106 107 public void run() { 108 134 } 135 136 137 public synchronized Request getOldestReadyRequest() { 138 java.util.Iterator iterator = iterator(); 139 while (iterator.hasNext()) { 140 Request r = (Request) iterator.next(); 141 java.lang.reflect.Method target = null; String methodName; 144 if (this.shortcuts.contains(target)) { 145 methodName = this.getShortcut(target); 146 } else { 147 methodName = target.getName(); 148 } 149 java.lang.reflect.Method cond = (java.lang.reflect.Method ) this.sync.get(methodName); 151 if (cond != null) { 152 boolean test = this.testCondition(cond); 154 if (test) { 156 return r; 157 } 158 } 159 } 160 return null; 161 } 162 163 164 private boolean testCondition(java.lang.reflect.Method cond) { 165 boolean result = true; 166 Object [] args = new Object [0]; 167 168 System.out.println("ImplicitBody: testingCondition() on method" + cond); 169 170 try { 171 result = false; } catch (Exception e) { 173 System.err.println("Exception during invocation of method " + cond.getName()); 174 e.printStackTrace(); 175 } 176 return result; 177 } 178 179 180 public synchronized void serveOldestThatIsNot(String s) { 181 192 } 193 194 195 196 199 public void dumpShortcutsTable() { 200 java.util.Enumeration en; 201 String currentshc; 202 java.lang.reflect.Method currentmethod; 203 en = this.shortcuts.keys(); 204 System.out.println("--- Dump of the shortcuts table ---"); 205 while (en.hasMoreElements()) { 206 currentshc = (String )en.nextElement(); 207 currentmethod = (java.lang.reflect.Method )this.shortcuts.get(currentshc); 208 System.out.println(currentshc + "/" + currentmethod.toString()); 209 } 210 } 211 212 213 public String getShortcut(java.lang.reflect.Method m) { 214 java.util.Enumeration en; 215 String currentshc; 216 java.lang.reflect.Method currentmethod; 217 218 en = this.shortcuts.keys(); 219 220 while (en.hasMoreElements()) { 221 currentshc = (String )en.nextElement(); 222 currentmethod = (java.lang.reflect.Method )this.shortcuts.get(currentshc); 223 224 if (currentmethod.equals(m)) 225 return currentshc; 226 } 227 return null; 228 } 229 230 231 public void addShortcut(String shortcut, String name, String [] argumentstype) { 232 int index = 0, size; 233 Class [] args; 234 java.lang.reflect.Method met = null; 235 236 if (this.shortcuts.containsKey(shortcut)) { 238 System.err.println("Shortcut '" + shortcut + "' already exists."); 239 return; 240 } 241 242 size = argumentstype.length; 243 args = new Class [size]; 244 245 try { 247 for (index = 0; index < size; index++) { 248 args[index] = MOP.forName(argumentstype[index]); 250 } 251 met = null; } catch (ClassNotFoundException e) { 253 System.err.println("Class not found : " + argumentstype[index]); 254 return; 255 } this.shortcuts.put(shortcut, met); 261 } 262 263 264 269 270 public void fillShortcutsTable() { 271 java.lang.reflect.Method [] mets; 272 java.lang.reflect.Method currentmethod; 273 String currentshc; 274 int size, index, index2; 275 276 mets = null; size = mets.length; 278 279 for (index = 0; index < size; index++) { 280 currentmethod = mets[index]; 281 currentshc = currentmethod.getName(); 282 283 } 290 } 291 292 293 public void setShortcutsTable() { 294 297 String reifiedObjectClassName; 298 299 301 if (this.shortcuts == null) { 302 this.shortcuts = new java.util.Hashtable (); 303 this.fillShortcutsTable(); 304 } else { 307 } 309 } 310 311 312 315 public static boolean isOverloaded(java.lang.reflect.Method met, Class reifiedObjectClass) { 316 int n = 0; 317 java.lang.reflect.Method [] mets = reifiedObjectClass.getMethods(); 318 int size = mets.length; 319 for (int index = 0; index < size; index++) { 320 java.lang.reflect.Method currentmethod = mets[index]; 321 String currentshc = currentmethod.getName(); 322 if (currentshc.equals(met.getName())) 323 n++; 324 } 325 return (n > 1); 326 } 327 328 329 } 330 | Popular Tags |