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.Encoder, this.Decoder);
            _factory               = new ActorChannelFactory(_directory, this.Encoder, this.Decoder);
            _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;
                }

                Task.Delay(TimeSpan.FromMilliseconds(100)).Wait();
                retryTimes++;
                if (retryTimes > 300)
                {
                    Shutdown();
                    throw new InvalidOperationException("Cannot connect to center actor.");
                }
            }
        }
Esempio n. 2
0
        public ActorChannelFactory(
            ActorDirectory directory,
            IActorMessageEncoder encoder, IActorMessageDecoder decoder)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (encoder == null)
            {
                throw new ArgumentNullException("encoder");
            }
            if (decoder == null)
            {
                throw new ArgumentNullException("decoder");
            }

            _directory = directory;
            _encoder   = encoder;
            _decoder   = decoder;
        }