|
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.DataStreamToCacheReader
public class DataStreamToCacheReader
This reader will parse a data stream using DataStreamReader
and store all
information in a data cache for further processing by the application.
See DataStreamWriter
for the details of the data file format.
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: DataStreamToCacheReader.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 |
cache
Cache for storage of extracted data. |
static long |
maxWaitForUpdate
The maximum period of time the reader will wait to be able to do an update before canceling the update. |
private DataStreamReader |
previousReader
Data reader used for the previous update. |
private boolean |
updateInProgress
Whether an update is currently running. |
Constructor Summary | |
---|---|
DataStreamToCacheReader(DataCache cache)
Creates a data reader on the specified stream. |
Method Summary | |
---|---|
boolean |
checkEventInterest(Event<? extends EventType> event)
Does nothing. |
boolean |
checkEventValid(Event<? extends EventType> event,
boolean soFar)
Does nothing. |
private boolean |
checkReaderOpen(DataStreamReader reader)
Checks whether the specified reader is still open by trying to execute an action on it. |
private Event<DataUpdateEvent> |
checkUpdateCanStart(DataStreamReader reader)
Verifies that an update may begin by first checking whether another update is not in progress and then requesting all event listeners to verify a UPDIN_UpdateStart -event. |
void |
completedRegisterWithEventManager(EventManager manager)
Does nothing. |
void |
completedUnregisterWithEventManager(EventManager manager)
Does nothing. |
private Event<DataUpdateEvent> |
doCheckUpdateCanStart()
Used by checkUpdateCanStart : Verifies that an update may begin by first checking
whether another update is not in progress and then requesting all event listeners to verify a
UPDIN_UpdateStart -event. |
void |
eventCommentLine(java.lang.String line,
DataStreamReader reader)
Used for callback by the DataStreamReader ; does nothing. |
void |
eventDataLineRead(java.util.List<java.lang.String> dataTokens,
int datasetIndex,
DataStreamReader reader)
Used for callback by the DataStreamReader ; adds a dataset to the cache. |
void |
eventFileInfoLine(java.lang.String info,
DataStreamReader reader)
Used for callback by the DataStreamReader ; adds a file info line to the cache. |
void |
eventLabelsSet(java.util.List<java.lang.String> labels,
DataStreamReader reader)
Used for callback by the DataStreamReader ; setts the data column labels in the cache. |
boolean |
eventProcessingException(Event<? extends EventType> event,
EventProcessingException exception)
Does nothing. |
void |
eventProcessingFinished(Event<? extends EventType> event)
Does nothing. |
void |
eventRaised(Event<? extends EventType> event)
Processes LiveGraph events. |
void |
eventSeparatorSet(java.lang.String separator,
DataStreamReader reader)
Used for callback by the DataStreamReader ; does nothing. |
boolean |
isUpdateInProgress()
Whether an update is currently running. |
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 |
processDataUpdateEvent(Event<DataUpdateEvent> event)
Attempts to initiate an update when a UPDIN_InitiateUpdate -event is received. |
private void |
raiseUpdateFinishedError(java.lang.Throwable err)
Raises an event to notify listeners that an update has finished with errors. |
private void |
raiseUpdateFinishedSusccess()
Raises an event to notify listeners that an update has finished without any errors. |
private void |
readFromStream(DataStreamReader reader,
boolean closeAfterRead)
Reads as many data lines from the underlying stream as there are available, parses the lines and stores the extracted information (if any) in this reader's data cache. |
private void |
setUpdateInProgress(boolean state)
Sets the internal updateInProgress state. |
private void |
startDataUpdate(DataStreamReader reader,
boolean closeAfterRead)
Attempts to initiate a data update in a new thread. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long maxWaitForUpdate
private DataCache cache
private boolean updateInProgress
private DataStreamReader previousReader
Constructor Detail |
---|
public DataStreamToCacheReader(DataCache cache)
cache
- The data cache into which to store the data.Method Detail |
---|
private void readFromStream(DataStreamReader reader, boolean closeAfterRead) throws java.io.IOException, DataFormatException
reader
- Data source.closeAfterRead
- Whether to close reader after reading.
java.io.IOException
- If an I/O error occurs.
DataFormatException
- If the data stream contents do not conform with the expected data
stream format.DataStreamWriter
,
DataStreamReader
public boolean isUpdateInProgress()
private void setUpdateInProgress(boolean state)
updateInProgress
state.
state
- The new state.private boolean checkReaderOpen(DataStreamReader reader)
reader
- A data stream reader.
true
if the reader is not closed, false
otherwise.private Event<DataUpdateEvent> doCheckUpdateCanStart()
checkUpdateCanStart
: Verifies that an update may begin by first checking
whether another update is not in progress and then requesting all event listeners to verify a
UPDIN_UpdateStart
-event.
DataUpdateEvent.UPDIN_UpdateStart
if an update may begin,
null
if the verification was not successfull.private Event<DataUpdateEvent> checkUpdateCanStart(DataStreamReader reader)
UPDIN_UpdateStart
-event. If the verification is not successful, the method
pauses the current thread and then reattempts the verification. This may be repeated
several times. If the verification was not successfull after maxWaitForUpdate
milliseconds, it will be regarded as failed.
This private method assumes that the calling method has synchronised on this
.
reader
- Data source for the update.
DataUpdateEvent.UPDIN_UpdateStart
if an update may begin,
null
otherwise.private void startDataUpdate(DataStreamReader reader, boolean closeAfterRead)
UPDIN_UpdateStart
-event against all listeners. If both
succeeds, a new thread is started that will read the stream into the cache.
The verification may be attempted several times, but no longer than
maxWaitForUpdate
milliseconds.
reader
- Data source.closeAfterRead
- Whether to close reader after reading.private void raiseUpdateFinishedSusccess()
private void raiseUpdateFinishedError(java.lang.Throwable err)
err
- The Throwable
describing the error.public void eventCommentLine(java.lang.String line, DataStreamReader reader)
DataStreamReader
; does nothing.
eventCommentLine
in interface DataStreamObserver
line
- The comment line.reader
- The reader which produced this event.public void eventDataLineRead(java.util.List<java.lang.String> dataTokens, int datasetIndex, DataStreamReader reader)
DataStreamReader
; adds a dataset to the cache.
eventDataLineRead
in interface DataStreamObserver
dataTokens
- An unmodifiable list containing all data tokens parsed from this line.datasetIndex
- The number of this data line in the stream (i.e. dataset file index).reader
- The reader which produced this event.public void eventFileInfoLine(java.lang.String info, DataStreamReader reader)
DataStreamReader
; adds a file info line to the cache.
eventFileInfoLine
in interface DataStreamObserver
info
- File description/info string.reader
- The reader which produced this event.public void eventLabelsSet(java.util.List<java.lang.String> labels, DataStreamReader reader)
DataStreamReader
; setts the data column labels in the cache.
eventLabelsSet
in interface DataStreamObserver
labels
- An unmodifiable list containing all parsed data series labels.reader
- The reader which produced this event.public void eventSeparatorSet(java.lang.String separator, DataStreamReader reader)
DataStreamReader
; does nothing.
eventSeparatorSet
in interface DataStreamObserver
separator
- The new data values separator string.reader
- The reader which produced this event.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
.
true
.EventListener.checkEventValid(Event, boolean)
public void eventRaised(Event<? extends EventType> event) throws java.lang.Exception
eventRaised
in interface EventListener
event
- The event to process.
java.lang.Exception
private void processDataUpdateEvent(Event<DataUpdateEvent> event)
UPDIN_InitiateUpdate
-event is received.
event
- The event to process.public boolean eventProcessingException(Event<? extends EventType> event, EventProcessingException exception)
eventProcessingException
in interface EventProducer
event
- Event that cause an exception.exception
- The exception.
false
.public void eventProcessingFinished(Event<? extends EventType> event)
eventProcessingFinished
in interface EventProducer
event
- Event that was processed.
|
LiveGraph data visualisation and analysis framework |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |