Skip to content

Commit 2499904

Browse files
Rename TaskLogImpl to TaskLogger
This change also removes the TaskLog interface, because we will not need it shortly. Conflicts: src/com/linkedin/parseq/BaseTask.java
1 parent bf0b8b9 commit 2499904

File tree

7 files changed

+46
-76
lines changed

7 files changed

+46
-76
lines changed

src/com/linkedin/parseq/BaseTask.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.linkedin.parseq;
1818

19+
import com.linkedin.parseq.internal.TaskLogger;
1920
import com.linkedin.parseq.promise.DelegatingPromise;
2021
import com.linkedin.parseq.promise.Promise;
2122
import com.linkedin.parseq.promise.PromiseListener;
@@ -139,7 +140,7 @@ public boolean setPriority(final int priority)
139140

140141
@Override
141142
public final void contextRun(final Context context,
142-
final TaskLog taskLog,
143+
final TaskLogger taskLogger,
143144
final Task<?> parent,
144145
final Collection<Task<?>> predecessors)
145146
{
@@ -154,7 +155,7 @@ public final void contextRun(final Context context,
154155
}
155156
_relationshipBuilder.addRelationship(Relationship.SUCCESSOR_OF, predecessors);
156157

157-
taskLog.logTaskStart(this);
158+
taskLogger.logTaskStart(this);
158159
try
159160
{
160161
promise = doContextRun(context);
@@ -171,18 +172,18 @@ public void onResolved(Promise<T> resolvedPromise)
171172
{
172173
if (promise.isFailed())
173174
{
174-
fail(promise.getError() , taskLog);
175+
fail(promise.getError() , taskLogger);
175176
}
176177
else
177178
{
178-
done(promise.get(), taskLog);
179+
done(promise.get(), taskLogger);
179180
}
180181
}
181182
});
182183
}
183184
catch (Throwable t)
184185
{
185-
fail(t, taskLog);
186+
fail(t, taskLogger);
186187
}
187188
}
188189
else
@@ -256,7 +257,7 @@ public Set<Related<Task<?>>> getRelationships()
256257
*/
257258
protected abstract Promise<? extends T> run(final Context context) throws Throwable;
258259

259-
private void done(final T value, final TaskLog taskLog)
260+
private void done(final T value, final TaskLogger taskLog)
260261
{
261262
if (transitionDone())
262263
{
@@ -265,7 +266,7 @@ private void done(final T value, final TaskLog taskLog)
265266
}
266267
}
267268

268-
private void fail(final Throwable error, final TaskLog taskLog)
269+
private void fail(final Throwable error, final TaskLogger taskLog)
269270
{
270271
if (transitionDone())
271272
{

src/com/linkedin/parseq/Engine.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.linkedin.parseq.internal.RejectedSerialExecutionHandler;
2222
import com.linkedin.parseq.internal.SerialExecutionException;
2323
import com.linkedin.parseq.internal.SerialExecutor;
24-
import com.linkedin.parseq.internal.TaskLogImpl;
24+
import com.linkedin.parseq.internal.TaskLogger;
2525
import com.linkedin.parseq.promise.Promise;
2626
import com.linkedin.parseq.promise.PromiseListener;
2727
import org.slf4j.ILoggerFactory;
@@ -127,9 +127,9 @@ public void run(final Task<?> task)
127127
} while (!_stateRef.compareAndSet(currState, newState));
128128

129129
final Logger planLogger = _loggerFactory.getLogger(LOGGER_BASE + ":planClass=" + task.getClass().getName());
130-
final TaskLog taskLog = new TaskLogImpl(task, _allLogger, _rootLogger, planLogger);
130+
final TaskLogger taskLogger = new TaskLogger(task, _allLogger, _rootLogger, planLogger);
131131
new ContextImpl(new SerialExecutor(_taskExecutor, new CancelPlanRejectionHandler(task)),
132-
_timerExecutor, task, taskLog, this).runTask();
132+
_timerExecutor, task, taskLogger, this).runTask();
133133

134134
InternalUtil.unwildcardTask(task).addListener(_taskDoneListener);
135135
}

src/com/linkedin/parseq/Task.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.linkedin.parseq;
1818

19+
import com.linkedin.parseq.internal.TaskLogger;
1920
import com.linkedin.parseq.promise.Promise;
2021
import com.linkedin.parseq.trace.Related;
2122
import com.linkedin.parseq.trace.ShallowTrace;
@@ -74,11 +75,11 @@ public interface Task<T> extends Promise<T>, Cancellable
7475
* reserved for use by {@link Engine} and {@link Context}.
7576
*
7677
* @param context the context to use while running this step
77-
* @param taskLog the logger used for task events
78+
* @param taskLogger the logger used for task events
7879
* @param parent the parent of this task
7980
* @param predecessors that lead to the execution of this task
8081
*/
81-
void contextRun(Context context, TaskLog taskLog,
82+
void contextRun(Context context, TaskLogger taskLogger,
8283
Task<?> parent, Collection<Task<?>> predecessors);
8384

8485

src/com/linkedin/parseq/TaskLog.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/com/linkedin/parseq/internal/ContextImpl.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.linkedin.parseq.EarlyFinishException;
2424
import com.linkedin.parseq.Engine;
2525
import com.linkedin.parseq.Task;
26-
import com.linkedin.parseq.TaskLog;
2726
import com.linkedin.parseq.promise.Promise;
2827
import com.linkedin.parseq.promise.PromiseListener;
2928

@@ -79,7 +78,7 @@ public class ContextImpl implements Context, Cancellable
7978

8079
private final Task<?> _parent;
8180
private final List<Task<?>> _predecessorTasks;
82-
private final TaskLog _taskLog;
81+
private final TaskLogger _taskLogger;
8382

8483
private final Engine _engine;
8584

@@ -88,26 +87,26 @@ public class ContextImpl implements Context, Cancellable
8887
public ContextImpl(final Executor taskExecutor,
8988
final DelayedExecutor timerScheduler,
9089
final Task<?> task,
91-
final TaskLog taskLog,
90+
final TaskLogger taskLogger,
9291
final Engine engine)
9392
{
94-
this(taskExecutor, timerScheduler, task, NO_PARENT, NO_PREDECESSORS, taskLog, engine);
93+
this(taskExecutor, timerScheduler, task, NO_PARENT, NO_PREDECESSORS, taskLogger, engine);
9594
}
9695

9796
private ContextImpl(final Executor taskExecutor,
9897
final DelayedExecutor timerScheduler,
9998
final Task<?> task,
10099
final Task<?> parent,
101100
final List<Task<?>> predecessorTasks,
102-
final TaskLog taskLog,
101+
final TaskLogger taskLogger,
103102
final Engine engine)
104103
{
105104
_timerScheduler = timerScheduler;
106105
_taskExecutor = taskExecutor;
107106
_task = InternalUtil.unwildcardTask(task);
108107
_parent = parent;
109108
_predecessorTasks = predecessorTasks;
110-
_taskLog = taskLog;
109+
_taskLogger = taskLogger;
111110
_engine = engine;
112111
}
113112

@@ -136,7 +135,7 @@ public void run()
136135
_inTask.set(_task);
137136
try
138137
{
139-
_task.contextRun(ContextImpl.this, _taskLog, _parent, _predecessorTasks);
138+
_task.contextRun(ContextImpl.this, _taskLogger, _parent, _predecessorTasks);
140139
}
141140
finally
142141
{
@@ -215,7 +214,7 @@ public boolean cancel(Exception reason)
215214
{
216215
boolean result = _task.cancel(reason);
217216
//run the task to capture the trace data
218-
_task.contextRun(this, _taskLog, _parent, _predecessorTasks);
217+
_task.contextRun(this, _taskLogger, _parent, _predecessorTasks);
219218
return result;
220219
}
221220

@@ -227,7 +226,7 @@ public Object getEngineProperty(String key)
227226

228227
private ContextImpl createSubContext(final Task<?> task, final List<Task<?>> predecessors)
229228
{
230-
return new ContextImpl(_taskExecutor, _timerScheduler, task, _task, predecessors, _taskLog, _engine);
229+
return new ContextImpl(_taskExecutor, _timerScheduler, task, _task, predecessors, _taskLogger, _engine);
231230
}
232231

233232
private void runSubTask(final Task<?> task, final List<Task<?>> predecessors)

src/com/linkedin/parseq/internal/TaskLogImpl.java renamed to src/com/linkedin/parseq/internal/TaskLogger.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.linkedin.parseq.internal;
1818

1919
import com.linkedin.parseq.Task;
20-
import com.linkedin.parseq.TaskLog;
2120
import com.linkedin.parseq.trace.ResultType;
2221
import com.linkedin.parseq.trace.ShallowTrace;
2322
import org.slf4j.Logger;
@@ -38,29 +37,34 @@
3837
*
3938
* @author Chris Pettitt ([email protected])
4039
*/
41-
public class TaskLogImpl implements TaskLog
40+
public class TaskLogger
4241
{
4342
private static final String START_TASK_FORMAT = "[plan={}]: Starting task '{}'";
4443
private static final String END_TASK_DEBUG_FORMAT = "[plan={}]: Ending task '{}'. Elapsed: {}ms, Result type: {}.";
4544
private static final String END_TASK_TRACE_FORMAT = "[plan={}]: Ending task '{}'. Elapsed: {}ms, Result type: {}. Value: {}.";
4645

4746
private static final AtomicLong _nextPlanId = new AtomicLong();
4847

48+
/**
49+
* The root task for the plan. Used to determine if a given task should be
50+
* logged using the plan logger.
51+
*/
4952
private final Task<?> _root;
5053

54+
/** A locally assigned plan id to disambiguate plan logging. */
5155
private final long _planId;
5256

53-
// Logs every trace it finds
57+
/** Logs every trace it finds. */
5458
private final Logger _allLogger;
5559

56-
// Logs only root traces
60+
/** Logs only root traces. */
5761
private final Logger _rootLogger;
5862

59-
// Logs all tasks for this this plan
63+
/** Logs all tasks for this this plan. */
6064
private final Logger _planLogger;
6165

62-
public TaskLogImpl(final Task<?> root, final Logger allLogger,
63-
final Logger rootLogger, final Logger planLogger)
66+
public TaskLogger(final Task<?> root, final Logger allLogger,
67+
final Logger rootLogger, final Logger planLogger)
6468
{
6569
_allLogger = allLogger;
6670
_rootLogger = rootLogger;
@@ -69,7 +73,6 @@ public TaskLogImpl(final Task<?> root, final Logger allLogger,
6973
_planId = _nextPlanId.getAndIncrement();
7074
}
7175

72-
@Override
7376
public void logTaskStart(final Task<?> task)
7477
{
7578
if (_planLogger.isDebugEnabled())
@@ -86,15 +89,14 @@ else if (_allLogger.isDebugEnabled())
8689
}
8790
}
8891

89-
@Override
9092
public void logTaskEnd(final Task<?> task)
9193
{
9294
if (_planLogger.isTraceEnabled())
9395
{
9496
_planLogger.trace(END_TASK_TRACE_FORMAT,
95-
new Object[] {_planId, task.getName(),
96-
elapsedMillis(task),
97-
ResultType.fromTask(task), stringValue(task)});
97+
new Object[]{_planId, task.getName(),
98+
elapsedMillis(task),
99+
ResultType.fromTask(task), stringValue(task)});
98100
}
99101
else if (_planLogger.isDebugEnabled())
100102
{
@@ -105,9 +107,9 @@ else if (_planLogger.isDebugEnabled())
105107
else if (_root == task && _rootLogger.isTraceEnabled())
106108
{
107109
_rootLogger.trace(END_TASK_TRACE_FORMAT,
108-
new Object[] {_planId, task.getName(),
109-
elapsedMillis(task),
110-
ResultType.fromTask(task), stringValue(task)});
110+
new Object[]{_planId, task.getName(),
111+
elapsedMillis(task),
112+
ResultType.fromTask(task), stringValue(task)});
111113
}
112114
else if (_root == task && _rootLogger.isDebugEnabled())
113115
{

test/com/linkedin/parseq/TestTaskStates.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.linkedin.parseq;
1818

19+
import com.linkedin.parseq.internal.TaskLogger;
1920
import com.linkedin.parseq.promise.Promise;
2021
import com.linkedin.parseq.promise.PromiseException;
2122
import com.linkedin.parseq.promise.PromiseUnresolvedException;
@@ -430,8 +431,13 @@ public Object getEngineProperty(String key)
430431
}
431432
}
432433

433-
private static class NullTaskLog implements TaskLog
434+
private static class NullTaskLog extends TaskLogger
434435
{
436+
public NullTaskLog()
437+
{
438+
super(null, null, null, null);
439+
}
440+
435441
@Override
436442
public void logTaskStart(final Task<?> task)
437443
{

0 commit comments

Comments
 (0)