Beispiel #1
0
 bool ServiceControl.Stop(HostControl hostControl)
 {
     if (_clusterRunner != null)
     {
         _clusterRunner.Shutdown().Wait();
         _clusterRunner = null;
     }
     return(true);
 }
Beispiel #2
0
        bool ServiceControl.Stop(HostControl hostControl)
        {
            _log.Info("Stop");

            if (_clusterRunner != null)
            {
                _clusterRunner.Shutdown().Wait();
                _clusterRunner = null;
            }
            return true;
        }
        bool ServiceControl.Start(HostControl hostControl)
        {
            _log.Info("Start");

            // force interface assembly to be loaded before creating ProtobufSerializer

            var type = typeof(IUser);

            if (type == null)
            {
                throw new InvalidProgramException("!");
            }

            // connect to redis

            try
            {
                var cstr = ConfigurationManager.ConnectionStrings["Redis"].ConnectionString;
                RedisStorage.Instance = new RedisStorage(cstr);
            }
            catch (Exception e)
            {
                _log.Error("Redis connection error", e);
                return(false);
            }

            // run cluster nodes

            var section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka");
            var config  = section.AkkaConfig;
            var runner  = new ClusterRunner(config, new[] { GetType().Assembly });

            runner.CreateClusterNodeContext = () => new ClusterNodeContext();

            var runnerConfig = config.GetValue("system.runner").GetObject();
            var nodes        = runnerConfig.GetKey(_runner ?? "default");

            if (nodes == null)
            {
                _log.Error("Cannot find runner:" + _runner);
                return(false);
            }

            runner.Launch(nodes.GetArray()).Wait();
            _clusterRunner = runner;

            return(true);
        }
Beispiel #4
0
        bool ServiceControl.Start(HostControl hostControl)
        {
            // force interface assembly to be loaded before creating ProtobufSerializer

            var type = typeof(IUser);
            if (type == null)
                throw new InvalidProgramException("!");

            // connect to mongo-db

            try
            {
                var cstr = ConfigurationManager.ConnectionStrings["Mongo"].ConnectionString;
                MongoDbStorage.Instance = new MongoDbStorage(cstr);
            }
            catch (Exception e)
            {
                _log.Error("MongoDB connection error", e);
                return false;
            }

            // run cluster nodes

            var section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka");
            var config = section.AkkaConfig;
            var runner = new ClusterRunner(config, new[] { GetType().Assembly });
            runner.CreateClusterNodeContext = () => new ClusterNodeContext();

            var runnerConfig = config.GetValue("system.runner").GetObject();
            var nodes = runnerConfig.GetKey(_runner ?? "default");
            if (nodes == null)
            {
                _log.Error("Cannot find runner:" + _runner);
                return false;
            }

            runner.Launch(nodes.GetArray()).Wait();
            _clusterRunner = runner;

            return true;
        }