Пример #1
0
        public IFuture <T> LoadFuture(string key, CacheLoader <T> loader)
        {
            stopwatch_.Start();
            T previous_value = old_value_.Value;

            try {
                // If the T is a value type and its value is default(T) it will never
                // be reloaded and always loaded from the cache loader. We could
                // make the parameter T nullable, but this makes the code much more
                // complicated and we do not want that.
                if (typeof(T).IsValueType || (object)previous_value == null)
                {
                    T new_value = loader.Load(key);
                    return(Set(new_value) ? this : Futures.ImmediateFuture(new_value));
                }
                else
                {
                    IFuture <T> new_value_future = loader.Reload(key, previous_value);
                    return(new_value_future ?? Futures.ImmediateFuture(default(T)));
                }
            } catch (Exception exception) {
                return(SetException(exception)
          ? this
          : Futures.ImmediateFailedFuture <T>(exception));
            }
        }
Пример #2
0
 /// <exception cref="System.Exception"/>
 public virtual ListenableFuture <T> Answer(InvocationOnMock invocation)
 {
     if (this._enclosing.r.NextFloat() < this.faultProbability)
     {
         return(Futures.ImmediateFailedFuture(new IOException("Injected fault")));
     }
     return((ListenableFuture <T>)invocation.CallRealMethod());
 }
Пример #3
0
 public override Future <FileStatus> Load(Path path)
 {
     try
     {
         FileSystem fs = path.GetFileSystem(conf);
         return(Futures.ImmediateFuture(fs.GetFileStatus(path)));
     }
     catch (Exception th)
     {
         // report failures so it can be memoized
         return(Futures.ImmediateFailedFuture(th));
     }
 }
Пример #4
0
        public override ListenableFuture <Void> SendEdits(long segmentTxId, long firstTxnId
                                                          , int numTxns, byte[] data)
        {
            try
            {
                ReserveQueueSpace(data.Length);
            }
            catch (LoggerTooFarBehindException e)
            {
                return(Futures.ImmediateFailedFuture(e));
            }
            // When this batch is acked, we use its submission time in order
            // to calculate how far we are lagging.
            long submitNanos            = Runtime.NanoTime();
            ListenableFuture <Void> ret = null;

            try
            {
                ret = singleThreadExecutor.Submit(new _Callable_378(this, segmentTxId, firstTxnId
                                                                    , numTxns, data, submitNanos));
            }
            finally
            {
                if (ret == null)
                {
                    // it didn't successfully get submitted,
                    // so adjust the queue size back down.
                    UnreserveQueueSpace(data.Length);
                }
                else
                {
                    // It was submitted to the queue, so adjust the length
                    // once the call completes, regardless of whether it
                    // succeeds or fails.
                    Futures.AddCallback(ret, new _FutureCallback_428(this, data));
                }
            }
            return(ret);
        }
        internal static Stubber FutureThrows(Exception t)
        {
            ListenableFuture <object> ret = Futures.ImmediateFailedFuture(t);

            return(Org.Mockito.Mockito.DoReturn(ret));
        }