net.sf.marineapi.provider
Class AbstractProvider<T extends ProviderEvent>

java.lang.Object
  extended by net.sf.marineapi.provider.AbstractProvider<T>
All Implemented Interfaces:
EventListener, SentenceListener
Direct Known Subclasses:
HeadingProvider, PositionProvider, SatelliteInfoProvider

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).

Author:
Kimmo Tuukkanen

Constructor Summary
AbstractProvider(SentenceReader reader, SentenceId... ids)
          Creates a new instance of AbstractProvider.
AbstractProvider(SentenceReader reader, String... ids)
          Creates a new instance of AbstractProvider.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractProvider

public AbstractProvider(SentenceReader reader,
                        String... ids)
Creates a new instance of AbstractProvider.

Parameters:
reader - Sentence reader to be used as data source
ids - Types of sentences to capture for creating provider events

AbstractProvider

public AbstractProvider(SentenceReader reader,
                        SentenceId... ids)
Creates a new instance of AbstractProvider.

Parameters:
reader - Sentence reader to be used as data source
ids - Types of sentences to capture for creating provider events
Method Detail

addListener

public void addListener(ProviderListener<T> listener)
Inserts a listener to provider.

Parameters:
listener - Listener to add

createProviderEvent

protected abstract T createProviderEvent()
Creates a ProviderEvent of type T.

Returns:
Created event, or null if failed.

getSentences

protected final List<Sentence> getSentences()
Returns the collected sentences.

Returns:
List of sentences.

hasAll

protected final boolean hasAll(String... id)
Tells if the provider has captured all the specified sentences.

Parameters:
id - Sentence type IDs to look for.
Returns:
True if all specified IDs match the captured sentences.

hasOne

protected final boolean hasOne(String... id)
Tells if the provider has captured at least one of the specified sentences.

Parameters:
id - Sentence type IDs to look for, in prioritized order.
Returns:
True if any of the specified IDs matches the type of at least one captured sentences.

isReady

protected abstract boolean isReady()
Tells if provider has captured the required sentences for creating new ProviderEvent.

Returns:
true if ready to create ProviderEvent, otherwise false.

isValid

protected abstract boolean isValid()
Tells if the captured sentence events contain valid data to be dispatched to ProviderListeners.

Returns:
true if valid, otherwise false.

readingPaused

public void readingPaused()
Description copied from interface: 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).

Specified by:
readingPaused in interface SentenceListener

readingStarted

public void readingStarted()
Description copied from interface: SentenceListener
Called before 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.

Specified by:
readingStarted in interface SentenceListener

readingStopped

public void readingStopped()
Description copied from interface: SentenceListener
Called after SentenceReader has permanently stopped reading, either due to an error or by calling the SentenceReader.stop() method.

Specified by:
readingStopped in interface SentenceListener

removeListener

public void removeListener(ProviderListener<T> listener)
Removes the specified listener from provider.

Parameters:
listener - Listener to remove

sentenceRead

public void sentenceRead(SentenceEvent event)
Description copied from interface: SentenceListener
Called by 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.

Specified by:
sentenceRead in interface SentenceListener
Parameters:
event - SentenceEvent containing the data.


Copyright (C) 2010-2014 Java Marine API authors. All Rights Reserved.