Skip to content

Commit c951925

Browse files
committed
tidying up inappropriate inheritance
1 parent e31d88e commit c951925

File tree

5 files changed

+122
-40
lines changed

5 files changed

+122
-40
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.core.utils.progress.tasks;
21+
22+
import org.neo4j.gds.core.utils.progress.ProgressLogger;
23+
24+
@SuppressWarnings("ClassCanBeRecord")
25+
final class LoggingLeafTaskVisitor implements TaskVisitor {
26+
private final ProgressLogger progressLogger;
27+
28+
LoggingLeafTaskVisitor(ProgressLogger progressLogger) {
29+
this.progressLogger = progressLogger;
30+
}
31+
32+
@Override
33+
public void visitLeafTask(LeafTask leafTask) {
34+
progressLogger.logFinishPercentage();
35+
}
36+
}

progress-tracking/src/main/java/org/neo4j/gds/core/utils/progress/tasks/TaskProgressLogger.java

Lines changed: 76 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,33 @@
2525
import org.neo4j.gds.core.utils.progress.JobId;
2626
import org.neo4j.gds.core.utils.progress.ProgressLogger;
2727

28-
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
28+
import java.util.function.Supplier;
2929

30-
public class TaskProgressLogger extends BatchingProgressLogger {
30+
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
3131

32+
@SuppressWarnings("ClassCanBeRecord")
33+
public final class TaskProgressLogger implements ProgressLogger {
34+
private final BatchingProgressLogger batchingProgressLogger;
3235
private final Task baseTask;
3336
private final TaskVisitor loggingLeafTaskVisitor;
3437

35-
TaskProgressLogger(LoggerForProgressTracking log, JobId jobId, Task baseTask, Concurrency concurrency) {
36-
super(log, jobId, baseTask, concurrency);
37-
this.baseTask = baseTask;
38-
this.loggingLeafTaskVisitor = new LoggingLeafTaskVisitor(this);
38+
static TaskProgressLogger create(LoggerForProgressTracking log, JobId jobId, Task baseTask, Concurrency concurrency) {
39+
var batchingProgressLogger = new BatchingProgressLogger(log, jobId, baseTask, concurrency);
40+
var loggingLeafTaskVisitor = new LoggingLeafTaskVisitor(batchingProgressLogger);
41+
42+
return new TaskProgressLogger(batchingProgressLogger, baseTask, loggingLeafTaskVisitor);
43+
}
44+
45+
static TaskProgressLogger create(LoggerForProgressTracking log, JobId jobId, Task baseTask, Concurrency concurrency, TaskVisitor leafTaskVisitor) {
46+
var batchingProgressLogger = new BatchingProgressLogger(log, jobId, baseTask, concurrency);
47+
48+
return new TaskProgressLogger(batchingProgressLogger, baseTask, leafTaskVisitor);
3949
}
40-
TaskProgressLogger(LoggerForProgressTracking log, JobId jobId, Task baseTask, Concurrency concurrency, TaskVisitor leafTaskVisitor) {
41-
super(log, jobId, baseTask, concurrency);
50+
51+
private TaskProgressLogger(BatchingProgressLogger batchingProgressLogger, Task baseTask, TaskVisitor loggingLeafTaskVisitor) {
52+
this.batchingProgressLogger = batchingProgressLogger;
4253
this.baseTask = baseTask;
43-
this.loggingLeafTaskVisitor = leafTaskVisitor;
54+
this.loggingLeafTaskVisitor = loggingLeafTaskVisitor;
4455
}
4556

4657
void logBeginSubTask(Task task, Task parentTask) {
@@ -104,20 +115,13 @@ private String unboundedIterationsTaskName(
104115

105116
private String taskDescription(Task task, Task parentTask) {
106117
String taskName;
107-
if (parentTask instanceof IterativeTask) {
108-
var iterativeParentTask = (IterativeTask) parentTask;
118+
if (parentTask instanceof IterativeTask iterativeParentTask) {
109119
var iterativeTaskMode = iterativeParentTask.mode();
110-
switch (iterativeTaskMode) {
111-
case DYNAMIC:
112-
case FIXED:
113-
taskName = boundedIterationsTaskName(iterativeParentTask, task);
114-
break;
115-
case OPEN:
116-
taskName = unboundedIterationsTaskName(iterativeParentTask, task);
117-
break;
118-
default:
119-
throw new UnsupportedOperationException(formatWithLocale("Enum value %s is not supported", iterativeTaskMode));
120-
}
120+
121+
taskName = switch (iterativeTaskMode) {
122+
case DYNAMIC, FIXED -> boundedIterationsTaskName(iterativeParentTask, task);
123+
case OPEN -> unboundedIterationsTaskName(iterativeParentTask, task);
124+
};
121125
} else {
122126
taskName = taskDescription(task);
123127
}
@@ -134,17 +138,58 @@ private void log100OnLeafTaskFinish(Task task) {
134138
task.visit(loggingLeafTaskVisitor);
135139
}
136140

137-
private static final class LoggingLeafTaskVisitor implements TaskVisitor {
141+
@Override
142+
public String getTask() {
143+
return batchingProgressLogger.getTask();
144+
}
138145

139-
private final ProgressLogger progressLogger;
146+
@Override
147+
public void setTask(String task) {
148+
batchingProgressLogger.setTask(task);
149+
}
140150

141-
private LoggingLeafTaskVisitor(ProgressLogger progressLogger) {
142-
this.progressLogger = progressLogger;
143-
}
151+
@Override
152+
public void logProgress(Supplier<String> msgFactory) {
153+
batchingProgressLogger.logProgress(msgFactory);
154+
}
144155

145-
@Override
146-
public void visitLeafTask(LeafTask leafTask) {
147-
progressLogger.logFinishPercentage();
148-
}
156+
@Override
157+
public void logProgress(long progress, Supplier<String> msgFactory) {
158+
batchingProgressLogger.logProgress(progress, msgFactory);
159+
}
160+
161+
@Override
162+
public void logMessage(Supplier<String> msg) {
163+
batchingProgressLogger.logMessage(msg);
164+
}
165+
166+
@Override
167+
public void logFinishPercentage() {
168+
batchingProgressLogger.logFinishPercentage();
169+
}
170+
171+
@Override
172+
public void logDebug(Supplier<String> msg) {
173+
batchingProgressLogger.logDebug(msg);
174+
}
175+
176+
@Override
177+
public void logWarning(String msg) {
178+
batchingProgressLogger.logWarning(msg);
179+
}
180+
181+
@Override
182+
public void logError(String msg) {
183+
batchingProgressLogger.logError(msg);
184+
}
185+
186+
@Override
187+
public long reset(long newTaskVolume) {
188+
return batchingProgressLogger.reset(newTaskVolume);
189+
}
190+
191+
@Override
192+
public void release() {
193+
batchingProgressLogger.release();
149194
}
150195
}

progress-tracking/src/main/java/org/neo4j/gds/core/utils/progress/tasks/TaskProgressTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public TaskProgressTracker(
6868
TaskRegistryFactory taskRegistryFactory,
6969
UserLogRegistryFactory userLogRegistryFactory
7070
) {
71-
this(baseTask, jobId, taskRegistryFactory, new TaskProgressLogger(log, jobId, baseTask, concurrency), userLogRegistryFactory);
71+
this(baseTask, jobId, taskRegistryFactory, TaskProgressLogger.create(log, jobId, baseTask, concurrency), userLogRegistryFactory);
7272
}
7373

7474
public TaskProgressTracker(

progress-tracking/src/main/java/org/neo4j/gds/core/utils/progress/tasks/TaskTreeProgressTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public TaskTreeProgressTracker(
3838
baseTask,
3939
jobId,
4040
taskRegistryFactory,
41-
new TaskProgressLogger(
41+
TaskProgressLogger.create(
4242
log,
4343
jobId,
4444
baseTask,

progress-tracking/src/test/java/org/neo4j/gds/core/utils/progress/tasks/TaskProgressLoggerTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@
2828
import static org.assertj.core.api.Assertions.assertThatNoException;
2929

3030
class TaskProgressLoggerTest {
31-
3231
@Test
33-
void shouldNotEliminateParentTaskIfCommonPreffix(){
34-
32+
void shouldNotEliminateParentTaskIfCommonPrefix() {
3533
var taskA = Tasks.leaf("A");
3634
var taskAB = Tasks.task("A B", List.of(taskA));
3735
var task = Tasks.task("T", List.of(taskA));
3836

39-
var logger =new TaskProgressLogger(LoggerForProgressTracking.noOpLog(), new JobId(),task,new Concurrency(1));
37+
var logger = TaskProgressLogger.create(
38+
LoggerForProgressTracking.noOpLog(),
39+
new JobId(),
40+
task,
41+
new Concurrency(1)
42+
);
4043

4144
assertThatNoException().isThrownBy(
42-
()-> {
45+
() -> {
4346
logger.startSubTask("T");
4447
logger.startSubTask("A B");
4548
logger.startSubTask("A ");
@@ -48,7 +51,5 @@ void shouldNotEliminateParentTaskIfCommonPreffix(){
4851
logger.finishSubTask("T");
4952
}
5053
);
51-
5254
}
53-
5455
}

0 commit comments

Comments
 (0)