-
Notifications
You must be signed in to change notification settings - Fork 0
/
StreamDataProcessor.cs
86 lines (74 loc) · 2.68 KB
/
StreamDataProcessor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*==========================================================================;
*
* This file is part of LATINO. See http://latino.sf.net
*
* File: StreamDataProcessor.cs
* Desc: Stream data processor base class
* Created: Dec-2010
*
* Author: Miha Grcar
*
* License: MIT (http://opensource.org/licenses/MIT)
*
***************************************************************************/
using System;
namespace Latino.Workflows
{
/* .-----------------------------------------------------------------------
|
| Class StreamDataProcessor
|
'-----------------------------------------------------------------------
*/
public abstract class StreamDataProcessor : StreamDataConsumer, IDataProducer
{
private Set<IDataConsumer> mDataConsumers
= new Set<IDataConsumer>();
private bool mCloneDataOnFork
= true;
private DispatchPolicy mDispatchPolicy
= DispatchPolicy.ToAll;
public StreamDataProcessor(string loggerName) : base(loggerName)
{
}
public StreamDataProcessor(Type loggerType) : this(loggerType.ToString())
{
}
public bool CloneDataOnFork
{
get { return mCloneDataOnFork; }
set { mCloneDataOnFork = value; }
}
public DispatchPolicy DispatchPolicy
{
get { return mDispatchPolicy; }
set { mDispatchPolicy = value; }
}
public Set<IDataConsumer>.ReadOnly SubscribedConsumers
{
get { return mDataConsumers; }
}
protected override void ConsumeData(IDataProducer sender, object data)
{
// process data
data = ProcessData(sender, data);
// dispatch data
WorkflowUtils.DispatchData(this, data, mCloneDataOnFork, mDispatchPolicy, mDataConsumers, mLogger);
}
public/*protected*/ abstract object ProcessData(IDataProducer sender, object data);
// *** IDataProducer interface implementation ***
public void Subscribe(IDataConsumer dataConsumer)
{
Utils.ThrowException(dataConsumer == null ? new ArgumentNullException("dataConsumer") : null);
mDataConsumers.Add(dataConsumer);
}
public void Unsubscribe(IDataConsumer dataConsumer)
{
Utils.ThrowException(dataConsumer == null ? new ArgumentNullException("dataConsumer") : null);
if (mDataConsumers.Contains(dataConsumer))
{
mDataConsumers.Remove(dataConsumer);
}
}
}
}