Class DataCollector<D>
- Type Parameters:
D- The type of data being managed by theDataCollector.
- All Implemented Interfaces:
Closeable,AutoCloseable
DataDistributor of changes or activity.
The DataCollector runs a scheduled task that executes at a fixed interval.
This task evaluates whether the data has changed using a provided Predicate.
If a change is detected, the dataUpdated method of the DataDistributor
is invoked. Otherwise, the pingReceived method of the DataDistributor
is called to indicate that the periodic check occurred.
The frequency of data collection can be configured through the constructor. If the frequency is less than or equal to zero, a default interval of 5 seconds is used.
- Author:
- Syam
-
Constructor Summary
ConstructorsConstructorDescriptionDataCollector(Predicate<D> collector, DataDistributor<D> distributor, int collectionFrequency) Constructs a newDataCollectorinstance that periodically evaluates data changes and notifies theDataDistributorof updates or activity. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes theDataCollectorand shuts down the associated scheduled task execution.
-
Constructor Details
-
DataCollector
public DataCollector(Predicate<D> collector, DataDistributor<D> distributor, int collectionFrequency) Constructs a newDataCollectorinstance that periodically evaluates data changes and notifies theDataDistributorof updates or activity.- Parameters:
collector- aPredicateused to determine if the data has changed. The predicate should returntrueif the data is updated, orfalseotherwise.distributor- theDataDistributorwhich provides the data to be evaluated and handles notifications for updates or periodic activity.collectionFrequency- the frequency, in seconds, at which the data collection and evaluation task should run. If the value is less than or equal to zero, a default interval of 5 seconds is used.
-
-
Method Details
-
close
public void close()Closes theDataCollectorand shuts down the associated scheduled task execution.This method initiates a graceful shutdown of the scheduler, allowing any currently executing tasks to complete within a timeout period of 5 seconds. If tasks do not terminate within this timeframe, the scheduler is forcibly shut down. Interruptions during this process are handled appropriately, and the thread's interrupt status is restored.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-