Class AbstractChannelConnector<O,​I,​CO,​CI>

  • Type Parameters:
    O - the output type from the underlying machine/platform
    I - the input type to the underlying machine/platform
    CO - the output type of the connector
    CI - the input type of the connector
    All Implemented Interfaces:
    Connector<O,​I,​CO,​CI>, EventHandlingConnector, AbstractModelAccess.NotificationChangedListener

    public abstract class AbstractChannelConnector<O,​I,​CO,​CI>
    extends AbstractConnector<O,​I,​CO,​CI>
    Defines a basic channeled connector.
    Author:
    Holger Eichelberger, SSE
    • Constructor Detail

      • AbstractChannelConnector

        @SafeVarargs
        protected AbstractChannelConnector​(ChannelProtocolAdapter<O,​I,​CO,​CI>... adapter)
        Creates an instance and installs the protocol adapter.
        Parameters:
        adapter - the protocol adapter
        Throws:
        java.lang.IllegalArgumentException - if adapter is null or empty or adapters are null
      • AbstractChannelConnector

        @SafeVarargs
        protected AbstractChannelConnector​(ChannelAdapterSelector<O,​I,​CO,​CI> selector,
                                           ChannelProtocolAdapter<O,​I,​CO,​CI>... adapter)
        Creates an instance and installs the protocol adapter.
        Parameters:
        selector - the adapter selector (null leads to a default selector for the first adapter)
        adapter - the protocol adapter
        Throws:
        java.lang.IllegalArgumentException - if adapter is null or empty or adapters are null
    • Method Detail

      • ensureAdapterSelector

        private static <O,​I,​CO,​CI> ChannelAdapterSelector<O,​I,​CO,​CI> ensureAdapterSelector​(ChannelAdapterSelector<O,​I,​CO,​CI> selector)
        Ensures that there is at least a default first-adapter selector of the right type.
        Type Parameters:
        O - the output type from the underlying machine/platform
        I - the input type to the underlying machine/platform
        CO - the output type of the connector
        CI - the input type of the connector
        Parameters:
        selector - the adapter selector (null leads to a default selector for the first adapter)
        Returns:
        selector or a default selector instance
      • request

        public CO request​(java.lang.String channel,
                          boolean notifyCallback)
                   throws java.io.IOException
        Explicitly requests reading data from the source. This is typically done by polling or events, but, in seldom cases, may be needed manually.
        Overrides:
        request in class AbstractConnector<O,​I,​CO,​CI>
        Parameters:
        channel - the channel to assign the received data to, may be AbstractConnector.DEFAULT_CHANNEL.
        notifyCallback - whether the reception callback shall be informed about new data
        Returns:
        the data from the machine, null for none, i.e., also no call to the reception callback
        Throws:
        java.io.IOException - in case that reading fails
      • write

        public void write​(CI data)
                   throws java.io.IOException
        Description copied from interface: Connector
        Writes the given data to the underlying machine/platform.
        Specified by:
        write in interface Connector<O,​I,​CO,​CI>
        Overrides:
        write in class AbstractConnector<O,​I,​CO,​CI>
        Parameters:
        data - the data to send to stream
        Throws:
        java.io.IOException - in case that problems during the connection happens
      • writeImpl

        protected final void writeImpl​(I data)
                                throws java.io.IOException
        Description copied from class: AbstractConnector
        Does the actual writing to the underlying machine/platform. Can be left empty if MachineConnector.hasModel().
        Specified by:
        writeImpl in class AbstractConnector<O,​I,​CO,​CI>
        Parameters:
        data - the data to be send
        Throws:
        java.io.IOException - if sending fails
      • writeImpl

        protected abstract void writeImpl​(I data,
                                          java.lang.String channel)
                                   throws java.io.IOException
        Does the actual writing to the underlying machine/platform. Can be left empty if MachineConnector.hasModel().
        Parameters:
        data - the data to be send
        channel - the channel name to use
        Throws:
        java.io.IOException - if sending fails
      • getOutputChannels

        protected java.lang.String[] getOutputChannels()
        Returns the output channel names.
        Returns:
        the output channel names