Example #1
0
        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.");
                }
            }
        }
Example #2
0
        public void Bootup(IActorDirectory directory)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (this.Active)
            {
                throw new InvalidOperationException(
                          string.Format("Local actor [{0}] has already been booted up.", this.Identity));
            }

            _log.DebugFormat("Claim local actor [{0}].", this.Identity);

            if (_directory != null)
            {
                throw new InvalidOperationException("Actor directory has already been assigned.");
            }
            _directory = directory;

            _manager = new ActorChannelManager(_directory, new ActorChannelFactory(_directory, this.ChannelConfiguration));
            _manager.ChannelConnected    += OnActorChannelConnected;
            _manager.ChannelDisconnected += OnActorChannelDisconnected;
            _manager.ChannelDataReceived += OnActorChannelDataReceived;

            try
            {
                _manager.ActivateLocalActor(this.Identity);
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                Shutdown();
                throw new InvalidOperationException(
                          string.Format("Cannot initiate the local actor [{0}] during bootup.", this.Identity));
            }

            try
            {
                if (!_directory.Active)
                {
                    _directory.Open();
                    _directory.Register(this.Identity);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                Shutdown();
                throw new InvalidOperationException(
                          string.Format("Cannot connect to actor directory during bootup, [{0}].", this.Identity));
            }
        }