diff options
author | Luck <git@lucko.me> | 2020-01-11 19:30:15 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2020-01-11 19:30:15 +0000 |
commit | 2fe79f4140011f93df1567afcc9b75fababa187e (patch) | |
tree | 2a747c3da719d061302577b9cda422fe609ab636 /spark-common/src/main/java/me/lucko | |
parent | 9e066d1052643b2be270b4039a102260abb41ebb (diff) | |
download | spark-2fe79f4140011f93df1567afcc9b75fababa187e.tar.gz spark-2fe79f4140011f93df1567afcc9b75fababa187e.tar.bz2 spark-2fe79f4140011f93df1567afcc9b75fababa187e.zip |
Add AbstractTickCounter
Diffstat (limited to 'spark-common/src/main/java/me/lucko')
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractTickCounter.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractTickCounter.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractTickCounter.java new file mode 100644 index 0000000..4633024 --- /dev/null +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractTickCounter.java @@ -0,0 +1,53 @@ +/* + * 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.sampler; + +import java.util.HashSet; +import java.util.Set; + +public abstract class AbstractTickCounter implements TickCounter { + + private final Set<TickTask> tasks = new HashSet<>(); + private int tick = 0; + + protected void onTick() { + for (TickTask r : this.tasks) { + r.onTick(this); + } + this.tick++; + } + + @Override + public int getCurrentTick() { + return this.tick; + } + + @Override + public void addTickTask(TickTask runnable) { + this.tasks.add(runnable); + } + + @Override + public void removeTickTask(TickTask runnable) { + this.tasks.remove(runnable); + } + +} |