19
19
import com .linkedin .parseq .After ;
20
20
import com .linkedin .parseq .Cancellable ;
21
21
import com .linkedin .parseq .Context ;
22
- import com .linkedin .parseq .DelayedExecutor ;
23
22
import com .linkedin .parseq .EarlyFinishException ;
24
- import com .linkedin .parseq .Engine ;
25
23
import com .linkedin .parseq .Task ;
26
24
import com .linkedin .parseq .promise .Promise ;
27
25
import com .linkedin .parseq .promise .PromiseListener ;
32
30
import java .util .Iterator ;
33
31
import java .util .List ;
34
32
import java .util .concurrent .ConcurrentLinkedQueue ;
35
- import java .util .concurrent .Executor ;
36
33
import java .util .concurrent .TimeUnit ;
37
34
38
35
/**
@@ -57,17 +54,10 @@ public class ContextImpl implements Context, Cancellable
57
54
}
58
55
}
59
56
60
- private final DelayedExecutor _timerScheduler ;
61
-
62
- /* An executor that provides two guarantees:
63
- *
64
- * 1. Only one task is executed at a time
65
- * 2. The completion of a task happens-before the execution of the next task
66
- *
67
- * For more on the happens-before constraint see the java.util.concurrent
68
- * package documentation.
57
+ /**
58
+ * Plan level configuration and facilities.
69
59
*/
70
- private final Executor _taskExecutor ;
60
+ private final PlanContext _planContext ;
71
61
72
62
private final Task <Object > _task ;
73
63
@@ -78,36 +68,24 @@ public class ContextImpl implements Context, Cancellable
78
68
79
69
private final Task <?> _parent ;
80
70
private final List <Task <?>> _predecessorTasks ;
81
- private final TaskLogger _taskLogger ;
82
-
83
- private final Engine _engine ;
84
71
85
72
private final ConcurrentLinkedQueue <Cancellable > _cancellables = new ConcurrentLinkedQueue <Cancellable >();
86
73
87
- public ContextImpl (final Executor taskExecutor ,
88
- final DelayedExecutor timerScheduler ,
89
- final Task <?> task ,
90
- final TaskLogger taskLogger ,
91
- final Engine engine )
74
+ public ContextImpl (final PlanContext planContext ,
75
+ final Task <?> task )
92
76
{
93
- this (taskExecutor , timerScheduler , task , NO_PARENT , NO_PREDECESSORS , taskLogger , engine );
77
+ this (planContext , task , NO_PARENT , NO_PREDECESSORS );
94
78
}
95
79
96
- private ContextImpl (final Executor taskExecutor ,
97
- final DelayedExecutor timerScheduler ,
80
+ private ContextImpl (final PlanContext planContext ,
98
81
final Task <?> task ,
99
82
final Task <?> parent ,
100
- final List <Task <?>> predecessorTasks ,
101
- final TaskLogger taskLogger ,
102
- final Engine engine )
83
+ final List <Task <?>> predecessorTasks )
103
84
{
104
- _timerScheduler = timerScheduler ;
105
- _taskExecutor = taskExecutor ;
85
+ _planContext = planContext ;
106
86
_task = InternalUtil .unwildcardTask (task );
107
87
_parent = parent ;
108
88
_predecessorTasks = predecessorTasks ;
109
- _taskLogger = taskLogger ;
110
- _engine = engine ;
111
89
}
112
90
113
91
public void runTask ()
@@ -127,15 +105,15 @@ public void onResolved(Promise<Object> resolvedPromise)
127
105
}
128
106
});
129
107
130
- _taskExecutor .execute (new PrioritizableRunnable ()
108
+ _planContext .execute (new PrioritizableRunnable ()
131
109
{
132
110
@ Override
133
111
public void run ()
134
112
{
135
113
_inTask .set (_task );
136
114
try
137
115
{
138
- _task .contextRun (ContextImpl .this , _taskLogger , _parent , _predecessorTasks );
116
+ _task .contextRun (ContextImpl .this , _planContext . getTaskLogger () , _parent , _predecessorTasks );
139
117
}
140
118
finally
141
119
{
@@ -156,7 +134,7 @@ public Cancellable createTimer(final long time, final TimeUnit unit,
156
134
final Task <?> task )
157
135
{
158
136
checkInTask ();
159
- final Cancellable cancellable = _timerScheduler .schedule (time , unit , new Runnable ()
137
+ final Cancellable cancellable = _planContext .schedule (time , unit , new Runnable ()
160
138
{
161
139
@ Override
162
140
public void run ()
@@ -214,19 +192,19 @@ public boolean cancel(Exception reason)
214
192
{
215
193
boolean result = _task .cancel (reason );
216
194
//run the task to capture the trace data
217
- _task .contextRun (this , _taskLogger , _parent , _predecessorTasks );
195
+ _task .contextRun (this , _planContext . getTaskLogger () , _parent , _predecessorTasks );
218
196
return result ;
219
197
}
220
198
221
199
@ Override
222
200
public Object getEngineProperty (String key )
223
201
{
224
- return _engine . getProperty (key );
202
+ return _planContext . getEngineProperty (key );
225
203
}
226
204
227
205
private ContextImpl createSubContext (final Task <?> task , final List <Task <?>> predecessors )
228
206
{
229
- return new ContextImpl (_taskExecutor , _timerScheduler , task , _task , predecessors , _taskLogger , _engine );
207
+ return new ContextImpl (_planContext , task , _task , predecessors );
230
208
}
231
209
232
210
private void runSubTask (final Task <?> task , final List <Task <?>> predecessors )
0 commit comments