public void setTimeoutByInterval(int type, long interval)
    {
        if (ivTimeoutType != CURRENT_TIME)
        {
            // If the keys has expired, and is not in use, then allow the
            // time out time to be reset, and the bean re-loaded.           d210290
            if (ivExpired == true &&
                ivDiscarded == false &&
                ivInUse == false)
            {
                ivExpired = false;
                ivTimeout = System.currentTimeMillis();
            }
            else
                throw new IllegalStateException("timeout already set");
        }

        long now = ivTimeout; // Save the 'current' time

        ivTimeoutType = TIMEOUT_TIME;
        ivInUse = true; // d210290

        switch (type)
        {
        // The specified 'interval' is the basic interval specification
        // indicating to 'reload the bean every so many minutes'...
        // which means that the bean must be loaded the first time it
        // is accessed in any given interval, where the start of the
        // first interval is midnight, January 1, 1970 UTC, and each
        // interval duration is the specified interval value.
        // By determining the bean timeout in this way, rather than just
        // adding the interval to the current time, consistent data access
        // may be obtained across cluster members.
        // Also, to avoid all beans with the same interval value ending up
        // with the same timeout, vary it by adding in an offset that is
        // reproducable across servers... simply use the hash code to
        // obtain an index over the interval in milliseconds.            d217712
            case BeanMetaData.CACHE_RELOAD_INTERVAL:
                if (interval > 0)
                {
                    long currOffset = now % interval;
                    long hashOffset = (ivBeanId.hashCode() & 0x7FFFFFFF) % interval;
                    ivTimeout = now + (hashOffset - currOffset);
                    if (ivTimeout <= now) // d232681
                        ivTimeout += interval;
                }
                else
                {
                    ivTimeout = Long.MAX_VALUE;
                }
                break;

            // The specified 'interval' is for reloading the bean at a specific
            // time every day... and the 'interval' value is the number of
            // milliseconds from midnight to that time, so just add it to
            // the time in milliseconds representing midnight.
            case BeanMetaData.CACHE_RELOAD_DAILY:
                GregorianCalendar today = new GregorianCalendar();
                today.set(GregorianCalendar.HOUR_OF_DAY, 0);
                today.set(GregorianCalendar.MINUTE, 0);
                today.set(GregorianCalendar.SECOND, 0);
                today.set(GregorianCalendar.MILLISECOND, 0);
                long midnight = today.getTime().getTime();
                ivTimeout = midnight + interval;

                // If this calculated timeout has already passed, add 24 hours to it.
                // For example, if DAILY indicates "3am" and "now" is "3:15am", the
                // entry will live until 3am tomorrow.
                if (ivTimeout <= now) // d232681
                {
                    ivTimeout += 24 * 60 * 60 * 1000; // 24 hours in milliseconds
                }
                break;

            // The specified 'interval' is for reloading the bean at a specific
            // time and day of every week... and the 'interval' value is the
            // number of milliseconds from midnight on Sunday to that time,
            // so just add it to the time in milliseconds representing midnight
            // on Sunday (i.e. early Sunday morning).
            case BeanMetaData.CACHE_RELOAD_WEEKLY:
                GregorianCalendar sunday = new GregorianCalendar();
                sunday.set(GregorianCalendar.DAY_OF_WEEK, GregorianCalendar.SUNDAY);
                sunday.set(GregorianCalendar.HOUR_OF_DAY, 0);
                sunday.set(GregorianCalendar.MINUTE, 0);
                sunday.set(GregorianCalendar.SECOND, 0);
                sunday.set(GregorianCalendar.MILLISECOND, 0);
                long midnightSunday = sunday.getTime().getTime();
                ivTimeout = midnightSunday + interval;

                // If this calculated timeout has already passed, add 7 days to it.
                // For example, if WEEKLY indicates "Monday 3am" and "now" is
                // "Tuesday 2:30am", the entry will live until next Monday 3am.
                if (ivTimeout <= now) // d232681
                {
                    ivTimeout += 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds
                }
                break;

            default:
                throw new IllegalArgumentException("Interval LoadPolicy not specified");
        }
    }
public void setTimeoutByInterval ( int type , long interval ) { if ( ivTimeoutType != CURRENT_TIME ) { if ( ivExpired == true && ivDiscarded == false && ivInUse == false ) { ivExpired = false ; ivTimeout = System . currentTimeMillis ( ) ; } else throw new IllegalStateException ( "timeout already set" ) ; } long now = ivTimeout ; ivTimeoutType = TIMEOUT_TIME ; ivInUse = true ; switch ( type ) { case BeanMetaData . CACHE_RELOAD_INTERVAL : if ( interval > 0 ) { long currOffset = now % interval ; long hashOffset = ( ivBeanId . hashCode ( ) & 0x7FFFFFFF ) % interval ; ivTimeout = now + ( hashOffset - currOffset ) ; if ( ivTimeout <= now ) ivTimeout += interval ; } else { ivTimeout = Long . MAX_VALUE ; } break ; case BeanMetaData . CACHE_RELOAD_DAILY : GregorianCalendar today = new GregorianCalendar ( ) ; today . set ( GregorianCalendar . HOUR_OF_DAY , 0 ) ; today . set ( GregorianCalendar . MINUTE , 0 ) ; today . set ( GregorianCalendar . SECOND , 0 ) ; today . set ( GregorianCalendar . MILLISECOND , 0 ) ; long midnight = today . getTime ( ) . getTime ( ) ; ivTimeout = midnight + interval ; if ( ivTimeout <= now ) { ivTimeout += 24 * 60 * 60 * 1000 ; } break ; case BeanMetaData . CACHE_RELOAD_WEEKLY : GregorianCalendar sunday = new GregorianCalendar ( ) ; sunday . set ( GregorianCalendar . DAY_OF_WEEK , GregorianCalendar . SUNDAY ) ; sunday . set ( GregorianCalendar . HOUR_OF_DAY , 0 ) ; sunday . set ( GregorianCalendar . MINUTE , 0 ) ; sunday . set ( GregorianCalendar . SECOND , 0 ) ; sunday . set ( GregorianCalendar . MILLISECOND , 0 ) ; long midnightSunday = sunday . getTime ( ) . getTime ( ) ; ivTimeout = midnightSunday + interval ; if ( ivTimeout <= now ) { ivTimeout += 7 * 24 * 60 * 60 * 1000 ; } break ; default : throw new IllegalArgumentException ( "Interval LoadPolicy not specified" ) ; } }
Changes the timeout for this key from the 'current time' to a
specific time out value by applying the specified interval to the
current time or re-calculates a specific time out value for a
key that has expired/timed out and will be reused (re-loaded). <p>

This method may be used to convert a key that contains the current
time, to a key with a specific time out setting for the
corresponding bean. <p>

This method is provided for performance, to allow one instance to
be created with the 'current time' to perform a cache search, and
if no object is found, to then convert the key to a 'time out' key
to actually use to insert the bean into the cache. <p>

Also for performance, this method allows a key and bean instance
that has timed out, but is not in use, to be reset and reloaded. <p>

Caution: This method is NOT synchronized, and should only be used
when the caller has exclusive access to the instance. <p>

@param type enumeration type defining the meaning of the specified
interval value.
@param interval time in milliseconds to be added to the current time
to determine when the associated bean will expire.

@exception IllegalStateException if the key does not currently represent
the current time, or has not expired and is not in use.