@@ -99,6 +99,9 @@ extension ClusterSystem {
9999 /// - SeeAlso: `ActorTags` for a detailed discussion of some frequently used tags.
100100 public var tags : ActorTags
101101
102+ /// Internal "actor context" which is used as storage for additional cluster actor features, such as watching.
103+ internal var context : DistributedActorContext
104+
102105 /// Underlying path representation, not attached to a specific Actor instance.
103106 // FIXME(distributed): make optional
104107 public var path : ActorPath {
@@ -123,30 +126,59 @@ extension ClusterSystem {
123126 /// Uniquely identifies the specific "incarnation" of this actor.
124127 public let incarnation : ActorIncarnation
125128
126- /// :nodoc:
127- public init ( local node: UniqueNode , path: ActorPath ? , incarnation: ActorIncarnation ) {
129+ // TODO(distributed): remove this workaround; only exists for old ActorSingletonManager
130+ public static func _make( local node: UniqueNode , path: ActorPath ? , incarnation: ActorIncarnation ) -> Self {
131+ . init( local: node, path: path, incarnation: incarnation)
132+ }
133+
134+ // TODO(distributed): remove this initializer, as it is only for Behavior actors
135+ init ( local node: UniqueNode , path: ActorPath ? , incarnation: ActorIncarnation ) {
136+ self . context = . init( lifecycle: nil )
128137 self . _location = . local( node)
129138 self . tags = ActorTags ( )
130139 self . incarnation = incarnation
131140 if let path {
132141 self . tags [ ActorTags . path] = path
133142 }
143+ traceLog_DeathWatch ( " Made ID: \( self ) " )
134144 }
135145
136- /// :nodoc:
137- public init ( remote node: UniqueNode , path: ActorPath ? , incarnation: ActorIncarnation ) {
146+ // TODO(distributed): remove this workaround; only exists for old ActorSingletonManager
147+ public static func _make( remote node: UniqueNode , path: ActorPath ? , incarnation: ActorIncarnation ) -> Self {
148+ . init( remote: node, path: path, incarnation: incarnation)
149+ }
150+
151+ // TODO(distributed): remove this initializer, as it is only for Behavior actors
152+ init ( remote node: UniqueNode , path: ActorPath ? , incarnation: ActorIncarnation ) {
153+ self . context = . init( lifecycle: nil )
138154 self . _location = . remote( node)
139155 self . incarnation = incarnation
140156 self . tags = ActorTags ( )
141157 if let path {
142158 self . tags [ ActorTags . path] = path
143159 }
160+ traceLog_DeathWatch ( " Made ID: \( self ) " )
144161 }
145162
146- /// :nodoc:
147- public init < Act> ( local node: UniqueNode , type: Act . Type , incarnation: ActorIncarnation )
163+ public init < Act> ( remote node: UniqueNode , type: Act . Type , incarnation: ActorIncarnation )
148164 where Act: DistributedActor , Act. ActorSystem == ClusterSystem
149165 {
166+ self . context = . init( lifecycle: nil )
167+ self . _location = . remote( node)
168+ self . incarnation = incarnation
169+ self . tags = ActorTags ( )
170+ // TODO: avoid mangling names on every spawn?
171+ if let mangledName = _mangledTypeName ( type) {
172+ self . tags [ ActorTags . type] = . init( mangledName: mangledName)
173+ }
174+ traceLog_DeathWatch ( " Made ID: \( self ) " )
175+ }
176+
177+ init < Act> ( local node: UniqueNode , type: Act . Type , incarnation: ActorIncarnation ,
178+ context: DistributedActorContext )
179+ where Act: DistributedActor , Act. ActorSystem == ClusterSystem
180+ {
181+ self . context = context
150182 self . _location = . local( node)
151183 self . tags = ActorTags ( )
152184 self . incarnation = incarnation
@@ -155,18 +187,36 @@ extension ClusterSystem {
155187 if let mangledName = _mangledTypeName ( type) {
156188 self . tags [ ActorTags . type] = . init( mangledName: mangledName)
157189 }
190+ traceLog_DeathWatch ( " Made ID: \( self ) " )
158191 }
159192
160- /// :nodoc:
161- public init ( remote node: UniqueNode , type: ( some DistributedActor ) . Type, incarnation: ActorIncarnation ) {
193+ init < Act> ( remote node: UniqueNode , type: Act . Type , incarnation: ActorIncarnation ,
194+ context: DistributedActorContext )
195+ where Act: DistributedActor , Act. ActorSystem == ClusterSystem
196+ {
197+ self . context = context
162198 self . _location = . remote( node)
163199 self . incarnation = incarnation
164200 self . tags = ActorTags ( )
165201 // TODO: avoid mangling names on every spawn?
166202 if let mangledName = _mangledTypeName ( type) {
167203 self . tags [ ActorTags . type] = . init( mangledName: mangledName)
168204 }
205+ traceLog_DeathWatch ( " Made ID: \( self ) " )
169206 }
207+
208+ internal var withoutContext : Self {
209+ var copy = self
210+ copy. context = . init( lifecycle: nil )
211+ return copy
212+ }
213+ }
214+ }
215+
216+ extension DistributedActor where ActorSystem == ClusterSystem {
217+ /// INTERNAL: Provides the actor context for use within this actor.
218+ internal var context : DistributedActorContext {
219+ self . id. context
170220 }
171221}
172222
@@ -237,7 +287,6 @@ extension ActorID {
237287
238288extension ActorID {
239289 /// :nodoc:
240- @inlinable
241290 public var _isLocal : Bool {
242291 switch self . _location {
243292 case . local: return true
@@ -246,20 +295,17 @@ extension ActorID {
246295 }
247296
248297 /// :nodoc:
249- @inlinable
250298 public var _isRemote : Bool {
251299 !self . _isLocal
252300 }
253301
254302 /// :nodoc:
255- @inlinable
256303 public var _asRemote : Self {
257304 let remote = Self ( remote: self . uniqueNode, path: self . path, incarnation: self . incarnation)
258305 return remote
259306 }
260307
261308 /// :nodoc:
262- @inlinable
263309 public var _asLocal : Self {
264310 let local = Self ( local: self . uniqueNode, path: self . path, incarnation: self . incarnation)
265311 return local
0 commit comments