public DefaultClusterContext(IIdentityLookup identityLookup, PidCache pidCache, ClusterContextConfig config, CancellationToken killSwitch) { _identityLookup = identityLookup; _pidCache = pidCache; _requestLogThrottle = Throttle.Create( config.MaxNumberOfEventsInRequestLogThrottlePeriod, config.RequestLogThrottlePeriod, i => Logger.LogInformation("Throttled {LogCount} TryRequestAsync logs", i) ); _clock = new TaskClock(config.ActorRequestTimeout, TimeSpan.FromSeconds(1), killSwitch); _clock.Start(); }
public ExperimentalClusterContext(Cluster cluster) { _identityLookup = cluster.IdentityLookup; _pidCache = cluster.PidCache; var config = cluster.Config; _requestLogThrottle = Throttle.Create( config.MaxNumberOfEventsInRequestLogThrottlePeriod, config.RequestLogThrottlePeriod, i => Logger.LogInformation("Throttled {LogCount} TryRequestAsync logs", i) ); _clock = new TaskClock(config.ActorRequestTimeout, TimeSpan.FromSeconds(1), cluster.System.Shutdown); _clock.Start(); }
public static async Task <(PID, ResponseStatusCode)> GetAsync(string name, string kind, CancellationToken ct) { //Check Cache if (PidCache.TryGetCache(name, out var pid)) { return(pid, ResponseStatusCode.OK); } //Get Pid var address = MemberList.GetPartition(name, kind); if (string.IsNullOrEmpty(address)) { return(null, ResponseStatusCode.Unavailable); } var remotePid = Partition.PartitionForKind(address, kind); var req = new ActorPidRequest { Kind = kind, Name = name }; try { var resp = ct == CancellationToken.None ? await RootContext.Empty.RequestAsync <ActorPidResponse>(remotePid, req, Config.TimeoutTimespan) : await RootContext.Empty.RequestAsync <ActorPidResponse>(remotePid, req, ct); var status = (ResponseStatusCode)resp.StatusCode; switch (status) { case ResponseStatusCode.OK: PidCache.TryAddCache(name, resp.Pid); return(resp.Pid, status); default: return(resp.Pid, status); } } catch (TimeoutException) { return(null, ResponseStatusCode.Timeout); } catch { return(null, ResponseStatusCode.Error); } }
public static void Start(string clusterName, IClusterProvider provider) { _logger.LogInformation("Starting Proto.Actor cluster"); var(h, p) = ParseAddress(ProcessRegistry.Instance.Address); var kinds = Remote.Remote.GetKnownKinds(); Partition.SpawnPartitionActors(kinds); Partition.SubscribeToEventStream(); PidCache.Spawn(); MemberList.Spawn(); MemberList.SubscribeToEventStream(); provider.RegisterMemberAsync(clusterName, h, p, kinds).Wait(); provider.MonitorMemberStatusChanges(); _logger.LogInformation("Cluster started"); }
public static void Shutdown(bool gracefull = true) { if (gracefull) { Config.ClusterProvider.Shutdown(); //This is to wait ownership transfering complete. Task.Delay(2000).Wait(); MemberList.Stop(); PidCache.Stop(); Partition.Stop(); } Remote.Remote.Shutdown(gracefull); Logger.LogInformation("Stopped Cluster"); }
public Task ReceiveAsync(IContext context) { switch (context.Message) { case Started _: _logger.LogDebug("Started PidCacheWatcher"); break; case WatchPidRequest msg: context.Watch(msg.Pid); break; case Terminated msg: PidCache.RemoveCacheByPid(msg.Who); break; } return Actor.Done; }
public static void Shutdown(bool gracefull = true) { if (gracefull) { cp.Shutdown(); MemberList.UnsubEventStream(); MemberList.Stop(); PidCache.UnsubEventStream(); PidCache.Stop(); Partition.UnsubEventStream(); Partition.StopPartitionActors(); } Remote.Remote.Shutdown(gracefull); Logger.LogInformation("Stopped Cluster"); }
public static void StartWithConfig(ClusterConfig config) { Config = config; Remote.Remote.Start(Config.Address, Config.Port, Config.RemoteConfig); Serialization.RegisterFileDescriptor(ProtosReflection.Descriptor); Logger.LogInformation("Starting Proto.Actor cluster"); var(host, port) = ParseAddress(ProcessRegistry.Instance.Address); var kinds = Remote.Remote.GetKnownKinds(); Partition.Setup(kinds); PidCache.Setup(); MemberList.Setup(); Config.ClusterProvider.RegisterMemberAsync(Config.Name, host, port, kinds, config.InitialMemberStatusValue, config.MemberStatusValueSerializer).Wait(); Config.ClusterProvider.MonitorMemberStatusChanges(); Logger.LogInformation("Started Cluster"); }
public static void StartWithConfig(ClusterConfig config) { cfg = config; Remote.Remote.Start(cfg.Address, cfg.Port, cfg.RemoteConfig); Serialization.RegisterFileDescriptor(ProtosReflection.Descriptor); Logger.LogInformation("Starting Proto.Actor cluster"); var(h, p) = ParseAddress(ProcessRegistry.Instance.Address); var kinds = Remote.Remote.GetKnownKinds(); Partition.SpawnPartitionActors(kinds); Partition.SubscribeToEventStream(); PidCache.Spawn(); PidCache.SubscribeToEventStream(); MemberList.SubscribeToEventStream(); cfg.ClusterProvider.RegisterMemberAsync(cfg.Name, h, p, kinds, config.InitialMemberStatusValue, config.MemberStatusValueSerializer).Wait(); cfg.ClusterProvider.MonitorMemberStatusChanges(); Logger.LogInformation("Started Cluster"); }
public static void Start(string clusterName, string address, int port, IClusterProvider provider) { Remote.Remote.Start(address, port); cp = provider; Serialization.RegisterFileDescriptor(ProtosReflection.Descriptor); Logger.LogInformation("Starting Proto.Actor cluster"); var(h, p) = ParseAddress(ProcessRegistry.Instance.Address); var kinds = Remote.Remote.GetKnownKinds(); Partition.SpawnPartitionActors(kinds); Partition.SubscribeToEventStream(); PidCache.Spawn(); PidCache.SubscribeToEventStream(); MemberList.Spawn(); MemberList.SubscribeToEventStream(); cp.RegisterMemberAsync(clusterName, h, p, kinds).Wait(); cp.MonitorMemberStatusChanges(); Logger.LogInformation("Started Cluster"); }
public static void RemoveCache(string name) => PidCache.RemoveCacheByName(name);