Package net.solarnetwork.central.support
Class DelayedOcassionalProcessor<T>
java.lang.Object
net.solarnetwork.central.support.DelayedOcassionalProcessor<T>
- All Implemented Interfaces:
Runnable,AsyncProcessor<T>,net.solarnetwork.service.PingTest,net.solarnetwork.service.ServiceLifecycleObserver
public abstract class DelayedOcassionalProcessor<T>
extends Object
implements AsyncProcessor<T>, Runnable, net.solarnetwork.service.ServiceLifecycleObserver, net.solarnetwork.service.PingTest
Asynchronously process ocassionally-appearing items.
The goal of this class is to help asynchronously process "bursty" items that come into being inconsistently, and sometimes in a duplicate manner, after a brief delay. The delay allows de-duplication to occur within the delay period.
Different processing styles can be achieved via different Queue
implementations, such as LinkedHashSetBlockingQueue for
de-duplication or DelayQueueSet for consistently delayed
de-duplication.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumProcessor statistics.Nested classes/interfaces inherited from interface net.solarnetwork.service.PingTest
net.solarnetwork.service.PingTest.Result -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDelayedOcassionalProcessor(Clock clock, net.solarnetwork.util.StatTracker stats, org.springframework.scheduling.TaskScheduler scheduler, Queue<T> items) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidasyncProcessItem(T item) Asynchronously process an item.booleancancelAsyncProcessItem(T item) Cancel a pending task previously submitted toAsyncProcessor.asyncProcessItem(T).final DurationgetDelay()Get the delay.longfinal intSet the queue size alert threshold.net.solarnetwork.service.PingTest.Resultprotected abstract voidprocessItemInternal(T item) Process a delayed item.final voidrun()voidvoidfinal voidSet the delay.final voidsetQueueSizeAlertThreshold(int queueSizeAlertThreshold) Set the queue size alert threshold.
-
Field Details
-
DEFAULT_DELAY
Thedelayproperty default value. -
DEFAULT_QUEUE_SIZE_ALERT_THRESHOLD
public static final int DEFAULT_QUEUE_SIZE_ALERT_THRESHOLDThequeueSizeAlertThresholddefault value.- See Also:
-
clock
The clock to use. -
stats
protected final net.solarnetwork.util.StatTracker statsThe statistics tracker.
-
-
Constructor Details
-
DelayedOcassionalProcessor
public DelayedOcassionalProcessor(Clock clock, net.solarnetwork.util.StatTracker stats, org.springframework.scheduling.TaskScheduler scheduler, Queue<T> items) Constructor.- Parameters:
clock- the clockstats- the statsscheduler- the scheduleritems- the item buffer; this must support concurrent accessdelegate- the delegate- Throws:
IllegalArgumentException- if any argument is null
-
-
Method Details
-
serviceDidStartup
public void serviceDidStartup()- Specified by:
serviceDidStartupin interfacenet.solarnetwork.service.ServiceLifecycleObserver
-
serviceDidShutdown
public void serviceDidShutdown()- Specified by:
serviceDidShutdownin interfacenet.solarnetwork.service.ServiceLifecycleObserver
-
asyncProcessItem
Description copied from interface:AsyncProcessorAsynchronously process an item.- Specified by:
asyncProcessItemin interfaceAsyncProcessor<T>- Parameters:
item- the item to asynchronously process
-
cancelAsyncProcessItem
Description copied from interface:AsyncProcessorCancel a pending task previously submitted toAsyncProcessor.asyncProcessItem(T).- Specified by:
cancelAsyncProcessItemin interfaceAsyncProcessor<T>- Parameters:
item- the item to cancel processing for
-
processItemInternal
Process a delayed item.- Parameters:
item- the item to process
-
run
public final void run() -
getPingTestId
- Specified by:
getPingTestIdin interfacenet.solarnetwork.service.PingTest
-
getPingTestName
- Specified by:
getPingTestNamein interfacenet.solarnetwork.service.PingTest
-
getPingTestMaximumExecutionMilliseconds
public long getPingTestMaximumExecutionMilliseconds()- Specified by:
getPingTestMaximumExecutionMillisecondsin interfacenet.solarnetwork.service.PingTest
-
performPingTest
- Specified by:
performPingTestin interfacenet.solarnetwork.service.PingTest- Throws:
Exception
-
getDelay
Get the delay.- Returns:
- the delay; defaults to
DEFAULT_DELAY
-
setDelay
Set the delay.- Parameters:
delay- the delay to set
-
getQueueSizeAlertThreshold
public final int getQueueSizeAlertThreshold()Set the queue size alert threshold.- Returns:
- the queue size threshold after which the ping test should fail;
defaults to
DEFAULT_QUEUE_SIZE_ALERT_THRESHOLD
-
setQueueSizeAlertThreshold
public final void setQueueSizeAlertThreshold(int queueSizeAlertThreshold) Set the queue size alert threshold.- Parameters:
queueSizeAlertThreshold- the queue size threshold after which the ping test should fail
-