19 using Lucene.Net.Support;
21 namespace Lucene.Net.Store
40 public static long LOCK_POLL_INTERVAL = 1000;
45 public const long LOCK_OBTAIN_WAIT_FOREVER = - 1;
52 public abstract bool Obtain();
58 protected internal System.Exception failureReason;
76 public virtual bool Obtain(
long lockWaitTimeout)
79 bool locked = Obtain();
80 if (lockWaitTimeout < 0 && lockWaitTimeout != LOCK_OBTAIN_WAIT_FOREVER)
81 throw new System.ArgumentException(
"lockWaitTimeout should be LOCK_OBTAIN_WAIT_FOREVER or a non-negative number (got " + lockWaitTimeout +
")");
83 long maxSleepCount = lockWaitTimeout / LOCK_POLL_INTERVAL;
87 if (lockWaitTimeout != LOCK_OBTAIN_WAIT_FOREVER && sleepCount++ >= maxSleepCount)
89 System.String reason =
"Lock obtain timed out: " + this.ToString();
90 if (failureReason != null)
92 reason += (
": " + failureReason);
94 var e = failureReason != null
101 System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(LOCK_POLL_INTERVAL));
103 catch (System.Threading.ThreadInterruptedException)
113 public abstract void Release();
118 public abstract bool IsLocked();
124 private Lock lock_Renamed;
125 private long lockWaitTimeout;
129 protected With(
Lock lock_Renamed,
long lockWaitTimeout)
131 this.lock_Renamed = lock_Renamed;
132 this.lockWaitTimeout = lockWaitTimeout;
136 protected internal abstract System.Object DoBody();
147 public virtual System.Object run()
152 locked = lock_Renamed.Obtain(lockWaitTimeout);
158 lock_Renamed.Release();