RPCBase.Server.ZkAdaptor.Identity C# (CSharp) Method

Identity() public method

public Identity ( string roundName ) : void
roundName string
return void
        public void Identity(string roundName)
        {
            if (electionDict.ContainsKey(roundName))
            {
                return;
            }

            var roundsRoot = string.Format("/{0}Rounds", RoutingRule.DistrictsName);
            var thisRound = string.Format("{0}/{1}", roundsRoot, roundName);
            try
            {
                handle.Create(roundsRoot, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
            }
            catch (KeeperException.NodeExistsException e)
            {
                // ignore
            }

            try
            {
                handle.Create(thisRound, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
            }
            catch (KeeperException.NodeExistsException e)
            {
                // ignore
            }

            var me = string.Format("{0}/{1}-n_", thisRound, uuid);
            var ret = handle.Create(me, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EphemeralSequential);

            var elect = new Election(handle, thisRound, roundName, Election.PathToSeq(ret));

            electionDict[roundName] = elect;
            elect.AttempToBecomeLeader();
        }

Usage Example

Exemplo n.º 1
0
        static void InitService()
        {
            AutoInit.Init();
            TypeRegister.Init();

            RoutingRule.DistrictsName = ConfigManager.DistrictsName();

            zkAdaptor = new ZkAdaptor();
            //amqpAdaptor = new AmqpAdaptor(ConfigManager.MQIP(), ConfigManager.AMQPPort(),
            //    ConfigManager.MQUser(), ConfigManager.MQPass());

            //ServiceImplementStub.Bind<LogicClientServiceImpl, ILogicClientImpl>(amqpAdaptor, new LogicClientServiceImpl());
            ServiceImplementStub.Bind<IDbClientNotifyImpl>(zkAdaptor, new NotifyServiceImpl());

            //Logic2CliService = new ClientLogicServiceDelegate(amqpAdaptor);
            //loginNotifyDelegate = new LoginNotifyDelegate(amqpAdaptor);
            //SchedulerLogicService = new SchedulerLogicServiceDelegate(amqpAdaptor);

            dbClientNotifyDelegate = new DbClientNotifyDelegate(zkAdaptor);

            //ConfigManager.RegisterParser(new ConfigManager.ConfigParserDelegate<EndPoint>(s =>
            //{
            //    var rets = s.Split(':');
            //    var host = rets[0];
            //    var port = 0;

            //    int.TryParse(rets[1], out port);

            //    IPAddress ip;
            //    if (IPAddress.TryParse(host, out ip))
            //    {
            //        return new IPEndPoint(ip, port);
            //    }

            //    return new DnsEndPoint(host, port);
            //}));

            CacheService = new RedisDataServiceDelegate(new RedisAdaptor(ConfigManager.Instance.Read<List<EndPoint>>("DataService", "CacheConn")));
            //DbService = new MysqlDataServiceDelegate(new MysqlAdaptor(ConfigManager.DbIP(), ConfigManager.DbName(), ConfigManager.DbUser(), ConfigManager.DbPass()));

            zkAdaptor.BeginReceive();
            //amqpAdaptor.BeginReceive();

            zkAdaptor.Identity("Logic");

            //Heartbeat();
        }