-
Notifications
You must be signed in to change notification settings - Fork 79
Create ClusterControl in ActorSystem directly #74 #89
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ public final class ActorSystem { | |
|
|
||
| // initialized during startup | ||
| internal var _cluster: ClusterShell? | ||
| internal var _clusterEvents: EventStream<ClusterEvent>? | ||
| internal var _clusterControl: ClusterControl? | ||
| internal var _nodeDeathWatcher: NodeDeathWatcherShell.Ref? | ||
|
|
||
| // ==== ---------------------------------------------------------------------------------------------------------------- | ||
|
|
@@ -176,6 +176,7 @@ public final class ActorSystem { | |
| effectiveSystemProvider = RemoteActorRefProvider(settings: settings, cluster: cluster, localProvider: localSystemProvider) | ||
| } else { | ||
| self._cluster = nil | ||
| self._clusterControl = ClusterControl(self.settings.cluster, clusterRef: self.deadLetters.adapted(), eventStream: EventStream(ref: self.deadLetters.adapted())) | ||
| } | ||
|
|
||
| self.systemProvider = effectiveSystemProvider | ||
|
|
@@ -201,9 +202,10 @@ public final class ActorSystem { | |
| do { | ||
| // Cluster MUST be the last thing we initialize, since once we're bound, we may receive incoming messages from other nodes | ||
| if let cluster = self._cluster { | ||
| let clusterEvents = try! EventStream<ClusterEvent>(self, name: "clusterEvents") | ||
| self._clusterEvents = clusterEvents | ||
| _ = try cluster.start(system: self, eventStream: self.clusterEvents) // only spawns when cluster is initialized | ||
| let clusterEvents = try! EventStream<ClusterEvent>(self, name: "clusterEvents", systemStream: true) | ||
| _ = try cluster.start(system: self, eventStream: clusterEvents) // only spawns when cluster is initialized | ||
|
|
||
| self._clusterControl = ClusterControl(settings.cluster, clusterRef: cluster.ref, eventStream: clusterEvents) | ||
|
|
||
| // Node watcher MUST be started AFTER cluster and clusterEvents | ||
| self._nodeDeathWatcher = try self._spawnSystemActor( | ||
|
|
@@ -237,9 +239,9 @@ public final class ActorSystem { | |
| /// Do not call from within actors or you may deadlock shutting down the system. | ||
| public func shutdown() { | ||
| self.log.log(level: .debug, "SHUTTING DOWN ACTOR SYSTEM [\(self.name)]. All actors will be stopped.", file: #file, function: #function, line: #line) | ||
| if self.settings.cluster.enabled { | ||
| if let cluster = self._cluster { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good to move from the settings check to this style 👍 |
||
| let receptacle = BlockingReceptacle<Void>() | ||
| self.cluster._shell.tell(.command(.unbind(receptacle))) // FIXME: should be shutdown | ||
| cluster.ref.tell(.command(.unbind(receptacle))) // FIXME: should be shutdown | ||
| receptacle.wait(atMost: .milliseconds(300)) // FIXME: configure | ||
| } | ||
| self.userProvider.stopAll() | ||
|
|
@@ -250,6 +252,14 @@ public final class ActorSystem { | |
| self._cluster = nil | ||
| self._receptionist = self.deadLetters.adapted() | ||
| } | ||
|
|
||
| public var cluster: ClusterControl { | ||
| guard let clusterControl = self._clusterControl else { | ||
| fatalError("BUG! Tried to access clusterControl on \(self) and it was nil! Please report this on the issue tracker.") | ||
| } | ||
|
|
||
| return clusterControl | ||
| } | ||
| } | ||
|
|
||
| extension ActorSystem: Equatable { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,7 @@ public class ProcessIsolated { | |
| let funKillServantProcess: (Int) -> Void = { (pid: Int) in | ||
| self.lock.withLockVoid { | ||
| if let servant = self._servants[pid] { | ||
| self.system.cluster._shell.tell(.command(.downCommand(servant.node.node))) | ||
| self.system.cluster.down(node: servant.node.node) | ||
| self._servants.removeValue(forKey: pid) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice; I wonder if we need to store the
_clusteras well though?All usage I guess would rather be though _control? we can always
_clusterControl._shell?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Thinking to have as little fields for the same thing as we can for the core actor system; we'd have exactly one way to access the shell then etc)