Class ReferenceManager<G>
Utility class to safely share instances of a certain type across multiple threads, while periodically refreshing them. This class ensures each reference is closed only once all threads have finished using it. It is recommended to consult the documentation of ReferenceManager<G> implementations for their MaybeRefresh() semantics.
@lucene.experimental
Inheritance
Assembly: DistributedLucene.Net.dll
Syntax
public abstract class ReferenceManager<G> : IDisposable where G : class
Type Parameters
Name | Description |
---|---|
G | The concrete type that will be Acquire()d and Release(G)d. |
Properties
Name | Description |
---|---|
Current | The current reference |
Methods
Name | Description |
---|---|
Acquire() | Obtain the current reference. You must match every call to acquire with one
call to Release(G); it's best to do so in a finally clause, and set
the reference to |
AddListener(ReferenceManager.IRefreshListener) | Adds a listener, to be notified when a reference is refreshed/swapped. |
AfterMaybeRefresh() | Called after a refresh was attempted, regardless of whether a new reference was in fact created. |
DecRef(G) | Decrement reference counting on the given reference. |
Dispose() | Closes this ReferenceManager to prevent future Acquire()ing. A reference manager should be disposed if the reference to the managed resource should be disposed or the application using the ReferenceManager<G> is shutting down. The managed resource might not be released immediately, if the ReferenceManager<G> user is holding on to a previously Acquire()d reference. The resource will be released once when the last reference is Release(G)d. Those references can still be used as if the manager was still active.
Applications should not Acquire() new references from this
manager once this method has been called. Acquire()ing a
resource on a disposed ReferenceManager<G> will throw an
|
Dispose(Boolean) | Called after Dispose(), so subclass can free any resources. |
GetRefCount(G) | Returns the current reference count of the given reference. |
MaybeRefresh() | You must call this (or MaybeRefreshBlocking()), periodically, if you want that Acquire() will return refreshed instances. Threads: 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.
If this method returns |
MaybeRefreshBlocking() | You must call this (or MaybeRefresh()), periodically, if you want that Acquire() will return refreshed instances. Threads: unlike MaybeRefresh(), if another thread is currently refreshing, this method blocks until that thread completes. It is useful if you want to guarantee that the next call to Acquire() will return a refreshed instance. Otherwise, consider using the non-blocking MaybeRefresh(). |
RefreshIfNeeded(G) | Refresh the given reference if needed. Returns |
Release(G) | Release the reference previously obtained via Acquire(). NOTE: it's safe to call this after Dispose(). |
RemoveListener(ReferenceManager.IRefreshListener) | Remove a listener added with AddListener(ReferenceManager.IRefreshListener). |
TryIncRef(G) | Try to increment reference counting on the given reference. Returns |