
cn.wjybxx.sequential.AbstractUniScheduledExecutor Maven / Gradle / Ivy
/*
* Copyright 2023-2024 wjybxx([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.wjybxx.sequential;
import cn.wjybxx.concurrent.*;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
/**
* 子类需要在{@link #execute(Runnable)}的时候为任务赋值id和options
*
* @author wjybxx
* date - 2023/4/7
*/
@SuppressWarnings("NullableProblems")
public abstract class AbstractUniScheduledExecutor
extends AbstractUniExecutor
implements UniScheduledExecutor {
// region schedule
@Override
public IScheduledPromise newScheduledPromise() {
return new UniScheduledPromise<>(this);
}
protected abstract IScheduledHelper helper();
@Override
public IScheduledFuture schedule(ScheduledTaskBuilder builder) {
IScheduledPromise promise = newScheduledPromise();
execute(ScheduledPromiseTask.ofBuilder(builder, promise, helper()));
return promise;
}
@Override
public IScheduledFuture scheduleFunc(Callable task, long delay, TimeUnit unit, ICancelToken cancelToken) {
IScheduledPromise promise = newScheduledPromise();
IScheduledHelper helper = helper();
execute(ScheduledPromiseTask.ofFunction(task, cancelToken, 0, promise, helper, helper.triggerTime(delay, unit)));
return promise;
}
@Override
public IScheduledFuture> scheduleAction(Runnable task, long delay, TimeUnit unit, ICancelToken cancelToken) {
IScheduledPromise
© 2015 - 2025 Weber Informatics LLC | Privacy Policy