public ReadReply ReadHandler(ReadRequest request)
        {
            Partition partition      = server.getPartition(request.ObjectKey.PartitionId);
            int       partitionClock = partition.getClock();

            Console.WriteLine(">>> PartitionName=" + request.ObjectKey.PartitionId + ", PartitionClock=" + partitionClock);
            ReadReply reply;

            try
            {
                DataStoreValue value = partition.getData(new DataStoreKey(request.ObjectKey.PartitionId, request.ObjectKey.ObjectId));
                reply = new ReadReply
                {
                    Object = new DataStoreValueDto {
                        Val = value.val
                    },
                    ObjectExists   = true,
                    PartitionClock = partitionClock
                };
            }
            catch (Exception)
            {
                reply = new ReadReply
                {
                    Object = new DataStoreValueDto {
                        Val = "NA"
                    },
                    ObjectExists   = false,
                    PartitionClock = partitionClock
                };
            }

            return(reply);
        }
        public ReadReply ReadHandler(ReadRequest request)
        {
            Partition partition = server.getPartition(request.ObjectKey.PartitionId);
            ReadReply reply     = null;

            try
            {
                DataStoreValue value = partition.getData(new DataStoreKey(request.ObjectKey.PartitionId, request.ObjectKey.ObjectId));
                reply = new ReadReply
                {
                    Object = new DataStoreValueDto {
                        Val = value.val
                    },
                    ObjectExists = true
                };
            }
            catch (Exception)
            {
                reply = new ReadReply
                {
                    Object = new DataStoreValueDto {
                        Val = "NA"
                    },
                    ObjectExists = false
                };
            }

            return(reply);
        }
示例#3
0
        public override Task <ReadReply> Read(ReadRequest req, ServerCallContext _)
        {
            man.CheckFreeze();
            ReadReply reply = new ReadReply {
                Val = store.Read(req.IdPart, req.IdObj)
            };

            Lib.Sleep(new Random().Next(minDelay, maxDelay));
            return(Task.FromResult(reply));
        }
示例#4
0
        public override Task <ReadReply> Read(ReadRequest req, ServerCallContext _)
        {
            man.CheckFreeze();
            ReadReply res = new ReadReply {
                Val = store.Read(req.IdPart, req.IdObj),
                Tag = ServerManager.RInfos[req.IdPart].PInfo.Tag
            };

            Lib.Sleep(new Random().Next(minDelay, maxDelay));
            return(Task.FromResult(res));
        }
示例#5
0
        public async void ReadData()
        {
            // 1. Build the time range for the query: start time and end time.
            DateTime startDate = DateTime.Parse("2020-12-15 09:00:00");
            DateTime endDate   = DateTime.Parse("2020-12-15 09:05:00");

            // 2. Build the condition-based query objec
            ReadOptions readOptions = new ReadOptions.Builder().Read(DataType.DtContinuousStepsDelta)
                                      .SetTimeRange(GetTime(startDate), GetTime(endDate), TimeUnit.Milliseconds)
                                      .Build();

            // 3. Use the specified condition query object to call the data controller to query the sampling dataset.
            // 4. Calling the data controller to query the sampling dataset is an asynchronous Task.

            var ReadTask = MyDataController.ReadAsync(readOptions);

            try
            {
                await ReadTask;

                if (ReadTask.IsCompleted && ReadTask.Result != null)
                {
                    ReadReply result = ReadTask.Result;
                    if (ReadTask.Exception == null)
                    {
                        Logger("Success read of SampleSets from HMS core");
                        foreach (SampleSet sampleSet in result.SampleSets)
                        {
                            ShowSampleSet(sampleSet);
                        }
                        Logger(Split);
                    }
                    else
                    {
                        PrintFailureMessage(ReadTask.Exception, "Read");
                    }
                }
            }
            catch (Exception ex)
            {
                PrintFailureMessage(ex, "Read");
            }
        }
示例#6
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);
        }