Package org.openmuc.framework.dataaccess
Interface ChannelRuntime
-
- All Known Subinterfaces:
Channel
public interface ChannelRuntimeTheChannelclass is used to access a single data field of a communication device. A desired channel can be obtained using theDataAccessService. A channel instance can be used to- Access the latest record. That is the latest data record that the framework either sampled or received by
listening or an application set using
setLatestRecord. - Directly read/write data from/to the corresponding communication device.
- Access historical data that was stored by a data logger such as SlotsDB.
Note that only the call of the read or write functions will actually result in a corresponding read or write request being sent to the communication device.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddListener(RecordListener listener)Adds a listener that is notified of new records received by sampling or listening.RecordgetLatestRecord()Returns the latest record of this channel.RecordgetLoggedRecord(long time)Returns the logged data record whose timestamp equals the giventime.java.util.List<Record>getLoggedRecords(long startTime)Returns a list of all logged data records with timestamps fromstartTimeup until now.java.util.List<Record>getLoggedRecords(long startTime, long endTime)Returns a list of all logged data records with timestamps fromstartTimetoendTimeinclusive.ReadRecordContainergetReadContainer()Returns aReadRecordContainerthat corresponds to this channel.WriteValueContainergetWriteContainer()Returns aWriteValueContainerthat corresponds to this channel.booleanisConnected()Returnstrueif a connection to the channel's communication device exist.Recordread()Actively reads a value from the channel's corresponding data field in the connected communication device.voidremoveListener(RecordListener listener)Removes a record listener.voidsetLatestRecord(Record record)Sets the latest record of this channel.Flagwrite(Value value)Writes the given value to the channel's corresponding data field in the connected communication device.voidwriteFuture(java.util.List<FutureValue> values)Schedules a List<records> with future timestamps as write tasks
This function will schedule single write tasks to the provided timestamps.
Once this function is called, previously scheduled write tasks will be erased.
-
-
-
Method Detail
-
addListener
void addListener(RecordListener listener)
Adds a listener that is notified of new records received by sampling or listening.- Parameters:
listener- the record listener that is notified of new records.
-
removeListener
void removeListener(RecordListener listener)
Removes a record listener.- Parameters:
listener- the listener shall be removed.
-
isConnected
boolean isConnected()
Returnstrueif a connection to the channel's communication device exist.- Returns:
trueif a connection to the channel's communication device exist.
-
getLatestRecord
Record getLatestRecord()
Returns the latest record of this channel. Every channel holds its latest record in memory. There exist three possible source for the latest record:- It may be provided by a communication driver that was configured to sample or listen on the channel. In this case the timestamp of the record represents the moment in time that the value was received by the driver.
- An application may also set the latest record using
setLatestRecord. - Finally values written using
writeare also stored as the latest record
Note that the latest record is never
NULL. When a channel is first created its latest record is automatically initialized with a flag that indicates that its value is not valid.- Returns:
- the latest record.
-
setLatestRecord
void setLatestRecord(Record record)
Sets the latest record of this channel. This function should only be used with channels that are neither sampling nor listening. Using this function it is possible to realize "virtual" channels that get their data not from drivers but from applications in the framework.Note that the framework treats the passed record in exactly the same way as if it had been received from a driver. In particular that means:
- If data logging is enabled for this channel the latest record is being logged by the registered loggers.
- Other applications can access the value set by this function using
getLatestRecord. - Applications are notified of the new record if they registered as listeners using
addListener. - If a scaling factor has been configured for this channel then the value passed to this function is scaled.
- Parameters:
record- the record to be set.
-
write
Flag write(Value value)
Writes the given value to the channel's corresponding data field in the connected communication device. If an error occurs, the returnedFlagwill indicate this.- Parameters:
value- the value that is to be written- Returns:
- the flag indicating whether the value was successfully written (
Flag.VALID) or not (any other flag).
-
writeFuture
void writeFuture(java.util.List<FutureValue> values)
Schedules a List<records> with future timestamps as write tasks
This function will schedule single write tasks to the provided timestamps.
Once this function is called, previously scheduled write tasks will be erased.- Parameters:
values- a list of future write values.
-
getWriteContainer
WriteValueContainer getWriteContainer()
Returns aWriteValueContainerthat corresponds to this channel. This container can be passed to the write function ofDataAccessServiceto write several values in one transaction.- Returns:
- a
WriteValueContainerthat corresponds to this channel.
-
read
Record read()
Actively reads a value from the channel's corresponding data field in the connected communication device. If an error occurs it will be indicated in the returned record's flag.- Returns:
- the record containing the value read, the time the value was received and a flag indicating success (
Flag.VALID) or an error (any other flag).
-
getReadContainer
ReadRecordContainer getReadContainer()
Returns aReadRecordContainerthat corresponds to this channel. This container can be passed to thereadfunction ofDataAccessServiceto read several values in one transaction.- Returns:
- a
ReadRecordContainerthat corresponds to this channel.
-
getLoggedRecord
Record getLoggedRecord(long time) throws DataLoggerNotAvailableException, java.io.IOException
Returns the logged data record whose timestamp equals the giventime. Note that it is the data logger's choice whether it stores values using the timestamp that the driver recorded when it received it or the timestamp at which the value is to be logged. If the former is the case then this function is not useful because it is impossible for an application to know the exact time at which a value was received. In this case usegetLoggedRecordsinstead.- Parameters:
time- the time in milliseconds since midnight, January 1, 1970 UTC.- Returns:
- the record that has been stored by the framework's data logger at the given
timestamp. Returnsnullif no record exists for this point in time. - Throws:
DataLoggerNotAvailableException- if no data logger is installed and therefore no logged data can be accessed.java.io.IOException- if any kind of error occurs accessing the logged data.
-
getLoggedRecords
java.util.List<Record> getLoggedRecords(long startTime) throws DataLoggerNotAvailableException, java.io.IOException
Returns a list of all logged data records with timestamps fromstartTimeup until now.- Parameters:
startTime- the starting time in milliseconds since midnight, January 1, 1970 UTC. inclusive- Returns:
- a list of all logged data records with timestamps from
startTimeup until now. - Throws:
DataLoggerNotAvailableException- if no data logger is installed and therefore no logged data can be accessed.java.io.IOException- if any kind of error occurs accessing the logged data.
-
getLoggedRecords
java.util.List<Record> getLoggedRecords(long startTime, long endTime) throws DataLoggerNotAvailableException, java.io.IOException
Returns a list of all logged data records with timestamps fromstartTimetoendTimeinclusive.- Parameters:
startTime- the starting time in milliseconds since midnight, January 1, 1970 UTC. inclusiveendTime- the ending time in milliseconds since midnight, January 1, 1970 UTC. inclusive- Returns:
- a list of all logged data records with timestamps from
startTimetoendTimeinclusive. - Throws:
DataLoggerNotAvailableException- if no data logger is installed and therefore no logged data can be accessed.java.io.IOException- if any kind of error occurs accessing the logged data.
-
-