コード例 #1
0
 /// <inheritdoc/>
 public IClusterMember GetMaster()
 {
     return(ExceptionDecorator.Run(() =>
     {
         var request = new GetMasterRequest();
         return new GetMasterResponseParser().Parse(_network.Invoke(request));
     }));
 }
コード例 #2
0
ファイル: GigaService.cs プロジェクト: JDinis99/DAD
        public override async Task <GetMasterReply> GetMaster(GetMasterRequest request, ServerCallContext context)
        {
            var masterId = _gigaStorage.GetMaster(request.PartitionId);

            return(await Task.FromResult(new GetMasterReply
            {
                MasterId = masterId
            }));
        }
コード例 #3
0
        public async Task <WriteReply> WriteAsync(WriteRequest request)
        {
            WriteReply reply;
            var        partitionId = request.PartitionId;

            try
            {
                reply = await ClientWriteAsync(request);

                var masterId = reply.MasterId;
                // if the current server is not the master
                if (masterId != this.ServerId && masterId != "")
                {
                    Console.WriteLine($"Establish a channel with the master server (id: {masterId}) of partition {partitionId}.");
                    EstablishChannel(masterId);
                    reply = await WriteAsync(request); // recursion
                }
            }
            catch (RpcException e)
            {
                Console.WriteLine($"RpcException: {e.StatusCode}");
                await CheckCurrentServerStatus();

                var getMasterRequest = new GetMasterRequest {
                    PartitionId = partitionId
                };
                var getMasterReply = await GetMasterAsync(getMasterRequest);

                var masterId = getMasterReply.MasterId;
                // if the current server is not the master
                if (masterId != this.ServerId && masterId != "")
                {
                    Console.WriteLine($"Establish a channel with the master server (id: {masterId}) of partition {partitionId}.");
                    EstablishChannel(masterId);
                }
                reply = await WriteAsync(request); // recursion
            }

            return(reply);
        }
コード例 #4
0
        public async Task <GetMasterReply> GetMasterAsync(GetMasterRequest request)
        {
            GetMasterReply reply;

            try
            {
                reply = await _client.GetMasterAsync(request);
            }
            catch (RpcException e)
            {
                Console.WriteLine($"RpcException: {e.StatusCode}");
                await CheckCurrentServerStatus();

                reply = await GetMasterAsync(request); // recursion
            }

            if (reply.MasterId == "")
            {
                Console.WriteLine($"The partition {request.PartitionId} does not have a master.");
            }

            return(reply);
        }
コード例 #5
0
        /* ====================================================================== */
        /* ====[                        Remote Calls                        ]==== */
        /* ====================================================================== */

        public async Task <ReadReply> ReadAsync(ReadRequest request)
        {
            var reply = new ReadReply(); // empty reply;

            try
            {
                reply = await ClientReadAsync(request);

                if (String.Equals(reply.Value, "N/A") && request.ServerId != "-1")
                {
                    EstablishChannel(request.ServerId);

                    var readRequest = new ReadRequest
                    {
                        PartitionId = request.PartitionId,
                        ObjectId    = request.ObjectId,
                        ServerId    = "-1"
                    };
                    reply = await ReadAsync(readRequest); // recursion
                }
                else if (String.Equals(reply.Value, "N/A") && request.ServerId == "-1" && reply.MasterId != this.ServerId && reply.MasterId != "")
                {
                    // if reply.Value == "N/A" then ask master, because the master of a partition always contains that partition
                    // if the partition master doesnt contain the request object, its because it doesnt exist
                    Console.WriteLine($"Establish a channel with the master server (id: {reply.MasterId}) of partition {request.PartitionId}.");
                    EstablishChannel(reply.MasterId);

                    var readRequest = new ReadRequest {
                        PartitionId = request.PartitionId,
                        ObjectId    = request.ObjectId,
                        ServerId    = "-1"
                    };
                    reply = await ReadAsync(readRequest); // recursion
                }
            }
            catch (RpcException e)
            {
                Console.WriteLine($"RpcException: {e.StatusCode}");
                await CheckCurrentServerStatus();

                if (request.ServerId != "-1")
                {
                    EstablishChannel(request.ServerId);

                    var readRequest = new ReadRequest
                    {
                        PartitionId = request.PartitionId,
                        ObjectId    = request.ObjectId,
                        ServerId    = "-1"
                    };
                    reply = await ReadAsync(readRequest); // recursion
                }
                else if (request.ServerId == "-1")
                {
                    var getMasterRequest = new GetMasterRequest {
                        PartitionId = request.PartitionId
                    };
                    var getMasterReply = await GetMasterAsync(getMasterRequest);

                    var masterId = getMasterReply.MasterId;
                    // if the current server is not the master
                    if (masterId != this.ServerId && masterId != "")
                    {
                        Console.WriteLine($"Establish a channel with the master server (id: {masterId}) of partition {request.PartitionId}.");
                        EstablishChannel(masterId);
                    }
                    reply = await ReadAsync(request); // recursion
                }
            }

            return(reply);
        }