Example #1
0
        public bool TryUpdate(ClusterIdentity clusterIdentity, PID newPid, PID existingPid)
        {
            if (clusterIdentity is null)
            {
                throw new ArgumentNullException(nameof(clusterIdentity));
            }

            if (newPid is null)
            {
                throw new ArgumentNullException(nameof(newPid));
            }

            if (existingPid is null)
            {
                throw new ArgumentNullException(nameof(existingPid));
            }

            if (!_cacheDict.TryUpdate(clusterIdentity, newPid, existingPid))
            {
                return(false);
            }

            clusterIdentity.CachedPid = newPid;
            return(true);
        }
Example #2
0
        public bool TryRemove(ClusterIdentity clusterIdentity)
        {
            if (clusterIdentity is null)
            {
                throw new ArgumentNullException(nameof(clusterIdentity));
            }

            return(_cacheDict.TryRemove(clusterIdentity, out _));
        }
Example #3
0
        public bool TryGet(ClusterIdentity clusterIdentity, out PID pid)
        {
            if (clusterIdentity is null)
            {
                throw new ArgumentNullException(nameof(clusterIdentity));
            }

            return(_cacheDict.TryGetValue(clusterIdentity, out pid));
        }
Example #4
0
        public bool RemoveByVal(ClusterIdentity clusterIdentity, PID pid)
        {
            var key = clusterIdentity;

            if (_cacheDict.TryGetValue(key, out var existingPid) && existingPid.Id == pid.Id &&
                existingPid.Address == pid.Address)
            {
                return(_cacheCollection.Remove(new KeyValuePair <ClusterIdentity, PID>(key, existingPid)));
            }

            return(false);
        }
Example #5
0
        public bool TryAdd(ClusterIdentity clusterIdentity, PID pid)
        {
            if (clusterIdentity is null)
            {
                throw new ArgumentNullException(nameof(clusterIdentity));
            }

            if (pid is null)
            {
                throw new ArgumentNullException(nameof(pid));
            }

            return(_cacheDict.TryAdd(clusterIdentity, pid));
        }
Example #6
0
        public bool RemoveByVal(ClusterIdentity clusterIdentity, PID pid)
        {
            if (clusterIdentity.CachedPid?.Equals(pid) == true)
            {
                clusterIdentity.CachedPid = null;
            }

            if (_cacheDict.TryGetValue(clusterIdentity, out var existingPid) && existingPid.Id == pid.Id &&
                existingPid.Address == pid.Address)
            {
                return(_cacheCollection.Remove(new KeyValuePair <ClusterIdentity, PID>(clusterIdentity, existingPid)));
            }

            return(false);
        }
Example #7
0
        public bool TryGet(ClusterIdentity clusterIdentity, out PID pid)
        {
            if (clusterIdentity is null)
            {
                throw new ArgumentNullException(nameof(clusterIdentity));
            }

            if (clusterIdentity.CachedPid is { } identityCachedPid)
            {
                //If the PID is already cached using ClusterIdentity, we can skip the lookup altogether
                pid = identityCachedPid;
                return(true);
            }
            return(_cacheDict.TryGetValue(clusterIdentity, out pid));
        }
        public async Task <T?> RequestAsync <T>(ClusterIdentity clusterIdentity, object message, ISenderContext context, CancellationToken ct)
        {
            var start = Stopwatch.StartNew();
            var i     = 0;

            var future  = context.GetFuture();
            PID?lastPid = null;

            try
            {
                while (!ct.IsCancellationRequested)
                {
                    if (context.System.Shutdown.IsCancellationRequested)
                    {
                        return(default);
        public async Task <T?> RequestAsync <T>(ClusterIdentity clusterIdentity, object message, ISenderContext context, CancellationToken ct)
        {
            var start = DateTime.UtcNow;

            Logger.LogDebug("Requesting {ClusterIdentity} Message {Message}", clusterIdentity, message);
            var i = 0;

            var future  = new FutureProcess(context.System);
            PID?lastPid = null;

            try
            {
                while (!ct.IsCancellationRequested)
                {
                    if (context.System.Shutdown.IsCancellationRequested)
                    {
                        return(default);
Example #10
0
        public bool TryUpdate(ClusterIdentity clusterIdentity, PID newPid, PID existingPid)
        {
            if (clusterIdentity is null)
            {
                throw new ArgumentNullException(nameof(clusterIdentity));
            }

            if (newPid is null)
            {
                throw new ArgumentNullException(nameof(newPid));
            }

            if (existingPid is null)
            {
                throw new ArgumentNullException(nameof(existingPid));
            }

            return(_cacheDict.TryUpdate(clusterIdentity, newPid, existingPid));
        }
Example #11
0
        public bool TryAdd(ClusterIdentity clusterIdentity, PID pid)
        {
            if (clusterIdentity is null)
            {
                throw new ArgumentNullException(nameof(clusterIdentity));
            }

            if (pid is null)
            {
                throw new ArgumentNullException(nameof(pid));
            }

            if (!_cacheDict.TryAdd(clusterIdentity, pid))
            {
                return(false);
            }

            clusterIdentity.CachedPid = pid;
            return(true);
        }
 public static Props WithClusterIdentity(this Props props, ClusterIdentity clusterIdentity)
 => props.WithOnInit(context => context.Set(clusterIdentity));
Example #13
0
 public static Task <T> RequestAsync <T>(this Cluster cluster, ClusterIdentity clusterIdentity, object message, CancellationToken ct) =>
 cluster.RequestAsync <T>(clusterIdentity, message, cluster.System.Root, ct) !;