public void Execute(PingCommand command)
 {
     if (command == null)
     {
         throw new ArgumentNullException("command");
     }
     ServerInst inst = serverInstances.GetById(new Guid(command.ServerId));
     TimeSpan   ts   = inst.Ping();
 }
Beispiel #2
0
        public bool IsZKRegistered(Guid id)
        {
            ServerInst inst = serverInstances.GetById(id);

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

            throw new ServerInstNotExistsException(String.Format("Server is not exist.[id={0}]", id));
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public void UnRegistry(Guid id)
        {
            log.Info("unregistry on Zk,id=" + id);
            ServerInst inst = serverInstances.GetById(id);

            if (inst != null)
            {
                log.Info(inst);
                //多次对每个server初始化有没有问题?
                LeaderContext leaderContext = new LeaderContext(zookeeper, inst.ServerInfo);
                leaderContext.CancelElection();
            }
        }
Beispiel #5
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();
            }
        }
Beispiel #6
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));
                }
            }
        }
 public void Init()
 {
     inst = new ServerInst("127.0.0.1", 8081, "test1", "test2");
 }
Beispiel #8
0
 public bool Add(ServerInst item)
 {
     return(items.TryAdd(item.Id, item));
 }