/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.kahadb.util;

import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 
 */
public final class Scheduler {

    

	public static final Timer CLOCK_DAEMON = new Timer("KahaDB Scheduler", true);
    private static final HashMap<Runnable, TimerTask> TIMER_TASKS = new HashMap<Runnable, TimerTask>();

    private Scheduler() {
    }

    public static synchronized void executePeriodically(final Runnable task, long period) {
    	TimerTask timerTask = new SchedulerTimerTask(task);
        CLOCK_DAEMON.scheduleAtFixedRate(timerTask, period, period);
        TIMER_TASKS.put(task, timerTask);
    }

    public static synchronized void cancel(Runnable task) {
    	TimerTask ticket = TIMER_TASKS.remove(task);
        if (ticket != null) {
            ticket.cancel();
            CLOCK_DAEMON.purge();//remove cancelled TimerTasks
        }
    }

    public static void executeAfterDelay(final Runnable task, long redeliveryDelay) {
    	TimerTask timerTask = new SchedulerTimerTask(task);
        CLOCK_DAEMON.schedule(timerTask, redeliveryDelay);
    }
    
    public static void shutdown() {
        CLOCK_DAEMON.cancel();
    }

}

@@ -915,17 +915,16 @@
 %0A%0A/**%0A *
- 
 %0A */%0Apub
@@ -956,15 +956,14 @@
  %7B%0A%0A
+%0A%0A
     
-%0A%0A%09
 publ
@@ -1262,33 +1262,36 @@
 g period) %7B%0A    
-%09
+    
 TimerTask timerT
@@ -1359,19 +1359,8 @@
 dule
-AtFixedRate
 (tim
@@ -1489,33 +1489,36 @@
 ble task) %7B%0A    
-%09
+    
 TimerTask ticket
@@ -1779,9 +1779,12 @@
     
-%09
+    
 Time
@@ -1896,20 +1896,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub

fix for: https://issues.apache.org/jira/browse/AMQ-3031