From 053007a7b86416992def59b18d72a4ed1a45c0c6 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Mon, 29 Oct 2018 15:24:23 +0800 Subject: [PATCH] add the number of pending tasks to metrics also refactor class name about task to remove prefix 'Huge' Change-Id: Id21e9d91a0b83b807189fffbee0247219322f234 --- .../com/baidu/hugegraph/api/job/TaskAPI.java | 28 +++++------- .../hugegraph/auth/HugeGraphAuthProxy.java | 4 +- .../baidu/hugegraph/core/GraphManager.java | 9 ++++ .../java/com/baidu/hugegraph/HugeGraph.java | 14 +++--- .../java/com/baidu/hugegraph/job/Job.java | 4 +- .../com/baidu/hugegraph/job/JobBuilder.java | 4 +- .../com/baidu/hugegraph/task/HugeTask.java | 45 ++++++++++--------- ...ugeTaskCallable.java => TaskCallable.java} | 18 ++++---- ...{HugeTaskManager.java => TaskManager.java} | 29 ++++++++---- ...eTaskScheduler.java => TaskScheduler.java} | 18 +++++--- .../task/{Status.java => TaskStatus.java} | 6 +-- .../baidu/hugegraph/example/ExampleUtil.java | 4 +- .../baidu/hugegraph/example/TaskExample.java | 19 ++++---- 13 files changed, 113 insertions(+), 89 deletions(-) rename hugegraph-core/src/main/java/com/baidu/hugegraph/task/{HugeTaskCallable.java => TaskCallable.java} (81%) rename hugegraph-core/src/main/java/com/baidu/hugegraph/task/{HugeTaskManager.java => TaskManager.java} (82%) rename hugegraph-core/src/main/java/com/baidu/hugegraph/task/{HugeTaskScheduler.java => TaskScheduler.java} (97%) rename hugegraph-core/src/main/java/com/baidu/hugegraph/task/{Status.java => TaskStatus.java} (91%) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/TaskAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/TaskAPI.java index 240b672d05..56b85a42f1 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/TaskAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/job/TaskAPI.java @@ -20,6 +20,7 @@ package com.baidu.hugegraph.api.job; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -39,14 +40,14 @@ import org.slf4j.Logger; -import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.api.API; import com.baidu.hugegraph.api.filter.StatusFilter.Status; import com.baidu.hugegraph.backend.id.IdGenerator; import com.baidu.hugegraph.core.GraphManager; import com.baidu.hugegraph.server.RestServer; import com.baidu.hugegraph.task.HugeTask; -import com.baidu.hugegraph.task.HugeTaskScheduler; +import com.baidu.hugegraph.task.TaskScheduler; +import com.baidu.hugegraph.task.TaskStatus; import com.baidu.hugegraph.util.E; import com.baidu.hugegraph.util.Log; import com.codahale.metrics.annotation.Timed; @@ -71,8 +72,7 @@ public Map> list(@Context GraphManager manager, LOG.debug("Graph [{}] list tasks with status {}, limit {}", graph, status, limit); - HugeGraph g = graph(manager, graph); - HugeTaskScheduler scheduler = g.taskScheduler(); + TaskScheduler scheduler = graph(manager, graph).taskScheduler(); Iterator> itor; if (status == null) { @@ -97,8 +97,7 @@ public Map get(@Context GraphManager manager, @PathParam("id") long id) { LOG.debug("Graph [{}] get task: {}", graph, id); - HugeGraph g = graph(manager, graph); - HugeTaskScheduler scheduler = g.taskScheduler(); + TaskScheduler scheduler = graph(manager, graph).taskScheduler(); return scheduler.task(IdGenerator.of(id)).asMap(); } @@ -110,8 +109,7 @@ public void delete(@Context GraphManager manager, @PathParam("id") long id) { LOG.debug("Graph [{}] delete task: {}", graph, id); - HugeGraph g = graph(manager, graph); - HugeTaskScheduler scheduler = g.taskScheduler(); + TaskScheduler scheduler = graph(manager, graph).taskScheduler(); HugeTask task = scheduler.deleteTask(IdGenerator.of(id)); E.checkArgument(task != null, "There is no task with id '%s'", id); } @@ -132,11 +130,8 @@ public Map update(@Context GraphManager manager, "Not support action '%s'", action)); } - HugeGraph g = graph(manager, graph); - HugeTaskScheduler scheduler = g.taskScheduler(); - + TaskScheduler scheduler = graph(manager, graph).taskScheduler(); HugeTask task = scheduler.task(IdGenerator.of(id)); - if (!task.completed()) { scheduler.cancel(task); } else { @@ -146,14 +141,13 @@ public Map update(@Context GraphManager manager, return ImmutableMap.of("cancelled", task.isCancelled()); } - private static com.baidu.hugegraph.task.Status parseStatus(String status) { + private static TaskStatus parseStatus(String status) { try { - return com.baidu.hugegraph.task.Status.valueOf(status); + return TaskStatus.valueOf(status); } catch (Exception e) { throw new IllegalArgumentException(String.format( - "Status value must be in [UNKNOWN, NEW, QUEUED, " + - "RESTORING, RUNNING, SUCCESS, CANCELLED, FAILED], " + - "but got '%s'", status)); + "Status value must be in %s, but got '%s'", + Arrays.asList(TaskStatus.values()), status)); } } } \ No newline at end of file diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java index 9000ed1eb6..d8fb44e20d 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java @@ -42,7 +42,7 @@ import com.baidu.hugegraph.exception.NotSupportException; import com.baidu.hugegraph.schema.SchemaManager; import com.baidu.hugegraph.structure.HugeFeatures; -import com.baidu.hugegraph.task.HugeTaskScheduler; +import com.baidu.hugegraph.task.TaskScheduler; import com.baidu.hugegraph.util.E; import com.baidu.hugegraph.util.Log; @@ -178,7 +178,7 @@ public boolean restoring() { return this.hugegraph.restoring(); } - public HugeTaskScheduler taskScheduler() { + public TaskScheduler taskScheduler() { this.verifyPermission(); return this.hugegraph.taskScheduler(); } diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java index da7e5bce0d..e52c82e06a 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java @@ -50,6 +50,7 @@ import com.baidu.hugegraph.serializer.JsonSerializer; import com.baidu.hugegraph.serializer.Serializer; import com.baidu.hugegraph.server.RestServer; +import com.baidu.hugegraph.task.TaskManager; import com.baidu.hugegraph.util.Log; import com.codahale.metrics.MetricRegistry; @@ -216,6 +217,14 @@ private void addMetrics(HugeConfig config) { } return count; }); + + // Add metrics for task + MetricsUtil.registerGauge(TaskManager.class, "workers", () -> { + return TaskManager.instance().workerPoolSize(); + }); + MetricsUtil.registerGauge(TaskManager.class, "pending-tasks", () -> { + return TaskManager.instance().pendingTasks(); + }); } private void registerCacheMetrics() { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java index 6511e37220..816e3cce4e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java @@ -62,8 +62,8 @@ import com.baidu.hugegraph.schema.SchemaManager; import com.baidu.hugegraph.schema.VertexLabel; import com.baidu.hugegraph.structure.HugeFeatures; -import com.baidu.hugegraph.task.HugeTaskManager; -import com.baidu.hugegraph.task.HugeTaskScheduler; +import com.baidu.hugegraph.task.TaskManager; +import com.baidu.hugegraph.task.TaskScheduler; import com.baidu.hugegraph.traversal.optimize.HugeGraphStepStrategy; import com.baidu.hugegraph.traversal.optimize.HugeVertexStepStrategy; import com.baidu.hugegraph.util.E; @@ -104,7 +104,7 @@ public class HugeGraph implements Graph { private final EventHub schemaEventHub; private final EventHub indexEventHub; private final RateLimiter rateLimiter; - private final HugeTaskManager taskManager; + private final TaskManager taskManager; private final HugeFeatures features; @@ -122,7 +122,7 @@ public HugeGraph(HugeConfig configuration) { final int limit = configuration.get(CoreOptions.RATE_LIMIT); this.rateLimiter = limit > 0 ? RateLimiter.create(limit) : null; - this.taskManager = HugeTaskManager.instance(); + this.taskManager = TaskManager.instance(); this.features = new HugeFeatures(this, true); @@ -294,8 +294,8 @@ public Analyzer analyzer() { return AnalyzerFactory.analyzer(name, mode); } - public HugeTaskScheduler taskScheduler() { - HugeTaskScheduler scheduler = this.taskManager.getScheduler(this); + public TaskScheduler taskScheduler() { + TaskScheduler scheduler = this.taskManager.getScheduler(this); E.checkState(scheduler != null, "Can't find task scheduler for graph '%s'", this); return scheduler; @@ -522,7 +522,7 @@ public Id[] mapVlName2Id(String[] vertexLabels) { */ public static void shutdown(long timout) throws InterruptedException { EventHub.destroy(timout); - HugeTaskManager.instance().shutdown(timout); + TaskManager.instance().shutdown(timout); } private class TinkerpopTransaction extends AbstractThreadLocalTransaction { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/Job.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/Job.java index 80994606de..0ca9ce04ec 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/Job.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/Job.java @@ -22,9 +22,9 @@ import java.util.Date; import com.baidu.hugegraph.task.HugeTask; -import com.baidu.hugegraph.task.HugeTaskCallable; +import com.baidu.hugegraph.task.TaskCallable; -public abstract class Job extends HugeTaskCallable { +public abstract class Job extends TaskCallable { public abstract String type(); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/JobBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/JobBuilder.java index bcbb6f9917..79ba363661 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/JobBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/JobBuilder.java @@ -22,7 +22,7 @@ import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.backend.id.Id; import com.baidu.hugegraph.task.HugeTask; -import com.baidu.hugegraph.task.HugeTaskScheduler; +import com.baidu.hugegraph.task.TaskScheduler; import com.baidu.hugegraph.type.HugeType; import com.baidu.hugegraph.util.E; @@ -68,7 +68,7 @@ public HugeTask schedule() { task.input(this.input); } - HugeTaskScheduler scheduler = this.graph.taskScheduler(); + TaskScheduler scheduler = this.graph.taskScheduler(); scheduler.schedule(task); scheduler.save(task); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTask.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTask.java index 21989d2c15..88fe7c914a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTask.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTask.java @@ -44,10 +44,15 @@ public class HugeTask extends FutureTask { private static final Logger LOG = Log.logger(HugeTask.class); - private static final Set COMPLETED_STATUSES = - ImmutableSet.of(Status.SUCCESS, Status.CANCELLED, Status.FAILED); + private static final Set COMPLETED_STATUSES; - private final HugeTaskCallable callable; + static { + COMPLETED_STATUSES = ImmutableSet.of(TaskStatus.SUCCESS, + TaskStatus.CANCELLED, + TaskStatus.FAILED); + } + + private final TaskCallable callable; private String type; private String name; @@ -56,7 +61,7 @@ public class HugeTask extends FutureTask { private List children; private String description; private Date create; - private volatile Status status; + private volatile TaskStatus status; private volatile int progress; private volatile Date update; private volatile int retries; @@ -64,11 +69,11 @@ public class HugeTask extends FutureTask { private volatile String result; public HugeTask(Id id, Id parent, String callable, String input) { - this(id, parent, HugeTaskCallable.fromClass(callable)); + this(id, parent, TaskCallable.fromClass(callable)); this.input = input; } - public HugeTask(Id id, Id parent, HugeTaskCallable callable) { + public HugeTask(Id id, Id parent, TaskCallable callable) { super(callable); E.checkArgumentNotNull(id, "Task id can't be null"); @@ -82,7 +87,7 @@ public HugeTask(Id id, Id parent, HugeTaskCallable callable) { this.parent = parent; this.children = null; this.description = null; - this.status = Status.NEW; + this.status = TaskStatus.NEW; this.progress = 0; this.create = new Date(); this.update = null; @@ -110,7 +115,7 @@ public void child(Id id) { this.children.add(id); } - public Status status() { + public TaskStatus status() { return this.status; } @@ -193,8 +198,8 @@ public String toString() { @Override public void run() { - assert this.status.code() < Status.RUNNING.code(); - this.status(Status.RUNNING); + assert this.status.code() < TaskStatus.RUNNING.code(); + this.status(TaskStatus.RUNNING); super.run(); } @@ -203,7 +208,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { try { return super.cancel(mayInterruptIfRunning); } finally { - this.status(Status.CANCELLED); + this.status(TaskStatus.CANCELLED); try { this.callable.cancelled(); } catch (Throwable e) { @@ -225,7 +230,7 @@ protected void done() { @Override protected void set(V v) { - this.status(Status.SUCCESS); + this.status(TaskStatus.SUCCESS); if (v != null) { this.result = v.toString(); } @@ -234,22 +239,22 @@ protected void set(V v) { @Override protected void setException(Throwable e) { - if (!(this.status == Status.CANCELLED && + if (!(this.status == TaskStatus.CANCELLED && e instanceof InterruptedException)) { LOG.warn("An exception occurred when running task: {}", this.id(), e); // Update status to FAILED if exception occurred(not interrupted) - this.status(Status.FAILED); + this.status(TaskStatus.FAILED); this.result = e.toString(); } super.setException(e); } - protected HugeTaskCallable callable() { + protected TaskCallable callable() { return this.callable; } - protected void status(Status status) { + protected void status(TaskStatus status) { this.status = status; } @@ -266,7 +271,7 @@ protected void property(String key, Object value) { this.description = (String) value; break; case P.STATUS: - this.status(SerialEnum.fromCode(Status.class, (byte) value)); + this.status(SerialEnum.fromCode(TaskStatus.class, (byte) value)); break; case P.PROGRESS: this.progress = (int) value; @@ -388,11 +393,11 @@ public Map asMap(boolean withDetails) { public static HugeTask fromVertex(Vertex vertex) { String callableName = vertex.value(P.CALLABLE); - HugeTaskCallable callable; + TaskCallable callable; try { - callable = HugeTaskCallable.fromClass(callableName); + callable = TaskCallable.fromClass(callableName); } catch (Exception e) { - callable = HugeTaskCallable.empty(e); + callable = TaskCallable.empty(e); } HugeTask task = new HugeTask<>((Id) vertex.id(), null, callable); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTaskCallable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskCallable.java similarity index 81% rename from hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTaskCallable.java rename to hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskCallable.java index 18105bfe3e..e908bbf09a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTaskCallable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskCallable.java @@ -25,12 +25,12 @@ import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.util.E; -public abstract class HugeTaskCallable implements Callable { +public abstract class TaskCallable implements Callable { - private HugeTaskScheduler scheduler = null; + private TaskScheduler scheduler = null; private HugeTask task = null; - public HugeTaskCallable() { + public TaskCallable() { // pass } @@ -46,11 +46,11 @@ public HugeGraph graph() { return this.scheduler().graph(); } - protected void scheduler(HugeTaskScheduler scheduler) { + protected void scheduler(TaskScheduler scheduler) { this.scheduler = scheduler; } - public HugeTaskScheduler scheduler() { + public TaskScheduler scheduler() { E.checkState(this.scheduler != null, "Can't call scheduler() before scheduling task"); return this.scheduler; @@ -67,17 +67,17 @@ public HugeTask task() { } @SuppressWarnings("unchecked") - public static HugeTaskCallable fromClass(String className) { + public static TaskCallable fromClass(String className) { try { Class clazz = Class.forName(className); - return (HugeTaskCallable) clazz.newInstance(); + return (TaskCallable) clazz.newInstance(); } catch (Exception e) { throw new HugeException("Failed to load task: %s", e, className); } } - public static HugeTaskCallable empty(Exception e) { - return new HugeTaskCallable() { + public static TaskCallable empty(Exception e) { + return new TaskCallable() { @Override public V call() throws Exception { throw e; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTaskManager.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java similarity index 82% rename from hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTaskManager.java rename to hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java index e3b1fdf2b3..b03fda92ff 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTaskManager.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import com.baidu.hugegraph.HugeException; @@ -32,24 +33,24 @@ import com.baidu.hugegraph.util.E; import com.baidu.hugegraph.util.ExecutorUtil; -public class HugeTaskManager { +public class TaskManager { public static final String TASK_WORKER = "task-worker-%d"; public static final String TASK_DB_WORKER = "task-db-worker-%d"; private static final int THREADS = 4; - private static final HugeTaskManager MANAGER = new HugeTaskManager(THREADS); + private static final TaskManager MANAGER = new TaskManager(THREADS); - private final Map schedulers; + private final Map schedulers; private final ExecutorService taskExecutor; private final ExecutorService dbExecutor; - public static HugeTaskManager instance() { + public static TaskManager instance() { return MANAGER; } - private HugeTaskManager(int pool) { + private TaskManager(int pool) { this.schedulers = new HashMap<>(); // For execute tasks @@ -62,11 +63,11 @@ public void addScheduler(HugeGraph graph) { E.checkArgumentNotNull(graph, "The graph can't be null"); ExecutorService task = this.taskExecutor; ExecutorService db = this.dbExecutor; - this.schedulers.put(graph, new HugeTaskScheduler(graph, task, db)); + this.schedulers.put(graph, new TaskScheduler(graph, task, db)); } public void closeScheduler(HugeGraph graph) { - HugeTaskScheduler scheduler = this.schedulers.get(graph); + TaskScheduler scheduler = this.schedulers.get(graph); if (scheduler != null && scheduler.close()) { this.schedulers.remove(graph); } @@ -96,7 +97,7 @@ private void closeTaskTx(HugeGraph graph) { } } - public HugeTaskScheduler getScheduler(HugeGraph graph) { + public TaskScheduler getScheduler(HugeGraph graph) { return this.schedulers.get(graph); } @@ -126,4 +127,16 @@ public void shutdown(long timeout) { throw new HugeException("Failed to wait for TaskScheduler", ex); } } + + public int workerPoolSize() { + return ((ThreadPoolExecutor) this.taskExecutor).getCorePoolSize(); + } + + public int pendingTasks() { + int size = 0; + for (TaskScheduler scheduler : this.schedulers.values()) { + size += scheduler.pendingTasks(); + } + return size; + } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTaskScheduler.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java similarity index 97% rename from hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTaskScheduler.java rename to hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java index f012d5d5c5..7f369d51c6 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTaskScheduler.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java @@ -56,7 +56,7 @@ import com.baidu.hugegraph.util.Events; import com.google.common.collect.ImmutableMap; -public class HugeTaskScheduler { +public class TaskScheduler { private final HugeGraph graph; private final ExecutorService taskExecutor; @@ -68,9 +68,9 @@ public class HugeTaskScheduler { private static final long NO_LIMIT = -1L; - public HugeTaskScheduler(HugeGraph graph, - ExecutorService taskExecutor, - ExecutorService dbExecutor) { + public TaskScheduler(HugeGraph graph, + ExecutorService taskExecutor, + ExecutorService dbExecutor) { E.checkNotNull(graph, "graph"); E.checkNotNull(taskExecutor, "taskExecutor"); E.checkNotNull(dbExecutor, "dbExecutor"); @@ -90,6 +90,10 @@ public HugeGraph graph() { return this.graph; } + public int pendingTasks() { + return this.tasks.size(); + } + private TaskTransaction tx() { // NOTE: only the owner thread can access task tx if (this.taskTx == null) { @@ -119,13 +123,13 @@ public Future restore(HugeTask task) { E.checkArgumentNotNull(task, "Task can't be null"); E.checkState(!task.isDone(), "No need to restore task '%s', " + "it has been completed", task.id()); - task.status(Status.RESTORING); + task.status(TaskStatus.RESTORING); return this.submitTask(task); } public Future schedule(HugeTask task) { E.checkArgumentNotNull(task, "Task can't be null"); - task.status(Status.QUEUED); + task.status(TaskStatus.QUEUED); return this.submitTask(task); } @@ -208,7 +212,7 @@ public Iterator> findAllTask(long limit) { return this.queryTask(ImmutableMap.of(), limit); } - public Iterator> findTask(Status status, long limit) { + public Iterator> findTask(TaskStatus status, long limit) { return this.queryTask(P.STATUS, status.code(), limit); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/Status.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskStatus.java similarity index 91% rename from hugegraph-core/src/main/java/com/baidu/hugegraph/task/Status.java rename to hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskStatus.java index 84a1aceabf..b39844751d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/Status.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskStatus.java @@ -21,7 +21,7 @@ import com.baidu.hugegraph.type.define.SerialEnum; -public enum Status implements SerialEnum { +public enum TaskStatus implements SerialEnum { UNKNOWN(0, "UNKNOWN"), @@ -37,10 +37,10 @@ public enum Status implements SerialEnum { private String name; static { - SerialEnum.register(Status.class); + SerialEnum.register(TaskStatus.class); } - Status(int status, String name) { + TaskStatus(int status, String name) { assert status < 256; this.status = (byte) status; this.name = name; diff --git a/hugegraph-example/src/main/java/com/baidu/hugegraph/example/ExampleUtil.java b/hugegraph-example/src/main/java/com/baidu/hugegraph/example/ExampleUtil.java index 34de16b2e8..1c5feaa088 100644 --- a/hugegraph-example/src/main/java/com/baidu/hugegraph/example/ExampleUtil.java +++ b/hugegraph-example/src/main/java/com/baidu/hugegraph/example/ExampleUtil.java @@ -29,7 +29,7 @@ import com.baidu.hugegraph.dist.RegisterUtil; import com.baidu.hugegraph.perf.PerfUtil; import com.baidu.hugegraph.task.HugeTask; -import com.baidu.hugegraph.task.HugeTaskScheduler; +import com.baidu.hugegraph.task.TaskScheduler; public class ExampleUtil { @@ -90,7 +90,7 @@ public static void profile() { } public static void waitAllTaskDone(HugeGraph graph) { - HugeTaskScheduler scheduler = graph.taskScheduler(); + TaskScheduler scheduler = graph.taskScheduler(); Iterator> tasks = scheduler.findAllTask(-1L); while (tasks.hasNext()) { try { diff --git a/hugegraph-example/src/main/java/com/baidu/hugegraph/example/TaskExample.java b/hugegraph-example/src/main/java/com/baidu/hugegraph/example/TaskExample.java index b7a7c3852d..e9c6704620 100644 --- a/hugegraph-example/src/main/java/com/baidu/hugegraph/example/TaskExample.java +++ b/hugegraph-example/src/main/java/com/baidu/hugegraph/example/TaskExample.java @@ -28,10 +28,10 @@ import com.baidu.hugegraph.backend.id.Id; import com.baidu.hugegraph.backend.id.IdGenerator; import com.baidu.hugegraph.task.HugeTask; -import com.baidu.hugegraph.task.HugeTaskCallable; -import com.baidu.hugegraph.task.HugeTaskManager; -import com.baidu.hugegraph.task.HugeTaskScheduler; -import com.baidu.hugegraph.task.Status; +import com.baidu.hugegraph.task.TaskStatus; +import com.baidu.hugegraph.task.TaskCallable; +import com.baidu.hugegraph.task.TaskManager; +import com.baidu.hugegraph.task.TaskScheduler; import com.baidu.hugegraph.util.Log; public class TaskExample { @@ -49,12 +49,11 @@ public static void main(String[] args) throws InterruptedException { task.type("type-1"); task.name("test-task"); - HugeTaskScheduler scheduler = HugeTaskManager.instance() - .getScheduler(graph); + TaskScheduler scheduler = TaskManager.instance().getScheduler(graph); scheduler.schedule(task); scheduler.save(task); Iterator> itor; - itor = scheduler.findTask(Status.RUNNING, -1); + itor = scheduler.findTask(TaskStatus.RUNNING, -1); System.out.println(">>>> running task: " + IteratorUtils.toList(itor)); Thread.sleep(TestTask.UNIT * 33); @@ -63,7 +62,7 @@ public static void main(String[] args) throws InterruptedException { scheduler.save(task); // Find task not finished(actually it should be RUNNING) - itor = scheduler.findTask(Status.CANCELLED, -1); + itor = scheduler.findTask(TaskStatus.CANCELLED, -1); assert itor.hasNext(); task = itor.next(); @@ -75,7 +74,7 @@ public static void main(String[] args) throws InterruptedException { Thread.sleep(TestTask.UNIT * 80); scheduler.save(task); - itor = scheduler.findTask(Status.SUCCESS, -1); + itor = scheduler.findTask(TaskStatus.SUCCESS, -1); assert itor.hasNext(); graph.close(); @@ -83,7 +82,7 @@ public static void main(String[] args) throws InterruptedException { HugeGraph.shutdown(30L); } - public static class TestTask extends HugeTaskCallable { + public static class TestTask extends TaskCallable { public static final int UNIT = 100;