Class PortConnector

java.lang.Object
org.ka2ddo.ax25.Connector
org.ka2ddo.yaac.io.PortConnector
Direct Known Subclasses:
AbstractGpsConnector, ExternalMessageSourceConnector, GpsdConnector, SerialWeatherConnector, TNCConnector, WxnowTxtConnector

public abstract class PortConnector extends Connector
This class defines the generic API for an object that connects a bidirectional real-time data stream to this application.

To support the dynamically plugin-built support for multiple port types, each non-abstract PortConnector subclass must define the following public static final fields:

  • TYPE_NAME - a String specifying the internal type name of the class (stored in the PortConfig.portType field of PortConfig records)
  • CONFIG_GUI - a wildcarded fully-qualified String name of a Class which implements an editor for the configuration parameters for the PortConnector subclass

To support configuration transfer, the subclass must also define the following public static final fields:

  • BLANK_FIELDS - a Set of the PortConfig.Fields enums for the fields that should not be copied for this port driver
  • REQ_FIELDS - a Map of the PortConfig.Fields enums for the fields that must be defined for this port driver, mapping to PortConfig.RequireHints structures containing the ResourceBundle keys for their UI prompt strings if they are undefined

If a field is both required and blanked, the configuration import code will prompt for the missing field.

To support the -createport command-line option, a port type whose port editor class changes the defaults in the PortConfig.Cfg object for a new port should have those changes performed by a public static method named fillinConfigDefaults(PortConfig.Cfg) in the PortConnector subclass, so that the command-line port creation logic can fill in those defaults to deal with new port specifications that are not complete.

Author:
Andrew Pavlin, KA2DDO
See Also:
  • Field Details

    • portConfig

      public PortConfig portConfig
      The port configuration associated with this PortConnector.
    • currentCfg

      public PortConfig.Cfg currentCfg
      The port type-specific configuration associated with this PortConnector.
  • Constructor Details

    • PortConnector

      protected PortConnector()
      Create a PortConnector.
  • Method Details

    • getStats

      Get a particular category of statistics for this port. Callers who only wish to read statistics should ensure the statistics category already exists by using the getCollectedStatsTypes() method, to prevent creation of spurious statistics with zero counts.
      Parameters:
      type - PortStatsType to obtain
      Returns:
      PortStats object for the category of statistics on this port.
    • getCollectedStatsTypes

      public Set<PortConnector.PortStatsType> getCollectedStatsTypes()
      Get all the categories of statistics currently collected on this port.
      Returns:
      Set of PortStatsType enums in use for the port
    • getPortConnectorInactivityTimer

      protected static Timer getPortConnectorInactivityTimer()
      Get the Timer for use by PortConnectors to handle inactivity tests.
      Returns:
      Timer dedicated to PortConnector timeout checks
    • registerPortConnectorType

      public static void registerPortConnectorType(String typeName, Class<? extends PortConnector> pcClazz)
      Add a new subclass of PortConnector to the supported map of PortConnector types. Note that putting a new Class object with the same typeName will replace any existing driver for that type name.
      Parameters:
      typeName - String name of PortConnector subclass
      pcClazz - the Class object for instantiating objects of this type
    • portTypeNames

      public static Set<String> portTypeNames()
      Get all the registered PortConnector names that should be displayed in the port configuration dialog as a port type.
      Returns:
      Set of String names to be displayed as port driver types.
    • portConnectorClasses

      public static Collection<Class<? extends PortConnector>> portConnectorClasses()
      Get all the concrete subclasses of PortConnector currently registered in YAAC for which instances can be created and configured.
      Returns:
      Collection of subclasses of PortConnector
    • getPortConnectorClass

      public static Class<? extends PortConnector> getPortConnectorClass(String portTypeName)
      Get the class corresponding to a particular port type name.
      Parameters:
      portTypeName - String name of port connector type
      Returns:
      Class providing that port connector type, or null if no match
    • addPortEventListener

      public void addPortEventListener(PortEventListener l)
      Register a listener for port transmission and/or reception events.
      Parameters:
      l - PortEventListener to register
    • removePortEventListener

      public void removePortEventListener(PortEventListener l)
      Unregister a listener so it no longer is informed of transmission and reception events.
      Parameters:
      l - PortEventListener to unregister
    • fireTransmitting

      protected void fireTransmitting(boolean isTransmitting)
      Report to interested listeners that the port has started or stopped transmitting.
      Parameters:
      isTransmitting - boolean true if transmission has started, false if stopped
    • fireReceiving

      public void fireReceiving(boolean isReceiving)
      Report to interested listeners that the port has started or stopped receiving.
      Parameters:
      isReceiving - boolean true if reception has started, false if stopped
    • fireFailed

      public void fireFailed()
      Report to interested listeners that the port has failed for some reason.
    • fillinConfigDefaultsForType

      public static void fillinConfigDefaultsForType(PortConfig cfg) throws UnknownServiceException, IOException
      Fill in the port-type-specific defaults for a port configuration.
      Parameters:
      cfg - PortConfig whose default values are to be adjusted
      Throws:
      UnknownServiceException - if the port type is unknown
      IOException - if some other problem occurs trying to fill in the defaults
    • createPort

      public static PortConnector createPort(PortConfig cfg) throws UnknownServiceException, IOException
      Instantiate a PortConnector object of the type specified in the configuration object.
      Parameters:
      cfg - PortConfig object identifying what type of port to create
      Returns:
      instantiated but not configured PortConnector subclass object
      Throws:
      IOException - if port could not be instantiated
      UnknownServiceException - if port type not recognized
    • configure

      public abstract void configure(PortConfig cfg) throws IOException, IllegalArgumentException
      Update the configuration of the connector to match the updated setup.
      Parameters:
      cfg - PortConfig defining new port settings
      Throws:
      IOException - if interface changes could not be applied
      IllegalArgumentException - if type information is invalid for changing the settings of this PortConnector
    • getPortConfig

      public PortConfig getPortConfig()
      Get the current configuration object for this PortConnector. Note that the caller should not modify this data structure; if the port parameters are to be changed, the PortConnector should be closed and then configured with an updated PortConfig object.
      Returns:
      PortConfig for this PortConnector (may return null for a non-configured port)
      See Also:
    • setPortConfig

      public void setPortConfig(PortConfig portConfig)
      Store the configuration associated with this PortConnector. The PortConfig is assumed to be of the correct type here, such that the current() method will return the appropriate type-specific configuration data.
      Parameters:
      portConfig - PortConfig matching the PortConnector subclass's type
    • getBitRate

      public int getBitRate()
      Get the bit transmission rate on this port. This abstract superclass does not know what the data rate is, and expects subclasses to override this method.
      Returns:
      bit rate in bits per second (baud)