Skip to content

Cleanup SubScriptActor.registerHandler #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AndreVanDelft opened this issue Jun 10, 2016 · 4 comments
Open

Cleanup SubScriptActor.registerHandler #48

AndreVanDelft opened this issue Jun 10, 2016 · 4 comments

Comments

@AndreVanDelft
Copy link
Contributor

In SubScriptActor:

    registerHandler(act: Either[ActorRef, ActualAdaptingParameter[ActorRef]]) =
      val vt         = new Trigger  // The value sent from `act` will pop from `vt` and will be
                                // returned from this script to be handled by the parent dataflow
      val handlerFun = here.ancestor(9).getProperty[String, PartialFunction[Any, Script[Any]]]("then").get  
          // PartialFunction from the dataflow this `act` is LHS of. 
          // Will handle the matching messages. 
          // TBD: ancestor(n) should be replaced by a more descriptive methods, 
          // no guessing on the argument `n` should be done.
      val handler    = (act, vt, handlerFun)  // Everything together

      do! handlers += handler  // Save the actor, the trigger and the handler function of the dataflow
      [vt ~~(msg)~~> [do! handlers -= handler; ^msg]]^  
      // Wait for a suitable message to pop from `vt`, 
      // then deregister the handler and return the message 
      // to be handled normally by the dataflow.

The purpose is to make sure only those handlers will execute that are LHS in a dataflow that expects the received actor message.
The code that does that test should be made more generic: a code fragment node should contain a method that tells whether a given value would match the contextual dataflow, in case there is such a data flow. That would be like the matches method in FormalConstrainedParameter. E.g. for usage see KeyTypedReactor.

Moreover, this line

      do! handlers += handler  // Save the actor, the trigger and the handler function of the dataflow

is IMO wrong: it makes an atomic action happen whereas we are only registrering. Probably this should be:

      let handlers += handler  // Save the actor, the trigger and the handler function of the dataflow
@AndreVanDelft
Copy link
Contributor Author

The current code has also 2 implicit scripts:

implicit script..
  actorRef2script(a: ActorRef)        = registerHandler(Left (  a))
  actorRefParam2script(??a: ActorRef) = registerHandler(Right(??a))

I wonder why there are 2 conversion scripts instead of one.
If I am right just the second would also implicitly convert plain ActorRef values; at least in the old compiler branch that resolved script calls. If this capability has been lost in the transition to the preprocessor, it should be brought back to life at some point.

@AndreVanDelft
Copy link
Contributor Author

AndreVanDelft commented Aug 1, 2016

The definition of registerHandler mentions an ActualAdaptingParameter in its parameter list.
Now type ActualAdaptingParameter is meant for actual parameter positions; if you want to make an extra refinement such as registerHandler, do it like this:

  registerHandler(act: FormalConstrainedParameter[ActorRef]]) = ...

(already dropped Either here).

@AndreVanDelft
Copy link
Contributor Author

AndreVanDelft commented Aug 1, 2016

If I am right we would need only the second conversion script.

But since we will only need one implicit script, as I assume, we do not need this extra refinement.
The “do!” is misplaced, since it should not be an action here, possibly excluding other actions.

implicit script..
  actorRefParam2script(??a: ActorRef): Any = 
    val vt         = new Trigger  // The value sent from `act` will pop from `vt` 
                                  // and will be returned from this script to be handled by the parent dataflow
    val handlerFun = here.ancestor(9).getProperty[String, PartialFunction[Any, Script[Any]]]("then").get  
          // PartialFunction from the dataflow this `act` is LHS of. 
          //  Will handle the matching messages. 
          // TBD: ancestor(n) should be replaced by a more descriptive methods, 
          // no guessing on the argument `n` should be done.
    val handler    = (act, vt, handlerFun)  // Everything together
    @{there.  onActivate{handlers += handler}
      there.onDeactivate{handlers -= handler}}: vt

@AndreVanDelft
Copy link
Contributor Author

For the Scala Symposium 2016 paper, I assume that we can replace

val handlerFun = here.ancestor(9).getProperty[String, PartialFunction[Any, Script[Any]]]("then").get

by

val handlerFun = here.getContextualDataflowHandler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant