Gridarta Editor
net.sf.gridarta.utils.DelayedChangeManager Class Reference

Helper for reducing the number of change events: calls to change() will be forwarded to DelayedChangeListener#change(). More...

+ Collaboration diagram for net.sf.gridarta.utils.DelayedChangeManager:

Classes

interface  State
 The states of the FSM. More...
 
class  TimeoutTimerTask
 A TimerTask that calls State#timeout() when the timer expires. More...
 

Public Member Functions

void change ()
 Delivers a change event to the associated DelayedChangeListener. More...
 
 DelayedChangeManager (final int initialDelay, final int notificationDelay, @NotNull final DelayedChangeListener delayedChangeListener)
 Creates a new instance. More...
 
void finish ()
 Finishes a series of change events. More...
 

Private Attributes

final DelayedChangeListener delayedChangeListener
 The DelayedChangeListener events are forwarded to. More...
 
final State idle
 The state "idle" of the FSM. More...
 
final int initialDelay
 The delay in millisecond the first forwarded event is delayed. More...
 
final int notificationDelay
 The interval in milliseconds events are forwarded during a long series of events. More...
 
final State pending
 The state "pending" of the FSM. More...
 
State state = idle
 The FSM's current state. More...
 
final Timer timer = new Timer()
 The Timer for delaying events. More...
 
final State wait
 The state "wait" of the FSM. More...
 

Detailed Description

Helper for reducing the number of change events: calls to change() will be forwarded to DelayedChangeListener#change().

Forwarded calls are dropped if they would happen very quickly.

Author
Andreas Kirschbaum

Definition at line 32 of file DelayedChangeManager.java.

Constructor & Destructor Documentation

◆ DelayedChangeManager()

net.sf.gridarta.utils.DelayedChangeManager.DelayedChangeManager ( final int  initialDelay,
final int  notificationDelay,
@NotNull final DelayedChangeListener  delayedChangeListener 
)

Creates a new instance.

Parameters
initialDelaythe initial delay for a series of events in milliseconds
notificationDelaythe delay for following events in a series of events; in milliseconds
delayedChangeListenerthe delayed change listener to forward events to

Definition at line 199 of file DelayedChangeManager.java.

References net.sf.gridarta.utils.DelayedChangeManager.delayedChangeListener, net.sf.gridarta.utils.DelayedChangeManager.initialDelay, and net.sf.gridarta.utils.DelayedChangeManager.notificationDelay.

Member Function Documentation

◆ change()

void net.sf.gridarta.utils.DelayedChangeManager.change ( )

Delivers a change event to the associated DelayedChangeListener.

Definition at line 208 of file DelayedChangeManager.java.

References net.sf.gridarta.utils.DelayedChangeManager.State.change().

+ Here is the call graph for this function:

◆ finish()

void net.sf.gridarta.utils.DelayedChangeManager.finish ( )

Finishes a series of change events.

Calling this function is optional: if it is called, a pending change event is immediately forwarded; otherwise when the notification timeout has expired.

Definition at line 218 of file DelayedChangeManager.java.

References net.sf.gridarta.utils.DelayedChangeManager.State.finish().

+ Here is the call graph for this function:

Member Data Documentation

◆ delayedChangeListener

final DelayedChangeListener net.sf.gridarta.utils.DelayedChangeManager.delayedChangeListener
private

The DelayedChangeListener events are forwarded to.

Definition at line 51 of file DelayedChangeManager.java.

Referenced by net.sf.gridarta.utils.DelayedChangeManager.DelayedChangeManager().

◆ idle

final State net.sf.gridarta.utils.DelayedChangeManager.idle
private
Initial value:
= new State() {
@NotNull
@Override
public State change() {
timer.schedule(new TimeoutTimerTask(), initialDelay);
return pending;
}
@NotNull
@Override
public State finish() {
return idle;
}
@NotNull
@Override
public State timeout() {
assert false;
return idle;
}
}

The state "idle" of the FSM.

Definition at line 104 of file DelayedChangeManager.java.

◆ initialDelay

final int net.sf.gridarta.utils.DelayedChangeManager.initialDelay
private

The delay in millisecond the first forwarded event is delayed.

This allows combining the first few events of a long series of events without delaying the delivery for a long time (notificationDelay).

Definition at line 39 of file DelayedChangeManager.java.

Referenced by net.sf.gridarta.utils.DelayedChangeManager.DelayedChangeManager().

◆ notificationDelay

final int net.sf.gridarta.utils.DelayedChangeManager.notificationDelay
private

The interval in milliseconds events are forwarded during a long series of events.

Definition at line 45 of file DelayedChangeManager.java.

Referenced by net.sf.gridarta.utils.DelayedChangeManager.DelayedChangeManager().

◆ pending

final State net.sf.gridarta.utils.DelayedChangeManager.pending
private
Initial value:
= new State() {
@NotNull
@Override
public State change() {
return pending;
}
@NotNull
@Override
public State finish() {
return wait;
}
@NotNull
@Override
public State timeout() {
timer.schedule(new TimeoutTimerTask(), notificationDelay);
return wait;
}
}

The state "pending" of the FSM.

Definition at line 132 of file DelayedChangeManager.java.

◆ state

State net.sf.gridarta.utils.DelayedChangeManager.state = idle
private

The FSM's current state.

Definition at line 188 of file DelayedChangeManager.java.

Referenced by net.sf.gridarta.utils.DelayedChangeManager.TimeoutTimerTask.run().

◆ timer

final Timer net.sf.gridarta.utils.DelayedChangeManager.timer = new Timer()
private

The Timer for delaying events.

Definition at line 57 of file DelayedChangeManager.java.

◆ wait

final State net.sf.gridarta.utils.DelayedChangeManager.wait
private
Initial value:
= new State() {
@NotNull
@Override
public State change() {
return pending;
}
@NotNull
@Override
public State finish() {
return wait;
}
@NotNull
@Override
public State timeout() {
return idle;
}
}

The state "wait" of the FSM.

Definition at line 161 of file DelayedChangeManager.java.


The documentation for this class was generated from the following file: