Skip to content

Conversation

@yim-lee
Copy link
Member

@yim-lee yim-lee commented Feb 20, 2020

Motivation:
The current actor singleton implementation has some shortcomings as documented in #396.

Modifications:

  • Support for proxy-only mode (i.e., without specifying behavior)
  • Proper implementation for Actorables. Before we can only obtain Actorable that is singleton, now we can actually define an Actorable to be singleton.

Result:
Resolves #396.

Motivation:
The current actor singleton implementation has some shortcomings as documented in #396.

Modifications:
- Support for proxy-only mode (i.e., without specifying behavior)
- Proper implementation for Actorables. Before we can only obtain `Actorable` that is singleton, now we can actually define an `Actorable` to be singleton.

Result:
Resolves #396.
@yim-lee yim-lee requested a review from ktoso February 20, 2020 03:03
ref3.tell(.greet(name: "Charlie", _replyTo: replyProbe3.ref))

// Spawn the singleton on `fourth`
_ = try fourth.singleton.ref(of: GreeterSingleton.Message.self, settings: singletonSettings, GreeterSingleton.makeBehavior(instance: GreeterSingleton("Hello-4")))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to do this because of the changes. Is this annoying?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See API idea above, perhaps that would be the most clean...?

So here we could keep just doing ref() without passing the behavior

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we would need to call host actually to spawn the singleton because fourth will become the new leader. before this was done in system setup. just a trade-off between different implementations i guess.

/// - SeeAlso: The `ActorSingleton` mechanism is conceptually similar to Erlang/OTP's <a href="http://erlang.org/doc/design_principles/distributed_applications.html">`DistributedApplication`</a>,
/// and <a href="https://doc.akka.io/docs/akka/current/cluster-singleton.html">`ClusterSingleton` in Akka</a>.
public final class ActorSingletonPlugin {
private var singletons: [String: BoxedActorSingleton] = [:]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worry about this. This is mutable. Safe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to comment here -- yes this is not safe indeed...

We need to put a lock around accessing these and host() calls etc...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How I'd really want to write all this is (but it's too annoying I think, until we have async/await things):

let ref = await plugin.ref()

since then all of the mutable state can actually be put inside an actor, and we'd implement by "asking the plugin actor about the ref" rather than doing it here where we are not safe from concurrent access...

We could do this today but it gets too annoying, since it'd be like -> AskResponse<ActorRef<...>> which I think is annoying... :-(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use NIO's lock in this project or something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One API discussion I think... about if we should do ref()/actor() ONLY or ref()/actor() AND host()

ref3.tell(.greet(name: "Charlie", _replyTo: replyProbe3.ref))

// Spawn the singleton on `fourth`
_ = try fourth.singleton.ref(of: GreeterSingleton.Message.self, settings: singletonSettings, GreeterSingleton.makeBehavior(instance: GreeterSingleton("Hello-4")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See API idea above, perhaps that would be the most clean...?

So here we could keep just doing ref() without passing the behavior

@ktoso
Copy link
Member

ktoso commented Feb 21, 2020

Overall great though :-)

Time to also document it some more with those semantics perhaps as well...?
Would you be up for a docs PR follow up as well?

@yim-lee
Copy link
Member Author

yim-lee commented Feb 21, 2020

Would you be up for a docs PR follow up as well?

Sure. I believe you started some docs on it already if I remember correctly?

@ktoso
Copy link
Member

ktoso commented Feb 21, 2020

Sure. I believe you started some docs on it already if I remember correctly?

It's just a placeholder really, nothing really documented in there, see plugin_actor_singleton.adoc

@yim-lee
Copy link
Member Author

yim-lee commented Feb 21, 2020

see plugin_actor_singleton.adoc

okie, i will update it in follow-up PR

@ktoso
Copy link
Member

ktoso commented Feb 21, 2020

Yay, thanks a ton :) No rush about it though 👍

@yim-lee
Copy link
Member Author

yim-lee commented Feb 21, 2020

Failure is #463

@yim-lee
Copy link
Member Author

yim-lee commented Feb 21, 2020

New (unrelated) failure: #464

@yim-lee
Copy link
Member Author

yim-lee commented Feb 21, 2020

test this please

@ktoso
Copy link
Member

ktoso commented Feb 22, 2020

Thanks for the failed tickets, simple ones to follow up on.

This looks good!

@ktoso ktoso merged commit c549ec5 into apple:master Feb 22, 2020
@ktoso ktoso deleted the singleton branch February 22, 2020 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revisit UX for singleton

2 participants