feat: add JavaScriptTask class

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-11-20 10:30:05 +08:00
parent 12d07bf552
commit 7f32062dca
3 changed files with 50 additions and 6 deletions

View File

@ -31,6 +31,10 @@ public class Base {
return ProxyClass.class;
}
public Class<?> getJavaScriptTaskClass() {
return JavaScriptTask.class;
}
public String read(String path) throws IOException {
return new String(Files.readAllBytes(new File(path).toPath()), StandardCharsets.UTF_8);
}

View File

@ -0,0 +1,39 @@
package pw.yumc.MiaoScript;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
public class JavaScriptTask implements Delayed {
private final Object task;
private final long startTime;
private final long executeTime;
public JavaScriptTask(Object task, long ms) {
this.task = task;
this.startTime = System.currentTimeMillis();
this.executeTime = ms;
}
@Override
public long getDelay(TimeUnit unit) {
return unit.convert((this.startTime + this.executeTime) - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
}
@Override
public int compareTo(Delayed delayed) {
JavaScriptTask task = (JavaScriptTask) delayed;
return (int) ((this.startTime + this.executeTime) - (task.getStartTime() + task.getExecuteTime()));
}
public Object getTask() {
return this.task;
}
public long getStartTime() {
return this.startTime;
}
public long getExecuteTime() {
return this.executeTime;
}
}