1 7 package org.jboss.cache.marshall; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 import org.jboss.cache.CacheImpl; 12 import org.jboss.cache.Fqn; 13 import org.jboss.cache.GlobalTransaction; 14 import org.jboss.cache.Node; 15 import org.jboss.cache.buddyreplication.BuddyGroup; 16 import org.jboss.cache.lock.NodeLock; 17 import org.jboss.cache.optimistic.DataVersion; 18 import org.jboss.cache.rpc.RpcTreeCache; 19 import org.jgroups.Address; 20 import org.jgroups.stack.IpAddress; 21 22 import java.lang.reflect.Method ; 23 import java.util.HashMap ; 24 import java.util.HashSet ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Set ; 28 29 36 public class MethodDeclarations 37 { 38 private static Log log = LogFactory.getLog(MethodDeclarations.class); 39 40 static final Set <Integer > crudMethodIds = new HashSet <Integer >(); 41 static final Set <Integer > transactionLifecycleMethodIds = new HashSet <Integer >(); 42 static final Set <Integer > buddyGroupOrganisationMethodIds = new HashSet <Integer >(); 43 static final Set <Integer > putMethodIds = new HashSet <Integer >(); 44 45 static final Map <Integer , Method > methods = new HashMap <Integer , Method >(); 47 48 static final Map <Method , Integer > methodIds = new HashMap <Method , Integer >(); 50 51 public static final Method putDataMethodLocal; 52 53 public static final Method putDataEraseMethodLocal; 54 55 public static final Method putKeyValMethodLocal; 56 57 public static final Method removeNodeMethodLocal; 58 59 public static final Method removeKeyMethodLocal; 60 61 public static final Method removeDataMethodLocal; 62 63 public static final Method evictNodeMethodLocal; 64 65 public static final Method evictVersionedNodeMethodLocal; 66 67 public static final Method prepareMethod; 68 69 public static final Method commitMethod; 70 71 public static final Method rollbackMethod; 72 73 public static final Method replicateMethod; 74 75 public static final Method replicateAllMethod; 76 77 public static final Method addChildMethodLocal; 78 79 public static final Method getKeyValueMethodLocal; 80 81 public static final Method getNodeMethodLocal; 82 83 public static final Method getKeysMethodLocal; 84 85 public static final Method getChildrenNamesMethodLocal; 86 87 public static final Method getDataMapMethodLocal; 88 89 public static final Method existsMethod; 90 91 public static final Method releaseAllLocksMethodLocal; 92 93 public static final Method printMethodLocal; 94 95 public static final Method lockMethodLocal; 96 97 public static final Method optimisticPrepareMethod; 98 99 public static final Method clusteredGetMethod; 100 101 public static final Method remoteAssignToBuddyGroupMethod; 102 103 public static final Method remoteRemoveFromBuddyGroupMethod; 104 105 public static final Method remoteAnnounceBuddyPoolNameMethod; 106 107 public static final Method dataGravitationCleanupMethod; 108 109 public static final Method dataGravitationMethod; 110 111 public static final Method moveMethodLocal; 112 113 public static final Method blockChannelLocal; 114 115 public static final Method unblockChannelLocal; 116 117 119 public static final Method putDataVersionedMethodLocal; 120 121 public static final Method putDataEraseVersionedMethodLocal; 122 123 public static final Method putKeyValVersionedMethodLocal; 124 125 public static final Method removeNodeVersionedMethodLocal; 126 127 public static final Method removeKeyVersionedMethodLocal; 128 129 public static final Method removeDataVersionedMethodLocal; 130 131 public static final int putDataMethodLocal_id = 1; 133 134 public static final int putDataEraseMethodLocal_id = 2; 135 136 public static final int putKeyValMethodLocal_id = 3; 137 138 140 public static final int removeNodeMethodLocal_id = 5; 141 142 public static final int removeKeyMethodLocal_id = 6; 143 144 public static final int removeDataMethodLocal_id = 7; 145 146 public static final int evictNodeMethodLocal_id = 8; 147 148 public static final int evictVersionedNodeMethodLocal_id = 9; 149 150 public static final int prepareMethod_id = 10; 151 152 public static final int commitMethod_id = 11; 153 154 public static final int rollbackMethod_id = 12; 155 156 public static final int replicateMethod_id = 13; 157 158 public static final int replicateAllMethod_id = 14; 159 160 public static final int addChildMethodLocal_id = 15; 161 162 public static final int existsMethod_id = 16; 163 164 public static final int releaseAllLocksMethodLocal_id = 17; 165 166 public static final int optimisticPrepareMethod_id = 18; 167 168 public static final int getPartialStateMethod_id = 19; 169 170 public static final int clusteredGetMethod_id = 22; 171 172 public static final int getChildrenNamesMethodLocal_id = 23; 173 174 public static final int getDataMapMethodLocal_id = 24; 175 176 public static final int getKeysMethodLocal_id = 25; 177 178 public static final int getKeyValueMethodLocal_id = 26; 179 180 public static final int dispatchRpcCallMethod_id = 27; 181 182 public static final int remoteAnnounceBuddyPoolNameMethod_id = 28; 183 184 public static final int remoteAssignToBuddyGroupMethod_id = 29; 185 186 public static final int remoteRemoveFromBuddyGroupMethod_id = 30; 187 188 189 public static final int getNodeMethodLocal_id = 31; 190 191 public static final int printMethodLocal_id = 32; 192 193 public static final int lockMethodLocal_id = 33; 194 195 public static final int dataGravitationCleanupMethod_id = 34; 196 197 public static final int dataGravitationMethod_id = 35; 198 199 public static final int moveMethodLocal_id = 36; 200 201 203 public static final int putDataVersionedMethodLocal_id = 37; 204 205 public static final int putDataEraseVersionedMethodLocal_id = 38; 206 207 public static final int putKeyValVersionedMethodLocal_id = 39; 208 209 public static final int removeNodeVersionedMethodLocal_id = 40; 210 211 public static final int removeKeyVersionedMethodLocal_id = 41; 212 213 public static final int removeDataVersionedMethodLocal_id = 42; 214 215 public static final int blockChannelMethodLocal_id = 43; 216 217 public static final int unblockChannelMethodLocal_id = 44; 218 219 220 static 221 { 222 try 223 { 224 getDataMapMethodLocal = CacheImpl.class.getDeclaredMethod("_getData", Fqn.class); 225 existsMethod = CacheImpl.class.getDeclaredMethod("exists", Fqn.class); 226 putDataMethodLocal = CacheImpl.class.getDeclaredMethod("_put", GlobalTransaction.class, Fqn.class, Map .class, boolean.class); 227 putDataEraseMethodLocal = CacheImpl.class.getDeclaredMethod("_put", GlobalTransaction.class, Fqn.class, Map .class, boolean.class, boolean.class); 228 putKeyValMethodLocal = CacheImpl.class.getDeclaredMethod("_put", GlobalTransaction.class, Fqn.class, Object .class, Object .class, boolean.class); 229 removeNodeMethodLocal = CacheImpl.class.getDeclaredMethod("_remove", GlobalTransaction.class, Fqn.class, boolean.class); 230 removeKeyMethodLocal = CacheImpl.class.getDeclaredMethod("_remove", GlobalTransaction.class, Fqn.class, Object .class, boolean.class); 231 removeDataMethodLocal = CacheImpl.class.getDeclaredMethod("_removeData", GlobalTransaction.class, Fqn.class, boolean.class); 232 evictNodeMethodLocal = CacheImpl.class.getDeclaredMethod("_evict", Fqn.class); 233 evictVersionedNodeMethodLocal = CacheImpl.class.getDeclaredMethod("_evict", Fqn.class, DataVersion.class); 234 235 prepareMethod = CacheImpl.class.getDeclaredMethod("prepare", GlobalTransaction.class, List .class, Address.class, boolean.class); 237 commitMethod = CacheImpl.class.getDeclaredMethod("commit", GlobalTransaction.class); 238 rollbackMethod = CacheImpl.class.getDeclaredMethod("rollback", GlobalTransaction.class); 239 addChildMethodLocal = CacheImpl.class.getDeclaredMethod("_addChild", GlobalTransaction.class, Fqn.class, Object .class, Node.class, boolean.class); 240 getKeyValueMethodLocal = CacheImpl.class.getDeclaredMethod("_get", Fqn.class, Object .class, boolean.class); 241 getNodeMethodLocal = CacheImpl.class.getDeclaredMethod("_get", Fqn.class); 242 getKeysMethodLocal = CacheImpl.class.getDeclaredMethod("_getKeys", Fqn.class); 243 getChildrenNamesMethodLocal = CacheImpl.class.getDeclaredMethod("_getChildrenNames", Fqn.class); 244 replicateMethod = CacheImpl.class.getDeclaredMethod("_replicate", MethodCall.class); 245 replicateAllMethod = CacheImpl.class.getDeclaredMethod("_replicate", List .class); 246 releaseAllLocksMethodLocal = CacheImpl.class.getDeclaredMethod("_releaseAllLocks", Fqn.class); 247 printMethodLocal = CacheImpl.class.getDeclaredMethod("_print", Fqn.class); 248 lockMethodLocal = CacheImpl.class.getDeclaredMethod("_lock", Fqn.class, NodeLock.LockType.class, boolean.class); 249 250 optimisticPrepareMethod = CacheImpl.class.getDeclaredMethod("optimisticPrepare", GlobalTransaction.class, List .class, Map .class, Address.class, boolean.class); 251 252 clusteredGetMethod = CacheImpl.class.getDeclaredMethod("_clusteredGet", MethodCall.class, Boolean .class); 253 254 256 remoteAnnounceBuddyPoolNameMethod = CacheImpl.class.getDeclaredMethod("_remoteAnnounceBuddyPoolName", IpAddress.class, String .class); 257 remoteRemoveFromBuddyGroupMethod = CacheImpl.class.getDeclaredMethod("_remoteRemoveFromBuddyGroup", String .class); 258 remoteAssignToBuddyGroupMethod = CacheImpl.class.getDeclaredMethod("_remoteAssignToBuddyGroup", BuddyGroup.class, Map .class); 259 260 dataGravitationCleanupMethod = CacheImpl.class.getDeclaredMethod("_dataGravitationCleanup", GlobalTransaction.class, Fqn.class, Fqn.class); 261 dataGravitationMethod = CacheImpl.class.getDeclaredMethod("_gravitateData", Fqn.class, boolean.class, boolean.class); 262 263 moveMethodLocal = CacheImpl.class.getDeclaredMethod("_move", Fqn.class, Fqn.class); 265 266 blockChannelLocal = CacheImpl.class.getDeclaredMethod("_block"); 268 unblockChannelLocal = CacheImpl.class.getDeclaredMethod("_unblock"); 269 270 putDataVersionedMethodLocal = CacheImpl.class.getDeclaredMethod("_put", GlobalTransaction.class, Fqn.class, Map .class, boolean.class, DataVersion.class); 272 putDataEraseVersionedMethodLocal = CacheImpl.class.getDeclaredMethod("_put", GlobalTransaction.class, Fqn.class, Map .class, boolean.class, boolean.class, DataVersion.class); 273 putKeyValVersionedMethodLocal = CacheImpl.class.getDeclaredMethod("_put", GlobalTransaction.class, Fqn.class, Object .class, Object .class, boolean.class, DataVersion.class); 274 removeNodeVersionedMethodLocal = CacheImpl.class.getDeclaredMethod("_remove", GlobalTransaction.class, Fqn.class, boolean.class, DataVersion.class); 275 removeKeyVersionedMethodLocal = CacheImpl.class.getDeclaredMethod("_remove", GlobalTransaction.class, Fqn.class, Object .class, boolean.class, DataVersion.class); 276 removeDataVersionedMethodLocal = CacheImpl.class.getDeclaredMethod("_removeData", GlobalTransaction.class, Fqn.class, boolean.class, DataVersion.class); 277 278 } 279 catch (NoSuchMethodException ex) 280 { 281 ex.printStackTrace(); 282 throw new ExceptionInInitializerError (ex.toString()); 283 } 284 285 methods.put(putDataMethodLocal_id, putDataMethodLocal); 286 methods.put(putDataEraseMethodLocal_id, putDataEraseMethodLocal); 287 methods.put(putKeyValMethodLocal_id, putKeyValMethodLocal); 288 methods.put(removeNodeMethodLocal_id, removeNodeMethodLocal); 289 methods.put(removeKeyMethodLocal_id, removeKeyMethodLocal); 290 methods.put(removeDataMethodLocal_id, removeDataMethodLocal); 291 methods.put(evictNodeMethodLocal_id, evictNodeMethodLocal); 292 methods.put(evictVersionedNodeMethodLocal_id, evictVersionedNodeMethodLocal); 293 methods.put(prepareMethod_id, prepareMethod); 294 methods.put(commitMethod_id, commitMethod); 295 methods.put(rollbackMethod_id, rollbackMethod); 296 methods.put(replicateMethod_id, replicateMethod); 297 methods.put(replicateAllMethod_id, replicateAllMethod); 298 methods.put(addChildMethodLocal_id, addChildMethodLocal); 299 methods.put(existsMethod_id, existsMethod); 300 methods.put(releaseAllLocksMethodLocal_id, releaseAllLocksMethodLocal); 301 methods.put(optimisticPrepareMethod_id, optimisticPrepareMethod); 302 methods.put(clusteredGetMethod_id, clusteredGetMethod); 303 methods.put(getChildrenNamesMethodLocal_id, getChildrenNamesMethodLocal); 304 methods.put(getDataMapMethodLocal_id, getDataMapMethodLocal); 305 methods.put(getKeysMethodLocal_id, getKeysMethodLocal); 306 methods.put(getKeyValueMethodLocal_id, getKeyValueMethodLocal); 307 methods.put(dispatchRpcCallMethod_id, RpcTreeCache.dispatchRpcCallMethod); 308 methods.put(remoteAnnounceBuddyPoolNameMethod_id, remoteAnnounceBuddyPoolNameMethod); 309 methods.put(remoteAssignToBuddyGroupMethod_id, remoteAssignToBuddyGroupMethod); 310 methods.put(remoteRemoveFromBuddyGroupMethod_id, remoteRemoveFromBuddyGroupMethod); 311 312 methods.put(getNodeMethodLocal_id, getNodeMethodLocal); 313 methods.put(printMethodLocal_id, printMethodLocal); 314 methods.put(lockMethodLocal_id, lockMethodLocal); 315 316 methods.put(dataGravitationCleanupMethod_id, dataGravitationCleanupMethod); 317 methods.put(dataGravitationMethod_id, dataGravitationMethod); 318 319 methods.put(moveMethodLocal_id, moveMethodLocal); 320 methods.put(blockChannelMethodLocal_id, blockChannelLocal); 321 methods.put(unblockChannelMethodLocal_id, unblockChannelLocal); 322 323 methods.put(putDataVersionedMethodLocal_id, putDataVersionedMethodLocal); 324 methods.put(putDataEraseVersionedMethodLocal_id, putDataEraseVersionedMethodLocal); 325 methods.put(putKeyValVersionedMethodLocal_id, putKeyValVersionedMethodLocal); 326 methods.put(removeDataVersionedMethodLocal_id, removeDataVersionedMethodLocal); 327 methods.put(removeKeyVersionedMethodLocal_id, removeKeyVersionedMethodLocal); 328 methods.put(removeNodeVersionedMethodLocal_id, removeNodeVersionedMethodLocal); 329 330 for (Integer id : methods.keySet()) 331 { 332 methodIds.put(methods.get(id), id); 333 } 334 335 336 putMethodIds.add(putDataMethodLocal_id); 337 putMethodIds.add(putDataEraseMethodLocal_id); 338 putMethodIds.add(putKeyValMethodLocal_id); 339 putMethodIds.add(putDataEraseVersionedMethodLocal_id); 340 putMethodIds.add(putDataVersionedMethodLocal_id); 341 putMethodIds.add(putKeyValVersionedMethodLocal_id); 342 343 crudMethodIds.addAll(putMethodIds); 344 crudMethodIds.add(removeNodeMethodLocal_id); 345 crudMethodIds.add(removeKeyMethodLocal_id); 346 crudMethodIds.add(removeDataMethodLocal_id); 347 crudMethodIds.add(dataGravitationCleanupMethod_id); 348 crudMethodIds.add(moveMethodLocal_id); 349 crudMethodIds.add(putDataVersionedMethodLocal_id); 350 crudMethodIds.add(putDataEraseVersionedMethodLocal_id); 351 crudMethodIds.add(putKeyValVersionedMethodLocal_id); 352 crudMethodIds.add(removeNodeVersionedMethodLocal_id); 353 crudMethodIds.add(removeKeyVersionedMethodLocal_id); 354 crudMethodIds.add(removeDataVersionedMethodLocal_id); 355 356 357 transactionLifecycleMethodIds.add(commitMethod_id); 358 transactionLifecycleMethodIds.add(rollbackMethod_id); 359 transactionLifecycleMethodIds.add(prepareMethod_id); 360 transactionLifecycleMethodIds.add(optimisticPrepareMethod_id); 361 362 buddyGroupOrganisationMethodIds.add(remoteAnnounceBuddyPoolNameMethod_id); 363 buddyGroupOrganisationMethodIds.add(remoteAssignToBuddyGroupMethod_id); 364 buddyGroupOrganisationMethodIds.add(remoteRemoveFromBuddyGroupMethod_id); 365 366 } 367 368 protected static int lookupMethodId(Method method) 369 { 370 Integer methodIdInteger = methodIds.get(method); 371 int methodId = -1; 372 373 if (methodIdInteger != null) 374 { 375 methodId = methodIdInteger; 376 } 377 else 378 { 379 if (log.isWarnEnabled()) 380 { 381 log.warn("Method " + method + " is not registered with " + CacheMarshaller200.class); 382 } 383 } 384 385 return methodId; 386 } 387 388 protected static Method lookupMethod(int id) 389 { 390 Method method = methods.get(id); 391 if (method == null) 392 { 393 if (log.isErrorEnabled()) 394 { 395 log.error("Method id " + id + " is not registered"); 396 } 397 throw new RuntimeException ("Method id " + id + " is not registered with " + CacheMarshaller200.class); 398 } 399 return method; 400 } 401 402 405 public static boolean isCrudMethod(int id) 406 { 407 return crudMethodIds.contains(Integer.valueOf(id)); 408 } 409 410 public static boolean isTransactionLifecycleMethod(int id) 411 { 412 return transactionLifecycleMethodIds.contains(id); 413 } 414 415 public static boolean isBuddyGroupOrganisationMethod(int id) 416 { 417 return buddyGroupOrganisationMethodIds.contains(id); 418 } 419 420 public static boolean isPutMethod(int id) 421 { 422 return putMethodIds.contains(id); 423 } 424 425 428 public static Method getVersionedMethod(int methodId) 429 { 430 if (isCrudMethod(methodId)) 431 { 432 switch (methodId) 433 { 434 case putDataEraseMethodLocal_id: 435 return putDataEraseVersionedMethodLocal; 436 case putDataMethodLocal_id: 437 return putDataVersionedMethodLocal; 438 case putKeyValMethodLocal_id: 439 return putKeyValVersionedMethodLocal; 440 case removeDataMethodLocal_id: 441 return removeDataVersionedMethodLocal; 442 case removeKeyMethodLocal_id: 443 return removeKeyVersionedMethodLocal; 444 case removeNodeMethodLocal_id: 445 return removeNodeVersionedMethodLocal; 446 case moveMethodLocal_id: 447 return moveMethodLocal; 448 default: 449 throw new RuntimeException ("Unrecognised method id " + methodId); 450 } 451 } 452 else 453 { 454 throw new RuntimeException ("Attempting to look up a versioned equivalent of a non-crud method"); 455 } 456 } 457 458 461 public static Method getUnversionedMethod(int methodId) 462 { 463 if (isCrudMethod(methodId)) 464 { 465 switch (methodId) 466 { 467 case putDataEraseVersionedMethodLocal_id: 468 return putDataEraseMethodLocal; 469 case putDataVersionedMethodLocal_id: 470 return putDataMethodLocal; 471 case putKeyValVersionedMethodLocal_id: 472 return putKeyValMethodLocal; 473 case removeDataVersionedMethodLocal_id: 474 return removeDataMethodLocal; 475 case removeKeyVersionedMethodLocal_id: 476 return removeKeyMethodLocal; 477 case removeNodeVersionedMethodLocal_id: 478 return removeNodeMethodLocal; 479 case moveMethodLocal_id: 480 return moveMethodLocal; 481 default: 482 throw new RuntimeException ("Unrecognised method id " + methodId); 483 } 484 } 485 else 486 { 487 throw new RuntimeException ("Attempting to look up a versioned equivalent of a non-crud method"); 488 } 489 } 490 491 492 public static boolean isDataGravitationMethod(int methodId) 493 { 494 return methodId == MethodDeclarations.dataGravitationCleanupMethod_id || methodId == MethodDeclarations.dataGravitationMethod_id; 495 } 496 } 497 498 | Popular Tags |