Пример #1
0
 /**
  * {@inheritDoc}
  */
 public virtual void Refresh()
 {
     if (refreshLock.TryLock())
     {
         try
         {
             dataModel.Refresh();
         }
         finally
         {
             refreshLock.Unlock();
         }
     }
 }
Пример #2
0
        /// <summary>
        /// You must call this (or <seealso cref="#maybeRefreshBlocking()"/>), periodically, if
        /// you want that <seealso cref="#acquire()"/> will return refreshed instances.
        ///
        /// <p>
        /// <b>Threads</b>: it's fine for more than one thread to call this at once.
        /// Only the first thread will attempt the refresh; subsequent threads will see
        /// that another thread is already handling refresh and will return
        /// immediately. Note that this means if another thread is already refreshing
        /// then subsequent threads will return right away without waiting for the
        /// refresh to complete.
        ///
        /// <p>
        /// If this method returns true it means the calling thread either refreshed or
        /// that there were no changes to refresh. If it returns false it means another
        /// thread is currently refreshing.
        /// </p> </summary>
        /// <exception cref="IOException"> if refreshing the resource causes an <seealso cref="IOException"/> </exception>
        /// <exception cref="ObjectDisposedException"> if the reference manager has been <seealso cref="#close() closed"/>.  </exception>
        public bool MaybeRefresh()
        {
            EnsureOpen();

            // Ensure only 1 thread does refresh at once; other threads just return immediately:
            bool doTryRefresh = refreshLock.TryLock();

            if (doTryRefresh)
            {
                try
                {
                    DoMaybeRefresh();
                }
                finally
                {
                    refreshLock.Unlock();
                }
            }

            return(doTryRefresh);
        }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public void Refresh()
 {
     if (refreshLock.TryLock())
     {
         try
         {
             dataModel.Refresh();
             try
             {
                 BuildAverageDiffs();
             }
             catch (TasteException te)
             {
                 log.Warn("Unexpected exception while refreshing", te);
             }
         }
         finally
         {
             refreshLock.Unlock();
         }
     }
 }
Пример #4
0
 /**
  * {@inheritDoc}
  */
 public void Refresh()
 {
     if (refreshLock.TryLock())
     {
         try
         {
             refreshLock.Lock();
             try
             {
                 Reload();
             }
             catch (IOException ioe)
             {
                 log.Warn("Unexpected exception while refreshing", ioe);
             }
         }
         finally
         {
             refreshLock.Unlock();
         }
     }
 }
 internal void TryApplyGlobalSlice()
 {
     if (globalBufferLock.TryLock())
     {
         /*
          * The global buffer must be locked but we don't need to update them if
          * there is an update going on right now. It is sufficient to apply the
          * deletes that have been added after the current in-flight global slices
          * tail the next time we can get the lock!
          */
         try
         {
             if (UpdateSlice(globalSlice))
             {
                 //          System.out.println(Thread.currentThread() + ": apply globalSlice");
                 globalSlice.Apply(globalBufferedUpdates, BufferedUpdates.MAX_INT32);
             }
         }
         finally
         {
             globalBufferLock.Unlock();
         }
     }
 }