类 AbstractProvider<T extends ProviderEvent>

java.lang.Object
net.sf.marineapi.provider.AbstractProvider<T>
类型参数:
T - The ProviderEvent to be dispatched.
所有已实现的接口:
EventListener, SentenceListener
直接已知子类:
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).

作者:
Kimmo Tuukkanen
  • 字段详细资料

    • DEFAULT_TIMEOUT

      public static int DEFAULT_TIMEOUT
      The default timeout for receicing a burst of sentences.
  • 构造器详细资料

    • AbstractProvider

      public AbstractProvider(SentenceReader reader, String... ids)
      Creates a new instance of AbstractProvider.
      参数:
      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.
      参数:
      reader - Sentence reader to be used as data source
      ids - Types of sentences to capture for creating provider events
  • 方法详细资料

    • addListener

      public void addListener(ProviderListener<T> listener)
      Inserts a listener to provider.
      参数:
      listener - Listener to add
    • createProviderEvent

      protected abstract T createProviderEvent()
      Creates a ProviderEvent of type T.
      返回:
      Created event, or null if failed.
    • getSentences

      protected final List<Sentence> getSentences()
      Returns the collected sentences.
      返回:
      List of sentences.
    • hasAll

      protected final boolean hasAll(String... id)
      Tells if the provider has captured all the specified sentences.
      参数:
      id - Sentence type IDs to look for.
      返回:
      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.
      参数:
      id - Sentence type IDs to look for, in prioritized order.
      返回:
      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.
      返回:
      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.
      返回:
      true if valid, otherwise false.
    • readingPaused

      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 在接口中 SentenceListener
    • readingStarted

      public void readingStarted()
      从接口复制的说明: 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.
      指定者:
      readingStarted 在接口中 SentenceListener
    • readingStopped

      public void readingStopped()
      从接口复制的说明: SentenceListener
      Called after SentenceReader has permanently stopped reading, either due to an error or by calling the SentenceReader.stop() method.
      指定者:
      readingStopped 在接口中 SentenceListener
    • removeListener

      public void removeListener(ProviderListener<T> listener)
      Removes the specified listener from provider.
      参数:
      listener - Listener to remove
    • sentenceRead

      public void sentenceRead(SentenceEvent event)
      从接口复制的说明: 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.
      指定者:
      sentenceRead 在接口中 SentenceListener
      参数:
      event - SentenceEvent containing the data.
    • setTimeout

      public void setTimeout(int millis)

      Sets the timeout for receiving a burst of sentences. The default value is 1000 ms as per default update rate of NMEA 0183 (1/s). However, the length of data bursts may vary depending on the device. If the timeout is exceeded before receiving all needed sentences, the sentences are discarded and waiting period for next burst of data is started. Use this method to increase the timeout if the bursts are constantly being discarded and thus no events are dispatched by the provider.

      参数:
      millis - Timeout to set, in milliseconds.
      另请参阅: