You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RegistrySynchronization.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
  3. Use and copying of this software and preparation of derivative works based
  4. upon this software are permitted. Any distribution of this software or
  5. derivative works must comply with all applicable United States export control
  6. laws.
  7. This software is made available AS IS, and Xerox Corporation makes no warranty
  8. about the software, its performance or its conformity to any specification.
  9. |<--- this code is formatted to fit into 80 columns --->|
  10. |<--- this code is formatted to fit into 80 columns --->|
  11. |<--- this code is formatted to fit into 80 columns --->|
  12. RegistrySynchronization.java
  13. Part of the Spacewar system.
  14. */
  15. package spacewar;
  16. import coordination.Coordinator;
  17. /**
  18. * This aspect ensures synchronized access to methods of the Registry in
  19. * the presence of several threads.
  20. *
  21. * It uses the Coordinator class, from the AspectJ coordination library.
  22. *
  23. * It uses a per-Registry coordination scheme, so there is one instance of
  24. * this class for each instance of the Registry class. When this class is
  25. * constructed, it registers appropriate mutexes and selfexes using the
  26. * behavior inherited from Coordinator.
  27. *
  28. * The mutating methods (register and unregister) should be self-exclusive.
  29. * Each reader method should be mutually exclusive with the mutating
  30. * methods. But the readers can run concurrently. */
  31. aspect RegistrySynchronization extends Coordinator perthis(this(Registry)) {
  32. protected pointcut synchronizationPoint():
  33. call(void Registry.register(..)) ||
  34. call(void Registry.unregister(..)) ||
  35. call(SpaceObject[] Registry.getObjects(..)) ||
  36. call(Ship[] Registry.getShips(..));
  37. public RegistrySynchronization() {
  38. addSelfex("register");
  39. addSelfex("unregister");
  40. addMutex(new String[] {"register", "unregister", "getObjects"});
  41. addMutex(new String[] {"register", "unregister", "getShips"});
  42. }
  43. }