Class DelayedWriter
- java.lang.Object
-
- java.lang.Thread
-
- org.ow2.clif.storage.lib.filestorage.DelayedWriter
-
- All Implemented Interfaces:
java.lang.Runnable
public class DelayedWriter extends java.lang.ThreadThis class supports delayed and timely ascending ordered writing of blade events to a BufferedWriter object. The goal of this feature is to write event blades in the chronological order of their starting date, regardless of the time they are actually available for writing, provided the delay is sufficient. This is mostly useful for action events: depending on response times variations, one action event E2 may be available for writing before another action event E1, while the corresponding request has been sent after, because the response time was shorter. Thanks to delayed writing, and as long as the maximum variation of response times is shorter than the delay, action reports are written in chronological order with regard to the request start date. But, when the maximum variation of response times from one request to another becomes greater than the delay, there is no guaranty that this order will be respected. The delay value in seconds may be set through system property defined byDELAY_S_PROP. Otherwise, default delay is defined byDELAY_S_DEFAULT.- Author:
- Bruno Dillenseger
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanclosingset to true when the writer must be closedprotected static longdelay_msminimum age of events before actually writing themstatic java.lang.StringDELAY_S_DEFAULTstatic java.lang.StringDELAY_S_PROPprotected java.util.SortedSet<BladeEvent>eventQprotected static longmaxPendingmaximum number of young events waiting to be written (subsumes delay_ms)static java.lang.StringMAXPENDING_DEFAULTstatic java.lang.StringMAXPENDING_PROPprotected longoffsetInitial time in msprotected java.io.BufferedWriterwriter
-
Constructor Summary
Constructors Constructor Description DelayedWriter(java.io.BufferedWriter out, long dateOffset_ms)Creates a delayed writer that will order blade events according to their date, before actually writing them using the provided BufferedWriter object, after the delay has expired.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlying buffered writer, after flushing all pending blade events to it.voidrun()The delay writer's activity consists in getting events from the blade events queue when they are sufficiently old (with respect to delay and blade event dates), and writing them to the underlying buffered writer.voidwrite(BladeEvent event)Delayed writing of a blade event.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
delay_ms
protected static long delay_ms
minimum age of events before actually writing them
-
DELAY_S_PROP
public static final java.lang.String DELAY_S_PROP
- See Also:
- Constant Field Values
-
DELAY_S_DEFAULT
public static final java.lang.String DELAY_S_DEFAULT
- See Also:
- Constant Field Values
-
maxPending
protected static long maxPending
maximum number of young events waiting to be written (subsumes delay_ms)
-
MAXPENDING_PROP
public static final java.lang.String MAXPENDING_PROP
- See Also:
- Constant Field Values
-
MAXPENDING_DEFAULT
public static final java.lang.String MAXPENDING_DEFAULT
- See Also:
- Constant Field Values
-
eventQ
protected java.util.SortedSet<BladeEvent> eventQ
-
offset
protected long offset
Initial time in ms
-
writer
protected java.io.BufferedWriter writer
-
closing
protected volatile boolean closing
set to true when the writer must be closed
-
-
Constructor Detail
-
DelayedWriter
public DelayedWriter(java.io.BufferedWriter out, long dateOffset_ms)Creates a delayed writer that will order blade events according to their date, before actually writing them using the provided BufferedWriter object, after the delay has expired.- Parameters:
out- the buffered writer to be used for finally writing blades eventdateOffset_ms- the initial date in ms (this value will be subtracted from the events dates when they are finally written to the buffered writer).
-
-
Method Detail
-
write
public void write(BladeEvent event) throws java.io.IOException
Delayed writing of a blade event. The delay applies from the date of the event (not current date when calling this method).- Parameters:
event- the blade event to write- Throws:
java.io.IOException- the delayed writer has been closed and cannot be used anymore.
-
close
public void close()
Closes the underlying buffered writer, after flushing all pending blade events to it. Any further attempt to write a blade event to this delayed writer will be rejected.
-
run
public void run()
The delay writer's activity consists in getting events from the blade events queue when they are sufficiently old (with respect to delay and blade event dates), and writing them to the underlying buffered writer. Sleeps if no event is old enough. The sleep duration depends on the delay value and the oldest pending event's date if any. Sleep is interrupted and all pending events are flushed to the buffered writer when the delayed writer is closed.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
-