view src/org/dancres/blitz/disk/BackoffGenerator.java @ 27:511648fa4d64 Version 2.1

Version to 2.1
author Dan Creswell <dan.creswell@gmail.com>
date Mon, 04 Jan 2010 13:00:40 +0000
parents 3dc0c5604566
children
line wrap: on
line source

package org.dancres.blitz.disk;

import java.util.Random;

import java.util.logging.Level;

import net.jini.config.ConfigurationException;

import org.dancres.blitz.config.ConfigurationFactory;

public class BackoffGenerator {
    private static final String LOAD_BACKOFF = "loadBackoff";

    private static int BACKOFF_BASE;
    private static int BACKOFF_JITTER;

    static {
        try {
            int[] myBackoff = 
                (int[]) ConfigurationFactory.getEntry(LOAD_BACKOFF,
                                                      int[].class,
                                                      new int[]{50, 50});

            BACKOFF_BASE = myBackoff[0];
            BACKOFF_JITTER = myBackoff[1];
        } catch (ConfigurationException aCE) {
            RetryingUpdate.theLogger.log(Level.SEVERE,
                                         "Failed to load backoff config", aCE);
        }
    }

    private static Random theBackoffGenerator = new Random();

    public static void pause() {
        try {
            Thread.sleep((long) (BACKOFF_BASE +
                                 theBackoffGenerator.nextInt(BACKOFF_JITTER)));
        } catch (InterruptedException anIE) {
        }
    }
}