Exemple #1
0
        static void Main(string[] args)
        {
            try
            {
                TTransport            transport = new TSocket("localhost", 9091);
                TProtocol             protocol  = new TBinaryProtocol(transport);
                ClusterNodeRPC.Client client    = new ClusterNodeRPC.Client(protocol);

                transport.Open();
                try
                {
                    client.appendLogEntry("+ 5");
                    Console.WriteLine("+ 5");
                    client.appendLogEntry("* 3");
                    Console.WriteLine("* 3");
                    client.appendLogEntry("- 2");
                    Console.WriteLine("- 2");
                    int res = client.getTestNum();
                    Console.WriteLine(String.Format("res is {0}", res));
                }
                finally
                {
                    transport.Close();
                }
            }
            catch (TApplicationException x)
            {
                Console.WriteLine(x.StackTrace);
            }
        }
Exemple #2
0
 public ClusterNodeSocket(TTransport _transport, ClusterNodeRPC.Client _client, IPEndPoint _ipport, int id)
 {
     ID        = id;
     transport = _transport;
     client    = _client;
     IPPort    = _ipport;
 }
Exemple #3
0
        public ClusterNode(IPEndPoint myIPandPort, List <IPEndPoint> ClusterNodeList, List <int> nodeIdList)
        {
            //设定各个状态的初始值
            myIPandPort_      = myIPandPort;
            node_should_stop_ = false;


            // 获取其他所有节点的transport和client,存于ExClusterNodeList,不包括自身
            ExClusterNodeList_      = new List <ClusterNodeSocket>();
            OriginalIPEndPointList_ = new List <IPEndPoint>();
            int _id = -1;

            for (int i = 0; i < ClusterNodeList.Count; ++i)
            {
                IPEndPoint IPPort = ClusterNodeList[i];
                if (myIPandPort_.Equals(IPPort))
                {
                    _id = nodeIdList[i];
                    continue;
                }

                OriginalIPEndPointList_.Add(IPPort);
                TTransport            transport = new TSocket(IPPort.Address.ToString(), IPPort.Port, Config.Heartbeat_interval * 2); //timeout ms
                TProtocol             protocol  = new TBinaryProtocol(transport);
                ClusterNodeRPC.Client client    = new ClusterNodeRPC.Client(protocol);
                ExClusterNodeList_.Add(new ClusterNodeSocket(transport, client, IPPort, nodeIdList[i]));
            }

            //初始化Server
            ServerHandler_ = new ServerHandler(0, _id, NodeRole.Follower, ExClusterNodeList_);
            ClusterNodeRPC.Processor processor = new ClusterNodeRPC.Processor(ServerHandler_);
            ServerTransport_ = new TServerSocket(myIPandPort.Port);
            Server_          = new TThreadPoolServer(processor, ServerTransport_);

            // 初始化线程
            TServer_       = new Thread(server_thread);
            Tconnect_      = new Thread(connect);
            TStateChecker_ = new Thread(state_checker);
            Tcommit_       = new Thread(commit);
        }