/interpreter/tags/at2dist110511/src/edu/vub/at/actors/ATActorMirror.java

http://ambienttalk.googlecode.com/ · Java · 230 lines · 27 code · 23 blank · 180 comment · 0 complexity · e50aeac2dd585a22c1b9916e0f7f6927 MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * ATActorMirror.java created on Aug 21, 2006
  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;
  29. import edu.vub.at.exceptions.InterpreterException;
  30. import edu.vub.at.exceptions.XIllegalOperation;
  31. import edu.vub.at.objects.ATBoolean;
  32. import edu.vub.at.objects.ATClosure;
  33. import edu.vub.at.objects.ATNil;
  34. import edu.vub.at.objects.ATObject;
  35. import edu.vub.at.objects.ATTypeTag;
  36. import edu.vub.at.objects.ATTable;
  37. import edu.vub.at.objects.grammar.ATSymbol;
  38. /**
  39. * The class ATActorMirror prescribes the minimal set of methods to be provided by the default
  40. * implementation of an actor mirror. Since new actor mirrors can be installed dynamically,
  41. * ATActorMirror defines the dependencies of the lexically scoped objects on the dynamic 'actor
  42. * context' to perform their duties. The hooks defined in this class relate to:
  43. *
  44. * <ul>
  45. * <li>Asynchronous message creation and sending to influence the communication protocol</li>
  46. * <li>Service advertising and requesting to influence the service discovery protocol</li>
  47. * <li>Mirror creation to provide support for true stratification</li>
  48. * <li>Actor protocol installation to deal with actor mirror interaction and to allow freezing
  49. * an actor with a given protocol</li>
  50. * </ul>
  51. *
  52. * @author smostinc
  53. */
  54. public interface ATActorMirror extends ATObject {
  55. /* ---------------------------------------------------
  56. * -- Language Construct to NATActorMirror Protocol --
  57. * --------------------------------------------------- */
  58. /**
  59. * Creates a first-class message in the language. Note that upon creation the
  60. * message does not have a receiver yet. This field will be set once the message
  61. * is actually being sent, a fact which can be intercepted by overriding the sendTo
  62. * base-level method.
  63. *
  64. * @param selector the name of the method to trigger remotely
  65. * @param arguments the actual arguments of the message
  66. * @param types the types with which the message will be born
  67. */
  68. public ATAsyncMessage base_createMessage(ATSymbol selector, ATTable arguments, ATTable types) throws InterpreterException;
  69. /**
  70. * Creates a mirror on the given object. This method serves as the 'mirror factory'
  71. * for the current actor.
  72. */
  73. public ATObject base_createMirror(ATObject onObject) throws InterpreterException;
  74. /**
  75. * This method implements the default asynchronous message sending semantics for
  76. * this particular actor. In addition to the ability to override the send meta-
  77. * operation on a single object to have specific adaptions, this hook allows the
  78. * programmer to modify the message sending semantics for all objects inside an
  79. * actor. The default implementation ensures the correct passing of messages when
  80. * they transgress the boundaries of the sending actor.
  81. *
  82. * @throws InterpreterException
  83. */
  84. public ATObject base_send(ATObject receiver, ATAsyncMessage message) throws InterpreterException;
  85. /**
  86. * When an actor receives an asynchronous message for a given receiver, it will delegate this
  87. * to the meta-level 'receive' operation of the designated object. This operation is introduced
  88. * as a mechanism to alter the semantics of message reception for all objects contained in an
  89. * actor. It can be used e.g. to keep track of all succesfully processed messages.
  90. */
  91. public ATObject base_receive(ATObject receiver, ATAsyncMessage message) throws InterpreterException;
  92. /**
  93. * This method provides access to a snapshot of the inbox of an actor. It is however not causally
  94. * connected to the inbox; adding/removing elements to/from this snapshot will not affect the inbox of
  95. * the actor.
  96. * @return a table containing all letters that are scheduled to be processed
  97. */
  98. public ATTable base_listIncomingLetters() throws InterpreterException;
  99. /**
  100. * This mechanism allows for changing the scheduling semantics of the actor's inbox.
  101. * Note: this method is responsible for calling the <tt>serve()</tt> method for each
  102. * scheduled message, which should be executed at a later point in time.
  103. *
  104. * @return a letter, which can be canceled again
  105. */
  106. public ATObject base_schedule(ATObject receiver, ATAsyncMessage message) throws InterpreterException;
  107. /**
  108. * This method fetches and processes the next letter from the inbox.
  109. * It should take into account the possibility that the inbox is empty.
  110. */
  111. public ATObject base_serve() throws InterpreterException;
  112. /**
  113. * This method provides access to a snapshot of the current published services of an actor.
  114. * The result is not causally connected; adding/removing elements to/from this snapshot will
  115. * not affect the current publications.
  116. * @return a table containing all publications of this actor
  117. */
  118. public ATTable base_listPublications() throws InterpreterException;
  119. /**
  120. * This method provides access to a snapshot of the current subscriptions of an actor.
  121. * The result is not causally connected; adding/removing elements to/from this snapshot will
  122. * not affect the current subscriptions.
  123. * @return a table containing all subscriptions of this actor
  124. */
  125. public ATTable base_listSubscriptions() throws InterpreterException;
  126. /**
  127. * This mechanism is the most basic mechanism to provide a service. It requires
  128. * a separate service description and an object offering the service. The return
  129. * value is a publication object which allows cancelling the service offer.
  130. */
  131. public ATObject base_provide(ATTypeTag topic, ATObject service) throws InterpreterException;
  132. /**
  133. * This mechanism is the most basic mechanism to require a service. The return
  134. * value is a subscription object which allows cancelling the service offer.
  135. * @param bool - if true, the subscription is permanent, if false, once the subscription
  136. * has been satisfied, it is automatically cancelled.
  137. */
  138. public ATObject base_require(ATTypeTag topic, ATClosure handler, ATBoolean bool) throws InterpreterException;
  139. /**
  140. * Create a far reference to a local object. Custom actor mirrors may override
  141. * this method in order to return different kinds of object references, e.g.
  142. * leased object references.
  143. *
  144. * @param toObject a **near** reference to the object to export
  145. * @return a local far reference to the object being exported
  146. * @throws XIllegalOperation if the passed object is a far reference, i.e. non-local
  147. */
  148. public ATObject base_createReference(ATObject toObject) throws InterpreterException;
  149. /**
  150. * def oldprotocol := actor.becomeMirroredBy: newprotocol
  151. *
  152. * Installs a new meta-object protocol into this actor.
  153. *
  154. * @param protocol meta-level code that overrides an actor's MOP methods
  155. * @return the previously installed meta-object protocol
  156. */
  157. public ATObject base_becomeMirroredBy_(ATActorMirror protocol) throws InterpreterException;
  158. /**
  159. * def aM := implicitActorMirror.getExplicitActorMirror()
  160. *
  161. * This method serves as the 'mirror factory' for explicit actor mirrors.
  162. *
  163. * @return an explicit actor mirror for the current actor.
  164. */
  165. public ATActorMirror base_getExplicitActorMirror() throws InterpreterException;
  166. /**
  167. * Provides access to this actor's "behaviour" object. This is the first
  168. * object created within an actor.
  169. *
  170. * Note: if the behaviour is accessed when evaluating the "init.at" initialization
  171. * file of an actor, the behaviour will <em>not have been initialized</em> yet.
  172. * It will appear as an empty object.
  173. */
  174. public ATObject base_behaviour() throws InterpreterException;
  175. /* -------------------------------------
  176. * -- Object Passing Protocol Support --
  177. * ------------------------------------- */
  178. /**
  179. * This mechanism interacts with the built-in receptionists set of the actor to
  180. * produce a new far object reference to a local object. The created far object
  181. * is by no means unique within the actor that created it.
  182. *
  183. * Creating such far references is performed when passing objects by reference
  184. * in the meta_pass method of scoped objects such as closures, objects and fields.
  185. *
  186. * @param object the local object to be given a reference to
  187. * @return a newly created far object reference
  188. *
  189. * @see edu.vub.at.objects.ATObject#meta_pass(ATFarReference)
  190. */
  191. //public ATFarReference base_export(ATObject object) throws InterpreterException;
  192. /**
  193. * This mechanism interacts with the built-in receptionists set of the actor to
  194. * resolve far references (which were received as part of an async message). The
  195. * method returns a local object whenever the far object denotes an object
  196. * hosted by this actor.
  197. *
  198. * If the denoted object is not hosted by this actor, a far object (possibly but
  199. * not necessarily the passed one) is returned which is the local and unique
  200. * representative of the remote object. This object will contain the queue of
  201. * messages to be transmitted to the remote object.
  202. *
  203. * @param farReference the far reference to be resolved
  204. * @return a local object | a unique far reference for this actor
  205. */
  206. //public ATObject base_resolve(ATFarReference farReference) throws InterpreterException;
  207. }