|
LiveGraph data visualisation and analysis framework |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.LiveGraph.dataCache.UpdateInvoker
public class UpdateInvoker
An object of this class is used to triger updates from a data input stream
into a DataCache
at regular intervals.
This product includes software developed by the
LiveGraph project and its contributors.
(http://www.live-graph.org)
Copyright (c) 2007-2008 G. Paperin.
All rights reserved.
File: UpdateInvoker.java
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:
1. Redistributions of source code must retain the above
acknowledgement of the LiveGraph project and its web-site, the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the
LiveGraph project and its web-site, the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with
the distribution.
3. All advertising materials mentioning features or use of this software or any derived
software must display the following acknowledgement:
This product includes software developed by the LiveGraph project and its
contributors.
(http://www.live-graph.org)
4. All advertising materials distributed in form of HTML pages or any other technology
permitting active hyper-links that mention features or use of this software or any
derived software must display the acknowledgment specified in condition 3 of this
agreement, and in addition, include a visible and working hyper-link to the LiveGraph
homepage (http://www.live-graph.org).
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Field Summary | |
---|---|
private DataCache |
dataCache
Cache to hold the data. |
private java.io.File |
dataFile
Data file from which to update. |
private DataStreamReader |
dataReader
The data reader for the input stream. |
private long |
interval
Interval between updates in milliseconds. |
private long |
lastUpdateTime
System milliseconds at last update. |
private boolean |
memoryStreamMode
Determines wether the invoker is in memory-stream mode. |
private boolean |
mustQuit
Whether the invoker thread should wind up at the next possibility. |
private long |
remainingMillis
Remaining milliseconds till the next update. |
private long |
sinceUpdateTime
Milliseconds since last update. |
private static long |
timeTickLength
How long to sleep for when updates are to be invoked automatically. |
Constructor Summary | |
---|---|
UpdateInvoker(DataCache cache)
Constructs a new invoker. |
Method Summary | |
---|---|
boolean |
checkEventInterest(Event<? extends EventType> event)
Does nothing. |
boolean |
checkEventValid(Event<? extends EventType> event,
boolean soFar)
Validates (or not) settings event. |
private void |
closeDataReader()
|
void |
completedRegisterWithEventManager(EventManager manager)
Does nothing. |
void |
completedUnregisterWithEventManager(EventManager manager)
Does nothing. |
boolean |
endMemoryStreamMode()
|
boolean |
eventProcessingException(Event<? extends EventType> event,
EventProcessingException exception)
Objects of this class do not handle eventProcessingException notofications. |
void |
eventProcessingFinished(Event<? extends EventType> event)
Objects of this class do not handle eventProcessingFinished notifications. |
void |
eventRaised(Event<? extends EventType> event)
Processes events. |
long |
getInterval()
The length of the interval between data updates. |
long |
getRemainingMillis()
Time to next update. |
private boolean |
openDataFileReader()
Creates a new DataStreamToCacheReader for a stream on the currently set data file. |
boolean |
permissionRegisterWithEventManager(EventManager manager)
Permits to register as listener with the main LiveGraph event manager and only with the main LiveGraph event manager. |
boolean |
permissionUnregisterWithEventManager(EventManager manager)
Does not permit any unregistering. |
private void |
processSettingsEvent(Event<SettingsEvent> event)
When the application's settings change, this method is called in order to update the internal state accordingly. |
private void |
raiseCannotInitiateUpdate(java.lang.String message)
|
private void |
raiseTimerTick()
Raises an event to notify listeners that this invoker has waken up to process events. |
boolean |
ready()
Tells whether this invoker's reader's underlying data stream is ready to be read. |
void |
requestUpdate()
Raises a UPDIN_InitiateUpdate -event to notify the DataStreamToCacheReader that
it is time for a data update. |
private void |
resetCache(DataCache.CacheMode mode)
|
void |
run()
Main invoker loop: call timeTick() ;
if it is time for the next update, call requestUpdate() ;
call timeTick() again and continue the loop until mustQuit is set to true;
call tidyUp() before quitting. |
private void |
setDataFile(java.lang.String fileName)
Sets the file from which the next update will be read and closes the previously used reader. |
private void |
setInterval(long interval)
Sets the length of the interval between automatic data updates in milliseconds. |
void |
setMustQuit(boolean val)
Used to notify this invoker that is must stop running at the next possibility. |
DataStreamWriter |
startMemoryStreamMode()
Uses a pipe buffer of 5 MB. |
boolean |
startMemoryStreamMode(java.io.InputStream in)
|
private void |
tidyUp()
Winds up the operations by closing the current data reader. |
private void |
timeTick()
Send the this invoker to sleep for timeTickLength milliseconds. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long timeTickLength
private boolean memoryStreamMode
startMemoryStreamMode(InputStream)
private DataStreamReader dataReader
private DataCache dataCache
private java.io.File dataFile
private long interval
private boolean mustQuit
private long remainingMillis
private long lastUpdateTime
private long sinceUpdateTime
Constructor Detail |
---|
public UpdateInvoker(DataCache cache)
cache
- The application's data cache.Method Detail |
---|
private void setInterval(long interval)
interval <= 0
the update will not be triggered automatically.
interval
- The length of the interval between automatic data updates in milliseconds
(if interval <= 0
the update will not be triggered automatically).public long getInterval()
interval <= 0
the update will not be triggered automatically.
interval <= 0
indicated that no updates will be triggered automatically.public void setMustQuit(boolean val)
val
- Whether this invoker should stop running at the next possibility.public long getRemainingMillis()
private void resetCache(DataCache.CacheMode mode)
private void setDataFile(java.lang.String fileName)
fileName
- File from which to read the data from now on.
java.lang.IllegalStateException
- If no valid data cache is set.private void closeDataReader()
public boolean ready() throws java.io.IOException
true
if the next readFromStream()
is guaranteed not to block for input,
false
otherwise. Note that returning false
does not guarantee that the next read will block.
java.io.IOException
- If an I/O error occurs.private void raiseCannotInitiateUpdate(java.lang.String message)
private boolean openDataFileReader()
DataStreamToCacheReader
for a stream on the currently set data file.
Called by requestUpdate()
either when no data reader is available
(dataReader
is null
), or if a data reader is available, but "do not cacha data"
is activated.
true
if a data reader was opened, false
if a data reader could not be
successfully opened (also raises an UPDIN_CannotInitiateUpdate
-event).public void requestUpdate()
UPDIN_InitiateUpdate
-event to notify the DataStreamToCacheReader
that
it is time for a data update.
private void timeTick()
timeTickLength
milliseconds.
When it wakes it, internal time state is updated an the observers notified.
private void raiseTimerTick()
private void tidyUp()
public void run()
timeTick()
;
if it is time for the next update, call requestUpdate()
;
call timeTick()
again and continue the loop until mustQuit
is set to true;
call tidyUp()
before quitting.
run
in interface java.lang.Runnable
public DataStreamWriter startMemoryStreamMode()
startMemoryStreamMode(InputStream)
to initiate the memory stream mode.
public boolean startMemoryStreamMode(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public boolean endMemoryStreamMode()
public boolean permissionRegisterWithEventManager(EventManager manager)
permissionRegisterWithEventManager
in interface EventListener
manager
- The EventManager
for the registering attempt.
(LiveGraph.application().eventManager() == manager)
.EventListener.permissionRegisterWithEventManager(EventManager)
public boolean permissionUnregisterWithEventManager(EventManager manager)
permissionUnregisterWithEventManager
in interface EventListener
manager
- The EventManager
for the registering attempt.
false
.EventListener.permissionUnregisterWithEventManager(EventManager)
public void completedRegisterWithEventManager(EventManager manager)
completedRegisterWithEventManager
in interface EventListener
manager
- The EventManager
with which this EventListener
is now registered.EventListener.completedRegisterWithEventManager(EventManager)
public void completedUnregisterWithEventManager(EventManager manager)
completedUnregisterWithEventManager
in interface EventListener
manager
- The EventManager
with which this EventListener
is now unregistered.EventListener.completedUnregisterWithEventManager(EventManager)
public boolean checkEventInterest(Event<? extends EventType> event)
checkEventInterest
in interface EventListener
event
- An event in which this EventListener
may be interested.
false
.EventListener.checkEventInterest(Event)
public boolean checkEventValid(Event<? extends EventType> event, boolean soFar)
checkEventValid
in interface EventListener
event
- The event to be validated.soFar
- Whether event
has been successfuly validated by whichever EventListener
s
(if any) were invoked to validate event
before this EventListener
.
false
if this invoker is in memoryStreamMode
and if the event is of the types
[DFS_DataFile, DFS_DoNotCacheData, DFS_ShowOnlyTailData, DFS_Load]
.EventListener.checkEventValid(Event, boolean)
public void eventRaised(Event<? extends EventType> event)
eventRaised
in interface EventListener
event
- Event to process.private void processSettingsEvent(Event<SettingsEvent> event)
event
- Describes the change event.public void eventProcessingFinished(Event<? extends EventType> event)
eventProcessingFinished
notifications.
eventProcessingFinished
in interface EventProducer
event
- Ignored.public boolean eventProcessingException(Event<? extends EventType> event, EventProcessingException exception)
eventProcessingException
notofications.
eventProcessingException
in interface EventProducer
event
- Ignored.exception
- Never actually thrown.
false
.
|
LiveGraph data visualisation and analysis framework |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |