Package org.cytoscape.event
Class DebounceTimer
java.lang.Object
org.cytoscape.event.DebounceTimer
A timer that can be used to ensure that time-consuming tasks, usually triggered
by events, do not run too often. It can be used by code that fires events to avoid
firing too many events, or by code listening for events to avoid running the handler
too often.
- Since:
- 3.8
Cytoscape Backwards Compatibility (API Class): We expect that this class will be used but not inherited by developers using this class. As such, we reserve the right to add methods to the class as part of minor version upgrades. We will not remove methods for any changes other than major version upgrades.
Module: event-api
To use this in your app, include the following dependency in your POM:
<dependency> <groupId>org.cytoscape</groupId> <artifactId>event-api</artifactId> </dependency>
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates a new DebounceTimer with the default delay.DebounceTimer(int delayMilliseconds)
Creates a new DebounceTimer with the given delay (in milliseconds). -
Method Summary
Modifier and TypeMethodDescriptionvoid
Starts a timer that will run the runnable after a short delay (on a separate thread).void
Starts a timer that will run the runnable after a short delay (on a separate thread).boolean
void
shutdown()
Initiates a shutdown that will release resources, calls to debounce() will no longer be accepted.
-
Field Details
-
DEFAULT_DELAY_MILLISECONDS
public static final int DEFAULT_DELAY_MILLISECONDS- See Also:
- Constant Field Values
-
-
Constructor Details
-
DebounceTimer
public DebounceTimer()Creates a new DebounceTimer with the default delay. When this DebounceTimer is no longer needed theshutdown()
method should be called to release resources. -
DebounceTimer
public DebounceTimer(int delayMilliseconds)Creates a new DebounceTimer with the given delay (in milliseconds). When this DebounceTimer is no longer needed theshutdown()
method should be called to release resources.
-
-
Method Details
-
debounce
Starts a timer that will run the runnable after a short delay (on a separate thread). If another call to this method occurs before the timer expires then the timer will be reset. When there are multiple quick calls to this method and the time between each call is less than the delay then the runnable will only run when the delay is reached. This method is non-blocking.
Code example:public void handleEvent(RowsSetEvent e) { if(e.containsColumn(CyNetwork.SELECTED)) { debounceTimer.debounce(() -> updateUI()); } }
-
debounce
Starts a timer that will run the runnable after a short delay (on a separate thread). If another call to this method (with the same key) occurs before the timer expires then the timer will be reset. When there are multiple quick calls to this method and the time between each call is less than the delay then the runnable will only run when the delay is reached. This method is non-blocking.
Code example:public void handleEvent(RowsSetEvent e) { if(e.containsColumn(CyNetwork.SELECTED)) { CyNetworkView networkView = applicationManager.getCurrentNetworkView(); if(networkView != null) { debounceTimer.debounce(networkView, () -> updateUI(networkView)); } } }
- Parameters:
key
- A key object to associate with the runnable, each key object will get its own timer.- Throws:
RejectedExecutionException
- if this timer has been shutdownNullPointerException
- if key or runnable are null
-
shutdown
public void shutdown()Initiates a shutdown that will release resources, calls to debounce() will no longer be accepted. -
isShutdown
public boolean isShutdown()
-