org.ceryle.util.idle
Class Idler

java.lang.Object
  extended by org.ceryle.util.idle.Idler

public class Idler
extends Object

Idler starts a thread that periodically runs a task to see if any activity has occurred. If no indication of activity has after a fixed amount of time (set by the int delay), the Idler returns true when queried with isIdle(). This is used in logging to keep track of actual usage vs. the application merely being open, using the method getElapsed(boolean,boolean).

Note that once instantiated, call start() to begin idle checking.

Since:
JDK1.3
Version:
$Id: Idler.java,v 3.7 2007-06-15 12:10:01 altheim Exp $
Author:
Murray Altheim

Field Summary
static long DEFAULT_DELAY
          An int containing the default number of milliseconds before going into an idle state.
static String IDLE_ACTIVE
          Feature identifier: log active.
static String IDLE_FEATURE_PFX
          Idler Feature prefix.
static long m_initialDelay
          The initial delay before the first idle check (in milliseconds).
 
Constructor Summary
Idler(MessageHandler messagehandler)
          Default constructor provided with a MessageHandler.
Idler(MessageHandler messageHandler, long delay)
          Constructor provided with a MessageHandler and an idle time delay (in milliseconds).
 
Method Summary
 void active()
          When called, indicates system activity, such that an idle state is delayed.
 void addIdleListener(IdleListener listener)
          Add a listener for changes to the idle state.
protected  void fireIdleStateChanged()
          Notify all listeners that have registered interest for notification on this event type.
 long getElapsed(boolean active, boolean millis)
          Returns a long indicating the number of milliseconds passed since the application session began.
 boolean isIdle()
          Returns the current idle state.
 boolean isStarted()
          Returns true if the Idler (Timer) task has been started.
 void removeIdleListener(IdleListener listener)
          Remove a listener for changes to the idle state.
 void setDelay(long delay)
          Sets the idle delay to the long delay.
 void start()
          Schedule an idle check using a new Timer and the current delay time.
 void stop()
          This method should be called prior to application termination to close all extant timer tasks.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDLE_FEATURE_PFX

public static final String IDLE_FEATURE_PFX
Idler Feature prefix.

See Also:
Constant Field Values

IDLE_ACTIVE

public static final String IDLE_ACTIVE
Feature identifier: log active.

See Also:
Constant Field Values

m_initialDelay

public static long m_initialDelay
The initial delay before the first idle check (in milliseconds). Default is 60000 (60 seconds).


DEFAULT_DELAY

public static final long DEFAULT_DELAY
An int containing the default number of milliseconds before going into an idle state. The value is 30000L (e.g., 10000 = 10 seconds).

See Also:
Constant Field Values
Constructor Detail

Idler

public Idler(MessageHandler messagehandler)
Default constructor provided with a MessageHandler. Uses the default idle time delay and quiet messaging (verbose false). Call start() to begin idle checking.


Idler

public Idler(MessageHandler messageHandler,
             long delay)
Constructor provided with a MessageHandler and an idle time delay (in milliseconds).

Method Detail

start

public void start()
Schedule an idle check using a new Timer and the current delay time. If there is a current IdleCheck process running, it will continue, but the current schedule will terminate and a new one begin.


stop

public void stop()
This method should be called prior to application termination to close all extant timer tasks.


isStarted

public boolean isStarted()
Returns true if the Idler (Timer) task has been started.


setDelay

public void setDelay(long delay)
Sets the idle delay to the long delay. This does not alter or cancel any current processes, but re-schedules the idle check when the next delay is started with a new Timer.


isIdle

public boolean isIdle()
Returns the current idle state.


active

public void active()
When called, indicates system activity, such that an idle state is delayed. If idle when this is called, this fires events to all registered listeners.


getElapsed

public long getElapsed(boolean active,
                       boolean millis)
Returns a long indicating the number of milliseconds passed since the application session began. When the boolean active is true, the total includes only active (i.e., non-idle) time; when false, idle time is ignored. If the boolean millis is true, the value is returned in milliseconds; otherwise, in seconds.


addIdleListener

public void addIdleListener(IdleListener listener)
Add a listener for changes to the idle state.


removeIdleListener

public void removeIdleListener(IdleListener listener)
Remove a listener for changes to the idle state.


fireIdleStateChanged

protected void fireIdleStateChanged()
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.