001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.core.config;
018
019import java.util.concurrent.Delayed;
020import java.util.concurrent.ExecutionException;
021import java.util.concurrent.ScheduledFuture;
022import java.util.concurrent.TimeUnit;
023import java.util.concurrent.TimeoutException;
024
025/**
026 *
027 */
028public class CronScheduledFuture<V> implements ScheduledFuture<V> {
029
030    private volatile ScheduledFuture<?> scheduledFuture;
031
032    public CronScheduledFuture(ScheduledFuture<V> future) {
033        this.scheduledFuture = future;
034    }
035
036    void setScheduledFuture(ScheduledFuture<?> future) {
037        this.scheduledFuture = future;
038    }
039
040    @Override
041    public long getDelay(TimeUnit unit) {
042        return scheduledFuture.getDelay(unit);
043    }
044
045    @Override
046    public int compareTo(Delayed delayed) {
047        return scheduledFuture.compareTo(delayed);
048    }
049
050    @Override
051    public boolean cancel(boolean mayInterruptIfRunning) {
052        return scheduledFuture.cancel(mayInterruptIfRunning);
053    }
054
055    @Override
056    public boolean isCancelled() {
057        return scheduledFuture.isCancelled();
058    }
059
060    @Override
061    public boolean isDone() {
062        return scheduledFuture.isDone();
063    }
064
065    @Override
066    @SuppressWarnings("unchecked")
067    public V get() throws InterruptedException, ExecutionException {
068        return (V) scheduledFuture.get();
069    }
070
071    @Override
072    @SuppressWarnings("unchecked")
073    public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
074        return (V) scheduledFuture.get(timeout, unit);
075    }
076}