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.

GameSynchronization.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 Game in the
  19. * presence of several threads.
  20. *
  21. * It uses the Coordinator class, from the AspectJ coordination library.
  22. * (This case is right on the borderline of being too simple to use the
  23. * coordination library, but we use it anyways to keep the similarity
  24. * with the RegistrySynchronizer.)
  25. *
  26. * It uses a per-Game coordination scheme, so there is one instance of
  27. * this class for each instance of the Game class. When this class is
  28. * constructed, it registers appropriate mutexes and selfexes using
  29. * the behavior inherited from Coordinator.
  30. *
  31. * The coordination constraints for the Game are simple. We just need to
  32. * make sure that newShip and handleCollisions are mutually exclusive. That
  33. * ensures that they we can't destroy a ship that has just been replaced.
  34. */
  35. aspect GameSynchronization extends Coordinator perthis(this(Game)) {
  36. protected pointcut synchronizationPoint():
  37. call(void Game.handleCollisions(..)) || call(Ship Game.newShip(..));
  38. public GameSynchronization() {
  39. addMutex(new String[] {"handleCollisions", "newShip"});
  40. }
  41. }