public abstract class AbstractProvider<T extends ProviderEvent> extends Object implements SentenceListener
Abstract base class for providers. Defines methods that all providers must implement and provides general services for capturing and validating the required sentences.
When constructing PositionEvent
,
the maximum age for all captured sentences is 1000 ms, i.e. all sentences are
from within the default NMEA update rate (1/s).
Constructor and Description |
---|
AbstractProvider(SentenceReader reader,
SentenceId... ids)
Creates a new instance of AbstractProvider.
|
AbstractProvider(SentenceReader reader,
String... ids)
Creates a new instance of AbstractProvider.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(ProviderListener<T> listener)
Inserts a listener to provider.
|
protected abstract T |
createProviderEvent()
Creates a
ProviderEvent of type T . |
protected List<Sentence> |
getSentences()
Returns the collected sentences.
|
protected boolean |
hasAll(String... id)
Tells if the provider has captured all the specified sentences.
|
protected boolean |
hasOne(String... id)
Tells if the provider has captured at least one of the specified
sentences.
|
protected abstract boolean |
isReady()
Tells if provider has captured the required sentences for creating new
ProviderEvent.
|
protected abstract boolean |
isValid()
Tells if the captured sentence events contain valid data to be dispatched
to ProviderListeners.
|
void |
readingPaused()
Called after
SentenceReader has timed
out for receiving new data. |
void |
readingStarted()
Called before
SentenceReader starts
dispatching events. |
void |
readingStopped()
Called after
SentenceReader has
permanently stopped reading, either due to an error or by calling the
SentenceReader.stop() method. |
void |
removeListener(ProviderListener<T> listener)
Removes the specified listener from provider.
|
void |
sentenceRead(SentenceEvent event)
Called by
SentenceReader when a single
NMEA 0183 sentence has been read and parsed from the data stream. |
public AbstractProvider(SentenceReader reader, String... ids)
reader
- Sentence reader to be used as data sourceids
- Types of sentences to capture for creating provider eventspublic AbstractProvider(SentenceReader reader, SentenceId... ids)
reader
- Sentence reader to be used as data sourceids
- Types of sentences to capture for creating provider eventspublic void addListener(ProviderListener<T> listener)
listener
- Listener to addprotected abstract T createProviderEvent()
ProviderEvent
of type T
.protected final List<Sentence> getSentences()
protected final boolean hasAll(String... id)
id
- Sentence type IDs to look for.protected final boolean hasOne(String... id)
id
- Sentence type IDs to look for, in prioritized order.protected abstract boolean isReady()
protected abstract boolean isValid()
public void readingPaused()
SentenceListener
Called after SentenceReader
has timed
out for receiving new data. Indicates that the reader is still active and
waiting for new data which isn't currently available for some reason. For
example, the device may have stopped broadcasting or the end of a file
has been reached.
Default time for timeout is defined by
SentenceReader.DEFAULT_TIMEOUT
. This
value can be overridden with
SentenceReader.setPauseTimeout(int)
.
readingPaused
in interface SentenceListener
public void readingStarted()
SentenceListener
SentenceReader
starts
dispatching events. Indicates that the reader is active and receiving
data. Also, this notification occurs when the dispatching continues
again after SentenceListener.readingPaused()
has occurred.readingStarted
in interface SentenceListener
public void readingStopped()
SentenceListener
SentenceReader
has
permanently stopped reading, either due to an error or by calling the
SentenceReader.stop()
method.readingStopped
in interface SentenceListener
public void removeListener(ProviderListener<T> listener)
listener
- Listener to removepublic void sentenceRead(SentenceEvent event)
SentenceListener
SentenceReader
when a single
NMEA 0183 sentence has been read and parsed from the data stream. By
default, only supported sentences defined in
SentenceId
are dispatched.sentenceRead
in interface SentenceListener
event
- SentenceEvent containing the data.Copyright (C) 2010-2017 Java Marine API authors. All Rights Reserved.