Ejemplo n.º 1
0
        public static IStorageResponse PerformRequest(this DataSet storage, IStorageRequest r)
        {
            if (r.Shape == null && (r.Stride != null || r.Origin != null))
            {
                throw new InvalidOperationException("Cannot perform data request with non-zero origin or stride and unknown shape");
            }
            if (!storage.Variables.Contains(r.VariableName))
            {
                throw new InvalidOperationException("Variable " + r.VariableName + " is not found in dataset");
            }

            Array data = null;

            for (int i = 0; i < RetryTimeouts.Length; i++)
            {
                try
                {
                    System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
                    traceSource.TraceEvent(System.Diagnostics.TraceEventType.Start, 8, string.Format("requesting GetData. var \"{0}\"", r.VariableName));
                    if (r.Origin == null && r.Shape == null && r.Stride == null)
                    {
                        data = storage[r.VariableName].GetData();
                    }
                    else if (r.Stride == null) // r.Shape is not null (see preconditions)
                    {
                        data = storage[r.VariableName].GetData(r.Origin, r.Shape);
                    }
                    else
                    {
                        data = storage[r.VariableName].GetData(r.Origin, r.Stride, r.Shape);
                    }
                    sw.Stop();
                    traceSource.TraceEvent(System.Diagnostics.TraceEventType.Stop, 8, string.Format("GetData done in {1}. var \"{0}\"", r.VariableName, sw.Elapsed));
                    return(new StorageResponse(r, data));
                }
                catch (Exception exc)
                {
                    int millisecSleep = (int)(RetryTimeouts[i] * (0.9 + random.NextDouble() * 0.2));
                    traceSource.TraceEvent(System.Diagnostics.TraceEventType.Error, 9, string.Format("GetData failed with {2}. var {1}. sleeping for {0} sec and retrying", millisecSleep * 0.001, r.VariableName, exc.ToString()));
                    System.Threading.Thread.Sleep(millisecSleep);
                }
            }

            traceSource.TraceEvent(System.Diagnostics.TraceEventType.Critical, 10, string.Format("Request to data set {0} failed after {1} retries", storage.URI, RetryTimeouts.Length));
            throw new InvalidOperationException(String.Format("Data is not available after {0} retries", RetryTimeouts.Length));
        }
Ejemplo n.º 2
0
        public async Task <IStorageResponse[]> GetDataAsync(params IStorageRequest[] requests)
        {
            var fixedrequests = new IStorageRequest[requests.Length];

            for (int i = 0; i < requests.Length; ++i)
            {
                if (requests[i].Shape != null)
                {
                    for (int j = 0; j < requests[i].Shape.Length; ++j)
                    {
                        int top = (requests[i].Origin == null ? 0 : requests[i].Origin[j]) + (requests[i].Stride == null ? 1 : requests[i].Stride[j]) * requests[i].Shape[j];
                        if (top > definition.DimensionsLengths[definition.VariablesDimensions[requests[i].VariableName][j]])
                        {
                            throw new IndexOutOfRangeException("Requested area is out of bounds.");
                        }
                    }
                    fixedrequests[i] = requests[i];
                }
                else
                {
                    int[] shp = new int[definition.VariablesDimensions[requests[i].VariableName].Length];
                    for (int j = 0; j < shp.Length; ++j)
                    {
                        shp[j] = (definition.DimensionsLengths[definition.VariablesDimensions[requests[i].VariableName][j]] - (requests[i].Origin == null ? 0 : requests[i].Origin[j])) / (requests[i].Stride == null ? 1 : requests[i].Stride[j]);
                    }
                    fixedrequests[i] = new StorageRequest(requests[i].VariableName, requests[i].Origin, requests[i].Stride, shp);
                }
            }
            var st = new StorageTask
            {
                Completion = new TaskCompletionSource <IStorageResponse[]>(),
                Request    = fixedrequests
            };

            requestHandler.OnNext(st);
            return(await st.Completion.Task);
        }
Ejemplo n.º 3
0
 public StorageResponse(IStorageRequest request, Array data)
 {
     this.request = request;
     this.data    = data;
 }