aboutsummaryrefslogtreecommitdiff
path: root/spark-common
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2021-08-19 20:50:08 +0100
committerLuck <git@lucko.me>2021-08-19 20:50:15 +0100
commit65e216657e4ac86d4e1a1bee30033d9b27f5f217 (patch)
tree52d5b7f3abd5dd3e2f134a0c08aa2705effd6c5c /spark-common
parentc4f96ced241802e40076d704b8977e2b35aff2b6 (diff)
downloadspark-65e216657e4ac86d4e1a1bee30033d9b27f5f217.tar.gz
spark-65e216657e4ac86d4e1a1bee30033d9b27f5f217.tar.bz2
spark-65e216657e4ac86d4e1a1bee30033d9b27f5f217.zip
Abstract tick reporter
Diffstat (limited to 'spark-common')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/tick/SimpleTickReporter.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/tick/SimpleTickReporter.java b/spark-common/src/main/java/me/lucko/spark/common/tick/SimpleTickReporter.java
new file mode 100644
index 0000000..9747784
--- /dev/null
+++ b/spark-common/src/main/java/me/lucko/spark/common/tick/SimpleTickReporter.java
@@ -0,0 +1,48 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.common.tick;
+
+public abstract class SimpleTickReporter extends AbstractTickReporter {
+ private boolean closed = false;
+ private long start = 0;
+
+ protected void onStart() {
+ if (this.closed) {
+ return;
+ }
+
+ this.start = System.nanoTime();
+ }
+
+ protected void onEnd() {
+ if (this.closed || this.start == 0) {
+ return;
+ }
+
+ double duration = (System.nanoTime() - this.start) / 1000000d;
+ onTick(duration);
+ }
+
+ @Override
+ public void close() {
+ this.closed = true;
+ }
+}