Class ProducerConsumer<T>
- Namespace
- Common
- Assembly
- Lykke.Common.dll
Producer-consumer pattern implementation.
public abstract class ProducerConsumer<T> : IStartStop, IStartable, IStopable, IDisposable where T : class
Type Parameters
T
Item type to produce and consume
- Inheritance
-
ProducerConsumer<T>
- Implements
-
IStartable
- Derived
- Inherited Members
- Extension Methods
Constructors
ProducerConsumer(ILog)
[Obsolete("Use protected ProducerConsumer([NotNull] string componentName, [NotNull] ILogFactory logFactory, bool enableAppInisghtsMetric = false)")]
protected ProducerConsumer(ILog log)
Parameters
log
ILog
ProducerConsumer(ILogFactory, string, bool)
protected ProducerConsumer(ILogFactory logFactory, string componentName = null, bool enableAppInisghtsMetric = false)
Parameters
logFactory
ILogFactorycomponentName
stringenableAppInisghtsMetric
bool
ProducerConsumer(string, ILog)
[Obsolete("Use protected ProducerConsumer([NotNull] string componentName, [NotNull] ILogFactory logFactory, bool enableAppInisghtsMetric = false)")]
protected ProducerConsumer(string componentName, ILog log)
Parameters
ProducerConsumer(string, ILog, bool)
[Obsolete("Use protected ProducerConsumer([NotNull] string componentName, [NotNull] ILogFactory logFactory, bool enableAppInisghtsMetric = false)")]
protected ProducerConsumer(string componentName, ILog log, bool enableAppInisghtsMetric)
Parameters
Fields
_componentName
[Obsolete("Use ComponentName")]
protected readonly string _componentName
Field Value
Properties
ComponentName
public string ComponentName { get; }
Property Value
Log
[Obsolete("Use your own log")]
protected ILog Log { get; }
Property Value
Methods
Consume(T)
Override this method to consume next item
protected virtual Task Consume(T item)
Parameters
item
T
Returns
Consume(T, CancellationToken)
Override this method to consume next item with possibility to interrupt execution using cancellationToken
protected virtual Task Consume(T item, CancellationToken cancellationToken)
Parameters
item
TcancellationToken
CancellationToken
Returns
Dispose()
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
Produce(T)
Produces next item. If producer-consumer is not started yet, then it will be started automatically
protected void Produce(T item)
Parameters
item
T
Start()
Starts producer-consumer
public virtual void Start()
Stop()
Stops producer-consumer. Synchronously waits until produced items queue became empty
public virtual void Stop()