View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.core.config;
18  
19  import java.util.concurrent.Delayed;
20  import java.util.concurrent.ExecutionException;
21  import java.util.concurrent.ScheduledFuture;
22  import java.util.concurrent.TimeUnit;
23  import java.util.concurrent.TimeoutException;
24  
25  /**
26   *
27   */
28  public class CronScheduledFuture<V> implements ScheduledFuture<V> {
29  
30      private volatile ScheduledFuture<?> scheduledFuture;
31  
32      public CronScheduledFuture(final ScheduledFuture<V> future) {
33          this.scheduledFuture = future;
34      }
35  
36      void setScheduledFuture(final ScheduledFuture<?> future) {
37          this.scheduledFuture = future;
38      }
39  
40      @Override
41      public long getDelay(final TimeUnit unit) {
42          return scheduledFuture.getDelay(unit);
43      }
44  
45      @Override
46      public int compareTo(final Delayed delayed) {
47          return scheduledFuture.compareTo(delayed);
48      }
49  
50      @Override
51      public boolean cancel(final boolean mayInterruptIfRunning) {
52          return scheduledFuture.cancel(mayInterruptIfRunning);
53      }
54  
55      @Override
56      public boolean isCancelled() {
57          return scheduledFuture.isCancelled();
58      }
59  
60      @Override
61      public boolean isDone() {
62          return scheduledFuture.isDone();
63      }
64  
65      @Override
66      @SuppressWarnings("unchecked")
67      public V get() throws InterruptedException, ExecutionException {
68          return (V) scheduledFuture.get();
69      }
70  
71      @Override
72      @SuppressWarnings("unchecked")
73      public V get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
74          return (V) scheduledFuture.get(timeout, unit);
75      }
76  }