Revision 5e31048f trunk/Pithos.Core/Agents/StatusAgent.cs
b/trunk/Pithos.Core/Agents/StatusAgent.cs | ||
---|---|---|
7 | 7 |
using System.Linq; |
8 | 8 |
using System.Threading; |
9 | 9 |
using System.Threading.Tasks; |
10 |
using System.Threading.Tasks.Dataflow; |
|
10 | 11 |
using Castle.ActiveRecord; |
11 | 12 |
using Castle.ActiveRecord.Framework.Config; |
12 | 13 |
using Pithos.Interfaces; |
... | ... | |
24 | 25 |
[System.ComponentModel.Composition.Import] |
25 | 26 |
public IPithosSettings Settings { get; set; } |
26 | 27 |
|
27 |
private Agent<Action> _persistenceAgent; |
|
28 |
//private Agent<Action> _persistenceAgent; |
|
29 |
private ActionBlock<Action> _persistenceAgent; |
|
28 | 30 |
|
29 | 31 |
|
30 | 32 |
private static readonly ILog Log = LogManager.GetLogger("StatusAgent"); |
... | ... | |
74 | 76 |
|
75 | 77 |
public void StartProcessing(CancellationToken token) |
76 | 78 |
{ |
77 |
_persistenceAgent = Agent<Action>.Start(queue =>
|
|
79 |
_persistenceAgent = new ActionBlock<Action>(async action=>
|
|
78 | 80 |
{ |
79 |
Action loop = null;
|
|
80 |
loop = () =>
|
|
81 |
{
|
|
82 |
var job = queue.Receive();
|
|
83 |
job.ContinueWith(t =>
|
|
81 |
try
|
|
82 |
{
|
|
83 |
await TaskEx.Run(action);
|
|
84 |
}
|
|
85 |
catch (Exception ex)
|
|
84 | 86 |
{ |
85 |
var action = job.Result; |
|
86 |
try |
|
87 |
{ |
|
88 |
action(); |
|
89 |
} |
|
90 |
catch (Exception ex) |
|
91 |
{ |
|
92 |
Log.ErrorFormat("[ERROR] STATE \n{0}",ex); |
|
93 |
} |
|
94 |
queue.DoAsync(loop); |
|
95 |
}); |
|
96 |
}; |
|
97 |
loop(); |
|
87 |
Log.ErrorFormat("[ERROR] STATE \n{0}",ex); |
|
88 |
} |
|
98 | 89 |
}); |
99 | 90 |
|
100 | 91 |
} |
... | ... | |
103 | 94 |
|
104 | 95 |
public void Stop() |
105 | 96 |
{ |
106 |
_persistenceAgent.Stop();
|
|
97 |
_persistenceAgent.Complete();
|
|
107 | 98 |
} |
108 | 99 |
|
109 | 100 |
|
Also available in: Unified diff