/interpreter/tags/at2dist041108/src/edu/vub/at/actors/natives/ELActor.java

http://ambienttalk.googlecode.com/ · Java · 564 lines · 298 code · 46 blank · 220 comment · 14 complexity · cd8b77c9daa2b9e8a42b0f9cc634bd61 MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * ELActor.java created on 27-dec-2006 at 16:17:23
  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.natives;
  29. import edu.vub.at.actors.ATActorMirror;
  30. import edu.vub.at.actors.ATAsyncMessage;
  31. import edu.vub.at.actors.ATFarReference;
  32. import edu.vub.at.actors.eventloops.BlockingFuture;
  33. import edu.vub.at.actors.eventloops.Callable;
  34. import edu.vub.at.actors.eventloops.Event;
  35. import edu.vub.at.actors.eventloops.EventLoop;
  36. import edu.vub.at.actors.id.ATObjectID;
  37. import edu.vub.at.actors.id.ActorID;
  38. import edu.vub.at.actors.net.comm.Address;
  39. import edu.vub.at.eval.Evaluator;
  40. import edu.vub.at.exceptions.InterpreterException;
  41. import edu.vub.at.exceptions.XClassNotFound;
  42. import edu.vub.at.exceptions.XIOProblem;
  43. import edu.vub.at.exceptions.XIllegalOperation;
  44. import edu.vub.at.exceptions.XObjectOffline;
  45. import edu.vub.at.objects.ATAbstractGrammar;
  46. import edu.vub.at.objects.ATContext;
  47. import edu.vub.at.objects.ATMethod;
  48. import edu.vub.at.objects.ATObject;
  49. import edu.vub.at.objects.ATTable;
  50. import edu.vub.at.objects.ATTypeTag;
  51. import edu.vub.at.objects.mirrors.Reflection;
  52. import edu.vub.at.objects.natives.NATContext;
  53. import edu.vub.at.objects.natives.NATObject;
  54. import edu.vub.at.objects.natives.NATTable;
  55. import edu.vub.at.objects.natives.OBJLexicalRoot;
  56. import edu.vub.at.objects.symbiosis.Symbiosis;
  57. import edu.vub.at.util.logging.Logging;
  58. import java.lang.reflect.InvocationTargetException;
  59. import java.lang.reflect.Method;
  60. import java.util.EventListener;
  61. /**
  62. * An instance of the class ELActor represents a programmer-defined
  63. * AmbientTalk/2 actor. The event queue of the actor event loop serves as the
  64. * actor's 'meta-level' queue.
  65. *
  66. * The events in the 'meta-level' queue are handled by the actor's mirror object.
  67. * This mirror is normally an instance of NATActorMirror, but it can be any
  68. * programmer-defined object that adheres to the ATActorMirror interface.
  69. *
  70. * @author tvcutsem
  71. */
  72. public class ELActor extends EventLoop {
  73. /**
  74. * A thread-local variable that contains the 'default actor' to use
  75. * when there is currently no ELActor event loop thread running.
  76. * This is primarily useful for performing unit tests where an actor
  77. * is automatically created when actor semantics is required.
  78. *
  79. * A warning is printed to the log because using the default actor should
  80. * only be used for testing purposes.
  81. */
  82. private static final ThreadLocal _DEFAULT_ACTOR_ = new ThreadLocal() {
  83. protected synchronized Object initialValue() {
  84. Logging.Actor_LOG.warn("Creating a default actor for thread " + Thread.currentThread());
  85. try {
  86. ELVirtualMachine host = new ELVirtualMachine(
  87. Evaluator.getNil(),
  88. new SharedActorField[] { },
  89. ELVirtualMachine._DEFAULT_GROUP_NAME_);
  90. return host.createEmptyActor().getFarHost();
  91. } catch (InterpreterException e) {
  92. throw new RuntimeException("Failed to initialize default actor: " + e.getMessage());
  93. }
  94. }
  95. };
  96. /**
  97. * Retrieves the currently running actor. If there is no running actor thread,
  98. * this returns the value stored in the thread-local default actor field.
  99. */
  100. public static final ELActor currentActor() {
  101. try {
  102. return ((ELActor) EventLoop.currentEventLoop());
  103. } catch (ClassCastException e) {
  104. // current event loop is not an actor event loop
  105. } catch (IllegalStateException e) {
  106. // current thread is not an event loop
  107. }
  108. Logging.Actor_LOG.warn("Asked for an actor in non-actor thread " + Thread.currentThread());
  109. return (ELActor) _DEFAULT_ACTOR_.get();
  110. }
  111. private ATActorMirror mirror_;
  112. private final ActorID id_;
  113. protected final ELVirtualMachine host_;
  114. protected final ReceptionistsSet receptionists_;
  115. /*
  116. * This object is created when the actor is initialized: i.e. it is the passed
  117. * version of the isolate that was passed to the actor: primitive by the creating actor.
  118. */
  119. private NATObject behaviour_;
  120. public ELActor(ATActorMirror mirror, ELVirtualMachine host) {
  121. super("actor " + mirror.toString());
  122. id_ = new ActorID();
  123. mirror_ = mirror;
  124. host_ = host;
  125. receptionists_ = new ReceptionistsSet(this);
  126. }
  127. /** constructor dedicated to initialization of discovery actor */
  128. protected ELActor(ELVirtualMachine host) {
  129. super("discovery actor");
  130. id_ = new ActorID();
  131. mirror_ = new NATActorMirror(host);
  132. host_ = host;
  133. receptionists_ = new ReceptionistsSet(this);
  134. }
  135. /**
  136. * Actor event loops handle events by allowing the meta-level events to
  137. * process themselves.
  138. */
  139. public void handle(Event event) {
  140. event.process(mirror_);
  141. }
  142. public ATActorMirror getImplicitActorMirror() { return mirror_; }
  143. public void setActorMirror(ATActorMirror mirror) { mirror_ = mirror; }
  144. public ELVirtualMachine getHost() {
  145. return host_;
  146. }
  147. public ActorID getActorID() {
  148. return id_;
  149. }
  150. public Thread getExecutor() {
  151. return processor_;
  152. }
  153. /**
  154. * Takes offline a given remote object such that it is no longer remotely accessible.
  155. * @param object a **far?** reference to the object to export
  156. * @throws XIllegalOperation if the passed object is not part of the export table - i.e. non-remotely accessible.
  157. */
  158. public void takeOffline(ATObject object) throws InterpreterException {
  159. // receptionist set will check whether ATObject is really remote to me
  160. receptionists_.takeOfflineObject(object);
  161. }
  162. /**
  163. * Resolve the given object id into a local reference. There are three cases to
  164. * consider:
  165. * A) The given id designates an object local to this actor: the returned object
  166. * will be a **near** reference to the object (i.e. the object itself)
  167. * B) The given id designates a far (non-local) object that lives in the same
  168. * address space as this actor: the returned object wil be a **far** reference
  169. * to the object.
  170. * C) The given id designates a far object that lives on a remote machine: the
  171. * returned object will be a **far** and **remote** reference to the object.
  172. *
  173. * @param id the identifier of the object to resolve
  174. * @return a near or far reference to the object, depending on where the designated object lives
  175. */
  176. public ATObject resolve(ATObjectID id, ATTypeTag[] types) throws XObjectOffline {
  177. return receptionists_.resolveObject(id, types);
  178. }
  179. /* -----------------------------
  180. * -- Initialisation Protocol --
  181. * ----------------------------- */
  182. /**
  183. * Initialises the root using the contents of the init file stored by
  184. * the hosting virtual machine.
  185. * @throws InterpreterException
  186. */
  187. protected void initRootObject() throws InterpreterException {
  188. ATAbstractGrammar initialisationCode = host_.getInitialisationCode();
  189. // evaluate the initialization code in the context of the global scope
  190. NATObject globalScope = Evaluator.getGlobalLexicalScope();
  191. NATContext initCtx = new NATContext(globalScope, globalScope);
  192. initialisationCode.meta_eval(initCtx);
  193. }
  194. /**
  195. * Initialises various fields in the lexical root of the actor, which are defined in the
  196. * context of every actor. Candidates are a "system" field which allows the program to
  197. * perform IO operations or a "~" field denoting the current working directory.
  198. *
  199. * @throws InterpreterException when initialisation of a field fails
  200. */
  201. protected void initSharedFields() throws InterpreterException {
  202. SharedActorField[] fields = host_.getFieldsToInitialize();
  203. NATObject globalScope = Evaluator.getGlobalLexicalScope();
  204. for (int i = 0; i < fields.length; i++) {
  205. SharedActorField field = fields[i];
  206. ATObject value = field.initialize();
  207. if (value != null) {
  208. globalScope.meta_defineField(field.getName(), value);
  209. }
  210. }
  211. }
  212. // Events to be processed by the actor event loop
  213. /**
  214. * The initial event sent by the actor mirror to its event loop to intialize itself.
  215. * @param future the synchronization point with the creating actor, needs to be fulfilled with a far ref to the behaviour.
  216. * @param parametersPkt the serialized parameters for the initialization code
  217. * @param initcodePkt the serialized initialization code (e.g. the code in 'actor: { code }')
  218. */
  219. protected void event_init(final BlockingFuture future, final Packet parametersPkt, final Packet initcodePkt) {
  220. receive(new Event("init("+this+")") {
  221. public void process(Object byMyself) {
  222. try {
  223. behaviour_ = new NATObject();
  224. // pass far ref to behaviour to creator actor who is waiting for this
  225. future.resolve(receptionists_.exportObject(behaviour_,"behaviour of "+byMyself));
  226. // !! WARNING: the following code is also duplicated in
  227. // ELDiscoveryActor's event_init. If this code is modified, don't
  228. // forget to modify that of the discovery actor as well !!
  229. // initialize lexically visible fields
  230. initSharedFields();
  231. // go on to initialize the root and all lexically visible fields
  232. initRootObject();
  233. ATObject params = parametersPkt.unpack();
  234. ATMethod initCode = initcodePkt.unpack().asMethod();
  235. if (!params.isTable()) {
  236. // actor initialized as actor: { ... } => free vars automatically added to a private lexical scope
  237. // in this case, params refers to an object that will play the role of lexical scope of the actor's behaviour
  238. params.asAmbientTalkObject().setLexicalParent(Evaluator.getGlobalLexicalScope());
  239. behaviour_.setLexicalParent(params);
  240. params = NATTable.EMPTY;
  241. }/* else {
  242. // actor initialized as actor: { |vars| ... } => vars become publicly accessible in the actor
  243. }*/
  244. // initialize the behaviour using the parameters and the code
  245. try {
  246. initCode.base_applyInScope(params.asTable(), new NATContext(behaviour_, behaviour_));
  247. } catch (InterpreterException e) {
  248. System.out.println(">>> Exception while initializing actor " + Evaluator.trunc(initCode.base_bodyExpression().toString(),20) + ":\n"+e.getMessage());
  249. e.printAmbientTalkStackTrace(System.out);
  250. Logging.Actor_LOG.error(behaviour_ + ": could not initialize actor behaviour", e);
  251. }
  252. } catch (InterpreterException e) {
  253. System.out.println(">>> Exception while creating actor: " + e.getMessage());
  254. e.printAmbientTalkStackTrace(System.out);
  255. Logging.Actor_LOG.error(behaviour_ + ": could not initialize actor behaviour", e);
  256. }
  257. }
  258. });
  259. }
  260. /**
  261. * The main entry point for any asynchronous self-sends.
  262. * Asynchronous self-sends (i.e. intra-actor sends) do not undergo any form of parameter passing,
  263. * there is no need to serialize and deserialize the message parameter in a Packet.
  264. *
  265. * When an actor receives an asynchronous message for a given receiver, it delegates control
  266. * to the message itself by means of the message's <tt>process</tt> method.
  267. * @throws InterpreterException
  268. */
  269. public void acceptSelfSend(final ATObject receiver, final ATAsyncMessage msg) throws InterpreterException {
  270. // This is the only place where messages are scheduled
  271. // The receiver is always a local object, receive has
  272. // already been invoked.
  273. mirror_.base_schedule(receiver, msg);
  274. // signal a serve event for every message that is accepted
  275. this.event_serve();
  276. }
  277. /**
  278. * The main entry point for any asynchronous messages sent to this actor
  279. * by external sources.
  280. * @param sender address of the sending actor, used to notify when the receiver has gone offline.
  281. * @param serializedMessage the asynchronous AmbientTalk base-level message to enqueue
  282. */
  283. public void event_remoteAccept(final Address sender, final Packet serializedMessage) {
  284. receive(new Event("remoteAccept("+serializedMessage+")") {
  285. public void process(Object myActorMirror) {
  286. try {
  287. // receive a pair [receiver, message]
  288. ATObject[] pair = serializedMessage.unpack().asNativeTable().elements_;
  289. ATObject receiver = pair[0];
  290. ATAsyncMessage msg = pair[1].asAsyncMessage();
  291. performAccept(receiver, msg);
  292. } catch (XObjectOffline e) {
  293. host_.event_objectTakenOffline(e.getObjectId(), sender);
  294. Logging.Actor_LOG.error(mirror_ + ": error unpacking "+ serializedMessage, e);
  295. } catch (InterpreterException e) {
  296. Logging.Actor_LOG.error(mirror_ + ": error unpacking "+ serializedMessage, e);
  297. }
  298. }
  299. });
  300. }
  301. /**
  302. * The main entry point for any asynchronous messages sent to this actor
  303. * by local actors.
  304. * @param ref the local reference of the sending actor, used to notify when the receiver has gone offline.
  305. * @param serializedMessage the asynchronous AmbientTalk base-level message to enqueue
  306. */
  307. public void event_localAccept(final NATLocalFarRef ref, final Packet serializedMessage) {
  308. receive(new Event("localAccept("+serializedMessage+")") {
  309. public void process(Object myActorMirror) {
  310. try {
  311. // receive a pair [receiver, message]
  312. ATObject[] pair = serializedMessage.unpack().asNativeTable().elements_;
  313. ATObject receiver = pair[0];
  314. ATAsyncMessage msg = pair[1].asAsyncMessage();
  315. performAccept(receiver, msg);
  316. } catch (XObjectOffline e) {
  317. ref.notifyTakenOffline();
  318. Logging.Actor_LOG.error(mirror_ + ": error unpacking "+ serializedMessage, e);
  319. } catch (InterpreterException e) {
  320. Logging.Actor_LOG.error(mirror_ + ": error unpacking "+ serializedMessage, e);
  321. }
  322. }
  323. });
  324. }
  325. public void event_serve() {
  326. receive(new Event("serve()") {
  327. public void process(Object myActorMirror) {
  328. try {
  329. ATObject result = mirror_.base_serve();
  330. Logging.Actor_LOG.debug(mirror_ + ": serve() returned " + result);
  331. } catch (InterpreterException e) {
  332. System.out.println(">>> Exception in actor " + myActorMirror + ": "+e.getMessage());
  333. e.printAmbientTalkStackTrace(System.out);
  334. Logging.Actor_LOG.error(mirror_ + ": serve() failed ", e);
  335. }
  336. }
  337. });
  338. }
  339. private void performAccept(ATObject receiver, ATAsyncMessage msg) {
  340. try {
  341. ATObject result = mirror_.base_receive(receiver, msg);
  342. Logging.Actor_LOG.debug(mirror_ + ": scheduling "+ msg + " returned " + result);
  343. // signal a serve event for every message that is accepted
  344. event_serve();
  345. } catch (InterpreterException e) {
  346. System.out.println(">>> Exception in actor " + getImplicitActorMirror() + ": "+e.getMessage());
  347. e.printAmbientTalkStackTrace(System.out);
  348. Logging.Actor_LOG.error(mirror_ + ": scheduling "+ msg + " failed ", e);
  349. }
  350. }
  351. /**
  352. * This method is invoked by a coercer in order to schedule a purely asynchronous symbiotic invocation
  353. * from the Java world.
  354. *
  355. * This method schedules the call for asynchronous execution. Its return value and or raised exceptions
  356. * are ignored. This method should only be used for {@link Method} objects whose return type is <tt>void</tt>
  357. * and whose declaring class is a subtype of {@link EventListener}. It represents asynchronous method
  358. * invocations from the Java world to the AmbientTalk world.
  359. *
  360. * @param principal the AmbientTalk object owned by this actor on which to invoke the method
  361. * @param method the Java method that was symbiotically invoked on the principal
  362. * @param args the arguments to the Java method call, already converted into AmbientTalk values
  363. */
  364. public void event_symbioticInvocation(final ATObject principal, final Method method, final ATObject[] args) {
  365. receive(new Event("asyncSymbioticInv of "+method.getName()) {
  366. public void process(Object actorMirror) {
  367. try {
  368. Reflection.downInvocation(principal, method, args);
  369. } catch (InterpreterException e) {
  370. System.out.println(">>> Exception in actor " + actorMirror + ": "+e.getMessage());
  371. e.printAmbientTalkStackTrace(System.out);
  372. Logging.Actor_LOG.error("asynchronous symbiotic invocation of "+method.getName()+" failed", e);
  373. }
  374. }
  375. });
  376. }
  377. /**
  378. * This method is invoked by a coercer in order to schedule a symbiotic invocation
  379. * from the Java world, which should be synchronous to the Java thread, but which
  380. * must be scheduled asynchronously to comply with the AT/2 actor model.
  381. *
  382. * The future returned by this method makes the calling (Java) thread <b>block</b> upon
  383. * accessing its value, waiting until the actor has processed the symbiotic invocation.
  384. *
  385. * @param principal the AmbientTalk object owned by this actor on which to invoke the method
  386. * @param meth the Java method that was symbiotically invoked on the principal
  387. * @param args the arguments to the Java method call, already converted into AmbientTalk values
  388. * @return a Java future that is resolved with the result of the symbiotic invocation
  389. * @throws Exception if the symbiotic invocation fails
  390. */
  391. public BlockingFuture sync_event_symbioticInvocation(final ATObject principal, final Method meth, final ATObject[] args) throws Exception {
  392. return receiveAndReturnFuture("syncSymbioticInv of " + meth.getName(), new Callable() {
  393. public Object call(Object actorMirror) throws Exception {
  394. Class targetType = meth.getReturnType();
  395. ATObject[] actualArgs = args;
  396. // if the return type is BlockingFuture, the first argument should specify the type
  397. // of the value with which BlockingFuture will be resolved
  398. if (targetType.equals(BlockingFuture.class)) {
  399. if ((meth.getParameterTypes().length > 0) && (meth.getParameterTypes()[0].equals(Class.class))) {
  400. targetType = args[0].asJavaClassUnderSymbiosis().getWrappedClass();
  401. // drop first argument, it only exists to specify the targetType
  402. ATObject[] newArgs = new ATObject[args.length-1];
  403. System.arraycopy(args, 1, newArgs, 0, newArgs.length);
  404. actualArgs = newArgs;
  405. }
  406. }
  407. ATObject result = Reflection.downInvocation(principal, meth, actualArgs);
  408. // SUPPORT FOR FUTURES
  409. if (Symbiosis.isAmbientTalkFuture(result)) {
  410. Logging.Actor_LOG.debug("Symbiotic futures: symbiotic call to " + meth.getName() + " returned an AT future");
  411. return Symbiosis.ambientTalkFutureToJavaFuture(result, targetType);
  412. } else {
  413. // return the proper value immediately
  414. return Symbiosis.ambientTalkToJava(result, targetType);
  415. }
  416. }
  417. });
  418. }
  419. /**
  420. * This method is invoked by a coercer in order to schedule a symbiotic invocation
  421. * of a method from java.lang.Object from the Java world, which should be synchronous
  422. * to the Java thread, but which
  423. * must be scheduled asynchronously to comply with the AT/2 actor model.
  424. *
  425. * The future returned by this method makes the calling (Java) thread <b>block</b> upon
  426. * accessing its value, waiting until the actor has processed the symbiotic invocation.
  427. *
  428. * Note: the parameter meth must be a method declared on the class java.lang.Object
  429. * (i.e. toString, hashCode and equals). The invocation is simply forwarded directly
  430. * to the principal with no conversion to an AmbientTalk invocation.
  431. *
  432. * @param principal the AmbientTalk object owned by this actor on which to invoke the method
  433. * @param meth the Java method that was symbiotically invoked on the principal
  434. * @param args the arguments to the Java method call, already converted into AmbientTalk values
  435. * @return a Java future that is resolved with the result of the symbiotic invocation
  436. * @throws Exception if the symbiotic invocation fails
  437. */
  438. public BlockingFuture sync_event_symbioticForwardInvocation(final ATObject principal, final Method meth, final Object[] args) throws Exception {
  439. return receiveAndReturnFuture("syncSymbioticInv of " + meth.getName(), new Callable() {
  440. public Object call(Object actorMirror) throws Exception {
  441. try {
  442. return meth.invoke(principal, args);
  443. } catch (InvocationTargetException e) {
  444. if (e instanceof Exception) {
  445. throw (Exception) e.getTargetException();
  446. } else {
  447. throw e;
  448. }
  449. }
  450. }
  451. });
  452. }
  453. /**
  454. * This method should only be used for purposes such as the IAT shell or unit testing.
  455. * It allows an external thread to make this actor evaluate an arbitrary expression.
  456. *
  457. * @param ast an abstract syntax tree to be evaluated by the receiving actor (in the
  458. * scope of its behaviour).
  459. * @return the result of the evaluation
  460. * @throws InterpreterException if the evaluation fails
  461. */
  462. public ATObject sync_event_eval(final ATAbstractGrammar ast) throws InterpreterException {
  463. try {
  464. return (ATObject) receiveAndWait("nativeEval("+ast+")", new Callable() {
  465. public Object call(Object inActor) throws Exception {
  466. return OBJLexicalRoot._INSTANCE_.base_eval_in_(ast, behaviour_);
  467. }
  468. });
  469. } catch (Exception e) {
  470. if (e instanceof InterpreterException) {
  471. throw (InterpreterException) e;
  472. } else {
  473. Logging.Actor_LOG.fatal("Unexpected Java exception: "+e.getMessage(), e);
  474. throw new RuntimeException("Unexpected exception: "+e);
  475. }
  476. }
  477. }
  478. /**
  479. * This method should only be used for purposes of unit testing. It allows
  480. * arbitary code to be scheduled by external threads such as unit testing frameworks.
  481. */
  482. public Object sync_event_performTest(Callable c) throws Exception {
  483. return (ATObject) receiveAndWait("performTest("+c+")", c);
  484. }
  485. /**
  486. * When the discovery manager receives a publication from another local actor or
  487. * another remote VM, the actor is asked to compare the incoming publication against
  488. * a subscription that it had announced previously.
  489. *
  490. * @param requiredTypePkt serialized form of the type attached to the actor's subscription
  491. * @param myHandler the closure specified as a handler for the actor's subscription
  492. * @param discoveredTypePkt serialized form of the type attached to the new publication
  493. * @param remoteServicePkt serialized form of the reference to the remote discovered service
  494. */
  495. public void event_serviceJoined(final Packet requiredTypePkt, final ATFarReference myHandler,
  496. final Packet discoveredTypePkt, final Packet remoteServicePkt) {
  497. receive(new Event("serviceJoined") {
  498. public void process(Object myActorMirror) {
  499. try {
  500. ATTypeTag requiredType = requiredTypePkt.unpack().asTypeTag();
  501. ATTypeTag discoveredType = discoveredTypePkt.unpack().asTypeTag();
  502. // is there a match?
  503. if (discoveredType.base_isSubtypeOf(requiredType).asNativeBoolean().javaValue) {
  504. ATObject remoteService = remoteServicePkt.unpack();
  505. // myhandler<-apply([remoteService])@[]
  506. Evaluator.trigger(myHandler, NATTable.of(remoteService));
  507. }
  508. } catch (XIOProblem e) {
  509. Logging.Actor_LOG.error("Error deserializing joined types or services: ", e.getCause());
  510. } catch (XClassNotFound e) {
  511. Logging.Actor_LOG.fatal("Could not find class while deserializing joined types or services: ", e.getCause());
  512. } catch (InterpreterException e) {
  513. Logging.Actor_LOG.error("Error while joining services: ", e);
  514. }
  515. }
  516. });
  517. }
  518. }