view src/org/dancres/blitz/lease/LeaseBounds.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.lease;

import java.util.logging.*;

import net.jini.config.ConfigurationException;

import org.dancres.blitz.Logging;

import org.dancres.blitz.util.Time;

import org.dancres.blitz.config.ConfigurationFactory;

/**
   Responsible for handling bounding of lease durations based on configuration
   items <code>notifyLeaseBound</code> and <code>entryLeaseBound</code>
 */
public class LeaseBounds {
    private static Logger theLogger =
        Logging.newLogger("org.dancres.blitz.lease.LeaseBounds");

    private static long theNotifyBound;
    private static long theEntryBound;
    private static long theViewBound;
    private static long theTxnBound;

    static {
        try {
            theNotifyBound =
                ((Long) ConfigurationFactory.getEntry("notifyLeaseBound",
                                                      long.class,
                                                      new Long(0))).longValue();
            theEntryBound =
                ((Long) ConfigurationFactory.getEntry("entryLeaseBound",
                                                      long.class,
                                                      new Long(0))).longValue();
            theViewBound =
                ((Long) ConfigurationFactory.getEntry("viewLeaseBound",
                                                      long.class,
                                                      new Long(0))).longValue();
            theTxnBound =
                ((Long) ConfigurationFactory.getEntry("loopbackTxnLeaseBound",
                    long.class,
                    new Long(0))).longValue();

            theLogger.log(Level.INFO, "LeaseBounds: " + theNotifyBound +
                          ", " + theEntryBound + ", " + theViewBound + ", " +
                          theTxnBound);

        } catch (ConfigurationException aCE) {
            theLogger.log(Level.SEVERE, "Got config problem", aCE);
        }
    }

    public static long boundWrite(long aLeaseDuration) {
        return Time.getLeaseDuration(aLeaseDuration, theEntryBound);
    }

    public static long boundNotify(long aLeaseDuration) {
        return Time.getLeaseDuration(aLeaseDuration, theNotifyBound);
    }

    public static long boundView(long aLeaseDuration) {
        return Time.getLeaseDuration(aLeaseDuration, theViewBound);
    }

    public static long boundTxn(long aLeaseDuration) {
        return Time.getLeaseDuration(aLeaseDuration, theTxnBound);
    }
}