Skip to content

Commit c54068f

Browse files
committed
Exposed extension events.
1 parent 04eb2ba commit c54068f

4 files changed

Lines changed: 20 additions & 19 deletions

File tree

Shuttle.Core.Threading/IProcessorThreadPool.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ public interface IProcessorThreadPool : IDisposable
1212
IProcessorThreadPool Start();
1313
Task<IProcessorThreadPool> StartAsync();
1414
IEnumerable<ProcessorThread> ProcessorThreads { get; }
15+
string Name { get; }
16+
IProcessorFactory ProcessorFactory { get; }
17+
ProcessorThreadOptions ThreadOptions { get; }
18+
int ThreadCount { get; }
1519
}
1620
}

Shuttle.Core.Threading/ProcessorThreadPool.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ namespace Shuttle.Core.Threading
88
{
99
public class ProcessorThreadPool : IProcessorThreadPool
1010
{
11-
private readonly string _name;
12-
private readonly IProcessorFactory _processorFactory;
13-
private readonly ProcessorThreadOptions _processorThreadOptions;
11+
public string Name { get; }
12+
public IProcessorFactory ProcessorFactory { get; }
13+
public ProcessorThreadOptions ThreadOptions { get; }
14+
public int ThreadCount { get; }
15+
1416
private readonly List<ProcessorThread> _processorThreads = new List<ProcessorThread>();
1517
private bool _disposed;
1618
private bool _started;
17-
private readonly int _threadCount;
1819

1920
public ProcessorThreadPool(string name, int threadCount, IProcessorFactory processorFactory, ProcessorThreadOptions processorThreadOptions)
2021
{
@@ -26,10 +27,10 @@ public ProcessorThreadPool(string name, int threadCount, IProcessorFactory proce
2627
throw new ThreadCountZeroException();
2728
}
2829

29-
_name = name ?? Guid.NewGuid().ToString();
30-
_processorFactory = processorFactory;
31-
_processorThreadOptions = processorThreadOptions;
32-
_threadCount = threadCount;
30+
Name = name ?? Guid.NewGuid().ToString();
31+
ProcessorFactory = processorFactory;
32+
ThreadOptions = processorThreadOptions;
33+
ThreadCount = threadCount;
3334
}
3435

3536
public event EventHandler<ProcessorThreadCreatedEventArgs> ProcessorThreadCreated;
@@ -74,9 +75,9 @@ private async Task Start(bool sync)
7475

7576
var i = 0;
7677

77-
while (i++ < _threadCount)
78+
while (i++ < ThreadCount)
7879
{
79-
var processorThread = new ProcessorThread($"{_name} / {i}", _processorFactory.Create(), _processorThreadOptions);
80+
var processorThread = new ProcessorThread($"{Name} / {i}", ProcessorFactory.Create(), ThreadOptions);
8081

8182
ProcessorThreadCreated?.Invoke(this, new ProcessorThreadCreatedEventArgs(processorThread));
8283

@@ -114,7 +115,7 @@ protected virtual void Dispose(bool disposing)
114115
thread.Stop();
115116
}
116117

117-
_processorFactory.TryDispose();
118+
ProcessorFactory.TryDispose();
118119
}
119120

120121
_disposed = true;

Shuttle.Core.Threading/ProcessorThreadPoolCreatedEventArgs.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ namespace Shuttle.Core.Threading
55
{
66
public class ProcessorThreadPoolCreatedEventArgs : EventArgs
77
{
8-
public string Name { get; }
9-
public int ThreadCount { get; }
10-
public IProcessorFactory ProcessorFactory { get; }
8+
public IProcessorThreadPool ProcessorThreadPool { get;}
119

12-
public ProcessorThreadPoolCreatedEventArgs(string name, int threadCount, IProcessorFactory processorFactory)
10+
public ProcessorThreadPoolCreatedEventArgs(IProcessorThreadPool processorThreadPool)
1311
{
14-
Name = Guard.AgainstNullOrEmptyString(name, nameof(name));
15-
ThreadCount = threadCount;
16-
ProcessorFactory = Guard.AgainstNull(processorFactory, nameof(processorFactory));
12+
ProcessorThreadPool = Guard.AgainstNull(processorThreadPool, nameof(processorThreadPool));
1713
}
1814
}
1915
}

Shuttle.Core.Threading/ProcessorThreadPoolFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public IProcessorThreadPool Create(string name, int threadCount, IProcessorFacto
1010
{
1111
var result = new ProcessorThreadPool(name, threadCount, processorFactory, processorThreadOptions);
1212

13-
ProcessorThreadPoolCreated?.Invoke(this, new ProcessorThreadPoolCreatedEventArgs(name, threadCount, processorFactory));
13+
ProcessorThreadPoolCreated?.Invoke(this, new ProcessorThreadPoolCreatedEventArgs(result));
1414

1515
return result;
1616
}

0 commit comments

Comments
 (0)