1
- using System ;
2
- using System . Linq ;
3
- using WhatNow . Contracts . Data ;
4
- using System . Threading . Tasks ;
5
- using WhatNow . Contracts . Actions ;
6
- using System . Collections . Generic ;
7
- using WhatNow . Contracts . Dependency ;
8
- using WhatNow . Contracts . Resources ;
9
- using WhatNow . Contracts . Statistics ;
10
-
11
- namespace WhatNow . Essentials
1
+ namespace WhatNow . Essentials
12
2
{
3
+ using System ;
4
+ using System . Linq ;
5
+ using WhatNow . Contracts . Data ;
6
+ using System . Threading . Tasks ;
7
+ using WhatNow . Contracts . Actions ;
8
+ using System . Collections . Generic ;
9
+ using WhatNow . Contracts . Dependency ;
10
+ using WhatNow . Contracts . Resources ;
11
+ using WhatNow . Contracts . Statistics ;
12
+
13
13
public class ActionPipe : IActionPipe
14
14
{
15
15
public ActionToken ActionToken { get ; }
@@ -31,13 +31,15 @@ public class ActionPipe : IActionPipe
31
31
public bool BreakRequested => Current . Any ( a => a . BreakRequested ) ;
32
32
33
33
readonly object executionsLock = new object ( ) ;
34
- readonly Dictionary < Type , Queue < TimeSpan > > executions ;
34
+ readonly Dictionary < Type , FixedSizedQueue < TimeSpan > > executions ;
35
35
36
36
public IEnumerable < BreakRequestReason > BreakReasons => actions
37
37
. Select ( a => a . Value . BreakRequestReason )
38
38
. Where ( br => br != null )
39
39
. ToArray ( ) ;
40
40
41
+ public const int MAX_QUEUE_SIZE = 100 ;
42
+
41
43
public ActionPipe ( IActionPipeMap map , ActionToken actionToken , IDependencyResolver dependencyResolver )
42
44
{
43
45
ActionToken = actionToken ;
@@ -50,7 +52,7 @@ public ActionPipe(IActionPipeMap map, ActionToken actionToken, IDependencyResolv
50
52
51
53
Current = new IAction [ 0 ] ;
52
54
53
- executions = actions . Keys . ToDictionary ( k => k , _ => new Queue < TimeSpan > ( ) ) ;
55
+ executions = actions . Keys . ToDictionary ( k => k , _ => new FixedSizedQueue < TimeSpan > ( MAX_QUEUE_SIZE ) ) ;
54
56
}
55
57
56
58
public void Restart ( )
@@ -63,6 +65,10 @@ public void Restart()
63
65
. ToDictionary ( k => k , t => ( IAction ) dependencyResolver . Resolve ( t ) ) ;
64
66
65
67
Current = new IAction [ 0 ] ;
68
+
69
+ lock ( executionsLock )
70
+ foreach ( var type in executions . Values )
71
+ type . Clear ( ) ;
66
72
}
67
73
68
74
public bool TryGetNextTask ( IResourceManager resourceManager , TaskFactory taskFactory , out Task task )
0 commit comments