Exemple #1
0
        private void HandOff(IActorRef replyTo)
        {
            if (HandOffStopper != null)
            {
                Log.Warning("HandOff shard [{0}] received during existing handOff", ShardId);
            }
            else
            {
                Log.Debug("HandOff shard [{0}]", ShardId);

                if (State.Entries.Count != 0)
                {
                    HandOffStopper = _context.Watch(_context.ActorOf(
                                                        ShardRegion.HandOffStopper.Props(ShardId, replyTo, IdByRef.Keys, HandOffStopMessage)));

                    //During hand off we only care about watching for termination of the hand off stopper
                    _context.Become(message =>
                    {
                        var terminated = message as Terminated;
                        if (terminated != null)
                        {
                            HandleTerminated(terminated.ActorRef);
                            return(true);
                        }
                        return(false);
                    });
                }
                else
                {
                    replyTo.Tell(new PersistentShardCoordinator.ShardStopped(ShardId));
                    _context.Stop(_context.Self);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="context">TBD</param>
 /// <param name="restart">TBD</param>
 /// <param name="child">TBD</param>
 /// <param name="cause">TBD</param>
 /// <param name="stats">TBD</param>
 /// <param name="children">TBD</param>
 public override void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats, IReadOnlyCollection <ChildRestartStats> children)
 {
     if (restart && stats.RequestRestartPermission(MaxNumberOfRetries, WithinTimeRangeMilliseconds))
     {
         RestartChild(child, cause, suspendFirst: false);
     }
     else
     {
         context.Stop(child);
     }
 }
Exemple #3
0
        protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
        {
            var failedChild = failedChildStats.Child;

            if (restart && failedChildStats.RequestRestartPermission(MaxNumberOfRetries, WithinTimeRangeMilliseconds))
            {
                RestartChild(failedChild, cause, suspendFirst: false);
            }
            else
            {
                context.Stop(failedChild);
            }
        }
Exemple #4
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="context">TBD</param>
 /// <param name="restart">TBD</param>
 /// <param name="child">TBD</param>
 /// <param name="cause">TBD</param>
 /// <param name="stats">TBD</param>
 /// <param name="children">TBD</param>
 public override void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats, IReadOnlyCollection <ChildRestartStats> children)
 {
     if (children.Count > 0)
     {
         if (restart && children.All(c => c.RequestRestartPermission(MaxNumberOfRetries, WithinTimeRangeMilliseconds)))
         {
             foreach (var crs in children)
             {
                 RestartChild(crs.Child, cause, suspendFirst: !child.Equals(crs.Child));
             }
         }
         else
         {
             foreach (var crs in children)
             {
                 context.Stop(crs.Child);
             }
         }
     }
 }
Exemple #5
0
        private async ValueTask <ConnectionOpened> CreateConnection(DnsEndPoint logicalAddress, DnsEndPoint physicalAddress, int connectionKey)
        {
            if (_log.IsDebugEnabled)
            {
                _log.Debug($"Connection for {logicalAddress} not found in cache");
            }
            var targetBroker = $"{physicalAddress.Host}:{physicalAddress.Port}";

            if (!logicalAddress.Equals(physicalAddress))
            {
                targetBroker = $"{logicalAddress.Host}:{logicalAddress.Port}";
            }

            var cnx = _context.ActorOf(Props.Create(() => new ClientCnx(_clientConfig, physicalAddress, targetBroker)), $"{targetBroker}{connectionKey}".ToAkkaNaming());
            var ask = await cnx.Ask <AskResponse>(Connect.Instance);

            if (ask.Failed)
            {
                //in a situation where we cannot connect, and since this will be retried,
                //in order to avoid conflicting actor names, lets kill it
                _context.Stop(cnx);
                await Task.Delay(TimeSpan.FromSeconds(1));

                throw ask.Exception;
            }

            var connection = ask.ConvertTo <ConnectionOpened>();

            if (_pool.TryGetValue(_logicalEndpoint, out _))
            {
                _pool[_logicalEndpoint][_randomKey] = connection;
            }
            else
            {
                _pool.Add(_logicalEndpoint, new Dictionary <int, ConnectionOpened> {
                    { _randomKey, connection }
                });
            }

            return(connection);
        }
Exemple #6
0
        protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
        {
            if (allChildren.Count > 0)
            {
                var failedChild = failedChildStats.Child;

                if (restart && allChildren.All(c => c.RequestRestartPermission(MaxNumberOfRetries, WithinTimeRangeMilliseconds)))
                {
                    foreach (var crs in allChildren)
                    {
                        RestartChild(crs.Child, cause, suspendFirst: !failedChild.Equals(crs.Child));
                    }
                }
                else
                {
                    foreach (var crs in allChildren)
                    {
                        context.Stop(crs.Child);
                    }
                }
            }
        }
        protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection<ChildRestartStats> allChildren)
        {
            if (allChildren.Count > 0)
            {
                var failedChild = failedChildStats.Child;

                if (restart && allChildren.All(c => c.RequestRestartPermission(_maxNumberOfRetries, _withinTimeRangeMilliseconds)))
                {
                    foreach (var crs in allChildren)
                    {
                        RestartChild(crs.Child, cause, suspendFirst: !failedChild.Equals(crs.Child));
                    }
                }
                else
                {
                    foreach (var crs in allChildren)
                    {
                        context.Stop(crs.Child);
                    }
                }
            }
        }
        protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection<ChildRestartStats> allChildren)
        {
            var failedChild = failedChildStats.Child;

            if (restart && failedChildStats.RequestRestartPermission(_maxNumberOfRetries, _withinTimeRangeMilliseconds))
                RestartChild(failedChild, cause, suspendFirst: false);
            else
                context.Stop(failedChild);
        }