private void OnActorAdded(ActorRemoteInfo actor) { Log.Debug("On ActorAddedEvent " + actor.Name); TaskCompletionSource <ActorRemoteInfo> tcs; if (_pendingActorsByName.TryRemove(actor.Name, out tcs)) { tcs.SetResult(actor); } }
private void OnActorCreated(string actorName, ulong targetNodeId, uint actorLocalId) { Log.Debug("Received actor created operation for Actor<Name:{0}>", actorName); var actor = new ActorRemoteInfo(actorName, new ActorKey(targetNodeId, actorLocalId)); //first one win race condition resolving, we can safely use this only because we use globaly Ordered broadcasts if (_actorsByName.TryAdd(actorName, actor)) { //because actor is created in repository before all other coordinators discover this //so in case if this is not target node to check and remove all garbage //actual owner of this broadcast would still have proper actor if (targetNodeId != _node.Id) { _node.Repository.Remove(_primaryNetContractId, actorName); } _actorAddedEvent.OnNext(actor); } else { Log.Debug("Received duplicate actor creation for Actor<Name:{0}>", actorName); } }
public async Task <ActorKey> GetOrCreate(string actorName) { await _initializedTask.Task; Log.Debug("GetOrCreate name:" + actorName); ActorRemoteInfo actorInfo; if (_actorsByName.TryGetValue(actorName, out actorInfo)) { Log.Debug("GetOrCreate->Resolved {0} from cache", actorInfo); return(actorInfo.Key); } else { NodeRemoteInfo targetNode = _distributionFunc(_node.ClusterView); Log.Debug("GetOrCreate->Creating Actor<Name:{0}> on NodeId:{1}", actorName, targetNode.NodeId); if (targetNode.NodeId != _node.Id) { _isisGroup.OrderedSend(CreateActorOperationId, actorName, targetNode.NodeId); } else { Actor newActor = _node.Repository.Create(_node, actorName, _primaryNetContractId); _isisGroup.OrderedSend(ActorCreatedOperationId, actorName, _node.Id, newActor.LocalId); } var tcs = new TaskCompletionSource <ActorRemoteInfo>(); ActorRemoteInfo actor = null; _pendingActorsByName.TryAdd(actorName, tcs); actor = await tcs.Task; return(actor.Key); } }