Пример #1
0
        public bool IsConnected(Guid id)
        {
            ServerInst inst = serverInstances.GetById(id);

            if (inst != null)
            {
                return(inst.IsConnected);
            }

            throw new ServerInstNotExistsException(String.Format("Server is not exist.[id={0}]", id));
        }
Пример #2
0
        public void Execute(SlaveOfCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            ServerInst master = serverInstances.GetById(command.MasterId);
            ServerInst slave  = serverInstances.GetById(command.SlaveId);

            slave.SlaveOf(master);
        }
Пример #3
0
        public void RegistryZk(Guid id)
        {
            log.Info("registry on Zk,id=" + id);
            ServerInst inst = serverInstances.GetById(id);

            if (inst != null)
            {
                log.Info(inst);
                ShardBuilder builder = new ShardBuilder();
                Shard        shard   = builder.AddServer(inst.ServerInfo).Build();
                //多次对每个server初始化有没有问题?
                LeaderContext leaderContext = new LeaderContext(zookeeper, inst.ServerInfo);
                leaderContext.JoinElection();
            }
        }
Пример #4
0
 public void Execute(PingCommand command)
 {
     if (command == null)
     {
         throw new ArgumentNullException("command");
     }
     ServerInst inst = serverInstances.GetById(new Guid(command.ServerId));
     TimeSpan   ts   = inst.Ping();
 }
Пример #5
0
        public void Execute(BeLeaderCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            ServerInst inst = serverInstances.GetById(command.ServerId);

            inst.BeMaster();

            foreach (var item in serverInstances.GetByShardName(inst.ServerInfo.ShardName))
            {
                if (item.Id != inst.Id)
                {
                    HAContext.Current.CommandBus.Send(new SlaveOfCommand(Guid.NewGuid(), inst.Id.ToString(), inst.ServerInfo.Host, inst.ServerInfo.Port,
                                                                         item.Id.ToString(), item.ServerInfo.Host, item.ServerInfo.Port, -1));
                }
            }
        }