/interpreter/tags/at_build150307/src/edu/vub/at/actors/id/ATObjectID.java

http://ambienttalk.googlecode.com/ · Java · 114 lines · 47 code · 19 blank · 48 comment · 7 complexity · eb4fc0371376dbf560b20a6a584e073f MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * ATObjectID.java created on 21-dec-2006 at 12:04:03
  4. * (c) Programming Technology Lab, 2006 - 2007
  5. * Authors: Tom Van Cutsem & Stijn Mostinckx
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use,
  11. * copy, modify, merge, publish, distribute, sublicense, and/or
  12. * sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following
  14. * conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be
  17. * included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  21. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  23. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  24. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. * OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28. package edu.vub.at.actors.id;
  29. import edu.vub.at.actors.natives.ELVirtualMachine;
  30. import edu.vub.at.exceptions.InterpreterException;
  31. import edu.vub.at.objects.natives.OBJLexicalRoot;
  32. import java.io.Serializable;
  33. /**
  34. * An ATObjectID instance represents a globally unique identifier denoting
  35. * an AmbientTalk/2 object. It is represented by a triplet:
  36. * ( VM id, Host actor id, object id )
  37. *
  38. * @author tvcutsem
  39. */
  40. public class ATObjectID implements Serializable {
  41. private static final long serialVersionUID = -2108704271907943887L;
  42. // Virtual Machines are identified by IP address + port
  43. private final GUID virtualMachineId_;
  44. // Inside a Virtual Machine actors (which accept the messages for this far object)
  45. // are denoted by their hashcode
  46. private final int actorId_;
  47. // Inside an NATActorMirror, objects are denoted by their hashcode
  48. private final int objectId_;
  49. public ATObjectID(GUID vmId, int actorId, int objectId) {
  50. virtualMachineId_ = vmId;
  51. actorId_ = actorId;
  52. objectId_ = objectId;
  53. }
  54. /*
  55. * Three cases to consider:
  56. * an object can be:
  57. * - local to an actor (isFar -> false, isRemote -> false)
  58. * - hosted by another local actor (isFar -> true, isRemote -> false)
  59. * - hosted by a remote actor (isFar -> true, isRemote -> true)
  60. */
  61. public boolean isFar() throws InterpreterException {
  62. return (actorId_ != OBJLexicalRoot._INSTANCE_.base_getActor().hashCode());
  63. }
  64. public boolean isRemote() {
  65. return (!virtualMachineId_.equals(ELVirtualMachine.currentVM().getGUID()));
  66. }
  67. /* -----------------------
  68. * -- Structural Access --
  69. * ----------------------- */
  70. public int getActorId() {
  71. return actorId_;
  72. }
  73. public int getObjectId() {
  74. return objectId_;
  75. }
  76. public GUID getVirtualMachineId() {
  77. return virtualMachineId_;
  78. }
  79. public int hashCode() {
  80. return virtualMachineId_.hashCode() | actorId_ | objectId_;
  81. }
  82. public boolean equals(Object other) {
  83. if (other instanceof ATObjectID) {
  84. ATObjectID id = (ATObjectID) other;
  85. return (id.getVirtualMachineId().equals(virtualMachineId_)
  86. && (id.getActorId() == actorId_)
  87. && (id.getObjectId() == objectId_));
  88. } else {
  89. return false;
  90. }
  91. }
  92. public String toString() {
  93. return virtualMachineId_.toString() + ":" + actorId_ + ":" + objectId_;
  94. }
  95. }