public void Bootup() { _log.InfoFormat("Claim local actor [{0}].", this.LocalActor); _log.InfoFormat("Register center actor [{0}].", this.CenterActor); var centerChannel = BuildActorCenterChannel(this.CenterActor, this.LocalActor); _directory = new ActorDirectory(this.CenterActor, centerChannel, this.ChannelConfiguration); _factory = new ActorChannelFactory(_directory, this.ChannelConfiguration); _manager = new ActorChannelManager(_factory); _manager.Connected += OnActorConnected; _manager.Disconnected += OnActorDisconnected; _manager.DataReceived += OnActorDataReceived; _manager.ActivateLocalActor(this.LocalActor); centerChannel.Open(); int retryTimes = 0; while (true) { if (centerChannel.Active) { break; } Thread.Sleep(TimeSpan.FromMilliseconds(100)); retryTimes++; if (retryTimes > 300) { Shutdown(); throw new InvalidOperationException("Cannot connect to center actor."); } } }
public void Shutdown() { if (_manager != null) { _manager.Connected -= OnActorConnected; _manager.Disconnected -= OnActorDisconnected; _manager.DataReceived -= OnActorDataReceived; _manager.CloseAllChannels(); _manager = null; } if (_directory != null) { _directory.GetCenterActorChannel().Close(); _directory = null; } }
public ActorChannelFactory( ActorDirectory directory, ActorChannelConfiguration channelConfiguration) { if (directory == null) { throw new ArgumentNullException("directory"); } if (channelConfiguration == null) { throw new ArgumentNullException("channelConfiguration"); } _directory = directory; _channelConfiguration = channelConfiguration; }