Mercurial > hg > blitz_condensed
diff src/org/dancres/blitz/disk/BackoffGenerator.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/dancres/blitz/disk/BackoffGenerator.java Sat Mar 21 11:00:06 2009 +0000 @@ -0,0 +1,41 @@ +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) { + } + } +} \ No newline at end of file