public void Execute(PingCommand command) { if (command == null) { throw new ArgumentNullException("command"); } ServerInst inst = serverInstances.GetById(new Guid(command.ServerId)); TimeSpan ts = inst.Ping(); }
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)); }
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); }
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(); } }
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(); } }
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"); }
public bool Add(ServerInst item) { return(items.TryAdd(item.Id, item)); }