Skip to content

Commit

Permalink
Lucene.Net.Util: Renamed Events class > WeakEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
NightOwl888 committed Oct 18, 2023
1 parent 8cfab58 commit 6dd2565
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/Lucene.Net.Facet/Taxonomy/CachedOrdinalsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private CachedOrds GetCachedOrds(AtomicReaderContext context)
ordsCache.Add(cacheKey, ords);
#if !FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
// LUCENENET specific: Add weak event handler for .NET Standard 2.0 and .NET Framework, since we don't have an enumerator to use
context.Reader.SubscribeToGetCacheKeysEvent(eventAggregator.GetEvent<Events.GetCacheKeysEvent>());
context.Reader.SubscribeToGetCacheKeysEvent(eventAggregator.GetEvent<WeakEvents.GetCacheKeysEvent>());
#endif
}
return ords;
Expand Down Expand Up @@ -229,8 +229,8 @@ public virtual long RamBytesUsed()
// we use a weak event to retrieve the CachedOrds instances. We look each of these up here to avoid the need
// to attach events to the CachedOrds instances themselves (thus using the existing IndexReader.Dispose()
// method to detach the events rather than using a finalizer in CachedOrds to ensure they are cleaned up).
var e = new Events.GetCacheKeysEventArgs();
eventAggregator.GetEvent<Events.GetCacheKeysEvent>().Publish(e);
var e = new WeakEvents.GetCacheKeysEventArgs();
eventAggregator.GetEvent<WeakEvents.GetCacheKeysEvent>().Publish(e);
foreach (var key in e.CacheKeys)
if (ordsCache.TryGetValue(key, out CachedOrds value))
cachedOrdsList.Add(value);
Expand Down
18 changes: 9 additions & 9 deletions src/Lucene.Net/Index/IndexReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void RegisterParentReader(IndexReader reader)
if (!parentReaders.TryGetValue(key: reader, out _))
{
parentReaders.Add(key: reader, value: null);
reader.SubscribeToGetParentReadersEvent(eventAggregator.GetEvent<Events.GetParentReadersEvent>());
reader.SubscribeToGetParentReadersEvent(eventAggregator.GetEvent<WeakEvents.GetParentReadersEvent>());
}
#endif
}
Expand Down Expand Up @@ -211,8 +211,8 @@ private void ReportDisposeToParentReaders() // LUCENENET: Renamed from reportClo
{
IndexReader target = kvp.Key;
#else
var e = new Events.GetParentReadersEventArgs();
eventAggregator.GetEvent<Events.GetParentReadersEvent>().Publish(e);
var e = new WeakEvents.GetParentReadersEventArgs();
eventAggregator.GetEvent<WeakEvents.GetParentReadersEvent>().Publish(e);
foreach (var target in e.ParentReaders)
{
#endif
Expand Down Expand Up @@ -636,18 +636,18 @@ protected virtual void Dispose(bool disposing)
// LUCENENET specific - since .NET Standard 2.0 and .NET Framework don't have a CondtionalWeakTable enumerator,
// we use a weak event to retrieve the ConditionalWeakTable items
[ExcludeFromRamUsageEstimation]
private readonly ISet<Events.GetParentReadersEvent> getParentReadersEvents = new JCG.HashSet<Events.GetParentReadersEvent>();
private readonly ISet<WeakEvents.GetParentReadersEvent> getParentReadersEvents = new JCG.HashSet<WeakEvents.GetParentReadersEvent>();
[ExcludeFromRamUsageEstimation]
private readonly ISet<Events.GetCacheKeysEvent> getCacheKeysEvents = new JCG.HashSet<Events.GetCacheKeysEvent>();
internal void SubscribeToGetParentReadersEvent(Events.GetParentReadersEvent getParentReadersEvent)
private readonly ISet<WeakEvents.GetCacheKeysEvent> getCacheKeysEvents = new JCG.HashSet<WeakEvents.GetCacheKeysEvent>();
internal void SubscribeToGetParentReadersEvent(WeakEvents.GetParentReadersEvent getParentReadersEvent)
{
if (getParentReadersEvent is null)
throw new ArgumentNullException(nameof(getParentReadersEvent));
if (getParentReadersEvents.Add(getParentReadersEvent))
getParentReadersEvent.Subscribe(OnGetParentReaders);
}

internal void SubscribeToGetCacheKeysEvent(Events.GetCacheKeysEvent getCacheKeysEvent)
internal void SubscribeToGetCacheKeysEvent(WeakEvents.GetCacheKeysEvent getCacheKeysEvent)
{
if (getCacheKeysEvent is null)
throw new ArgumentNullException(nameof(getCacheKeysEvent));
Expand All @@ -662,12 +662,12 @@ internal void SubscribeToGetCacheKeysEvent(Events.GetCacheKeysEvent getCacheKeys
}

// LUCENENET specific: Add weak event handler for .NET Standard 2.0 and .NET Framework, since we don't have an enumerator to use
private void OnGetParentReaders(Events.GetParentReadersEventArgs e)
private void OnGetParentReaders(WeakEvents.GetParentReadersEventArgs e)
{
e.ParentReaders.Add(this);
}

private void OnGetCacheKeys(Events.GetCacheKeysEventArgs e)
private void OnGetCacheKeys(WeakEvents.GetCacheKeysEventArgs e)
{
e.CacheKeys.Add(this.CoreCacheKey);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Lucene.Net/Search/CachingWrapperFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDo
cache.AddOrUpdate(key, docIdSet);
// LUCENENET specific - since .NET Standard 2.0 and .NET Framework don't have a CondtionalWeakTable enumerator,
// we use a weak event to retrieve the DocIdSet instances
reader.SubscribeToGetCacheKeysEvent(eventAggregator.GetEvent<Events.GetCacheKeysEvent>());
reader.SubscribeToGetCacheKeysEvent(eventAggregator.GetEvent<WeakEvents.GetCacheKeysEvent>());
}
finally
{
Expand Down Expand Up @@ -200,8 +200,8 @@ public virtual long GetSizeInBytes()
// we use a weak event to retrieve the DocIdSet instances. We look each of these up here to avoid the need
// to attach events to the DocIdSet instances themselves (thus using the existing IndexReader.Dispose()
// method to detach the events rather than using a finalizer in DocIdSet to ensure they are cleaned up).
var e = new Events.GetCacheKeysEventArgs();
eventAggregator.GetEvent<Events.GetCacheKeysEvent>().Publish(e);
var e = new WeakEvents.GetCacheKeysEventArgs();
eventAggregator.GetEvent<WeakEvents.GetCacheKeysEvent>().Publish(e);
foreach (var key in e.CacheKeys)
if (cache.TryGetValue(key, out DocIdSet value))
docIdSets.Add(value);
Expand Down
6 changes: 3 additions & 3 deletions src/Lucene.Net/Search/FieldCacheImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ private void AddCacheEntries<TKey, TValue>(IList<FieldCache.CacheEntry> result,
#else
// LUCENENET specific - since .NET Standard 2.0 and .NET Framework don't have a CondtionalWeakTable enumerator,
// we use a weak event to retrieve the readerKey instances and then lookup the values in the table one by one.
var e = new Events.GetCacheKeysEventArgs();
eventAggregator.GetEvent<Events.GetCacheKeysEvent>().Publish(e);
var e = new WeakEvents.GetCacheKeysEventArgs();
eventAggregator.GetEvent<WeakEvents.GetCacheKeysEvent>().Publish(e);
foreach (object readerKey in e.CacheKeys)
{
if (cache.readerCache.TryGetValue(readerKey, out IDictionary<TKey, object> innerCache))
Expand Down Expand Up @@ -270,7 +270,7 @@ private void InitReader(AtomicReader reader)
#if !FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
// LUCENENET specific - since .NET Standard 2.0 and .NET Framework don't have a CondtionalWeakTable enumerator,
// we use a weak event to retrieve the readerKey instances
reader.SubscribeToGetCacheKeysEvent(eventAggregator.GetEvent<Events.GetCacheKeysEvent>());
reader.SubscribeToGetCacheKeysEvent(eventAggregator.GetEvent<WeakEvents.GetCacheKeysEvent>());
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Lucene.Net.Util
/// Events are used in Lucene.NET to work around the fact that <see cref="System.Runtime.CompilerServices.ConditionalWeakTable{TKey, TValue}"/>
/// doesn't have an enumerator in .NET Framework or .NET Standard prior to 2.1. They are declared in this static class to avoid adding coupling.
/// </summary>
internal static class Events
internal static class WeakEvents
{
#region GetParentReaders

Expand Down

0 comments on commit 6dd2565

Please sign in to comment.