Class: Buffer

OSH. Buffer

Represents the buffer element which is in charge of synchronizing data.

new OSH.Buffer(options)

Name Type Description
options Object

The options object

Name Type Description
replayFactor Object

defines the replay speed of the buffer in order to synchronize data

Example

var buffer = new OSH.Buffer({
replayFactor: 1
});

Methods

addDataSource(dataSourceId, options)

Adds a new dataSource into the buffer.

Name Type Description
dataSourceId

The dataSource to add

options

syncMasterTime | bufferingTime | timeOut | name

addEntity(entity, options)

Adds an entity which contains one or more dataSources.
The dataSources are then added to the buffer using OSH.Buffer.addDataSource

Name Type Description
entity

The entity to add

options

The options object passed to the OSH.Buffer.addDataSource

buffering(name, bufferingTime)

This method is responsible of buffering data, that is to say it will timeOut the whole process to wait after more data.

Name Type Description
name

The name of the current dataSource which needs to be buffered

bufferingTime

The buffering time

cancelAll()

Cancels all current running/pending jobs. This function loop over the
datasources and cancel them one by one.

cancelDataSource(dataSourceId)

Cancels the dataSource. Cancels means to clear the data contained into the buffer and change the status to CANCEL

Name Type Description
dataSourceId

The dataSource to cancel

dispatchData(dataSourceId, data)

Dispatches the data through the EventManager. If the data to process is synchronized, it will launch a OSH.EventManager.EVENT.CURRENT_MASTER_TIME event
with {timeStamp:xxx} as parameter. In all case, it launches a OSH.EventManager.EVENT.DATA-dataSourceId event with {data:data} as parameter.

Name Type Description
dataSourceId

The dataSourceId of the data. It will be used as concatenated String into the fire method.

data

The data to fire

processData()

[TODO] This is an internal method.

processSyncData()

[TODO] This is an internal method.

push(event)

Pushes a data into the buffer. This method is used as internal method by the OSH.Buffer.startObservers.
The event contains the necessary elements to process the data.

Name Type Description
event

The event object received from the OSH.EventManager

Name Type Description
dataSourceId

The dataSource id to process

syncMasterTime

A boolean used to check if the data has to be synchronized with another data. If the value
is FALSE, the data will pass through the buffer and send back immediately.

data

The raw data provided by the DataSource

Name Type Description
timeStamp

The timeStamp of the data. It will be used in case of the syncMasterTime is set to TRUE.

Starts the buffer and starts the observers.

startAll()

Starts all dataSources. The method loops over all datasources and
calls the OSH.Buffer.startDataSource.

startDataSource(dataSourceId)

Starts buffering the dataSource.

Name Type Description
dataSourceId

the dataSource to start

startObservers()

Starts observing the data stream.

Stops the buffer and stops the observers.

stopObservers()

Stops observing the data stream.