Package jmri.jmrix

Class AbstractPortController

    • Method Detail

      • getInputStream

        public abstract java.io.DataInputStream getInputStream()
        Get the InputStream from the port.
        Specified by:
        getInputStream in interface PortAdapter
        Returns:
        the InputStream from the port
      • getOutputStream

        public abstract java.io.DataOutputStream getOutputStream()
        Get the outputStream to the port.
        Specified by:
        getOutputStream in interface PortAdapter
        Returns:
        the outputStream to the port
      • dispose

        @OverridingMethodsMustInvokeSuper
        public void dispose()
        Clean up before removal. Overriding methods must call super.dispose() or document why they are not calling the overridden implementation. In most cases, failure to call the overridden implementation will cause user-visible error.
        Specified by:
        dispose in interface PortAdapter
      • status

        public boolean status()
        Query the status of this connection. This is a question of configuration, not transient hardware status.
        Specified by:
        status in interface PortAdapter
        Returns:
        true if OK, at least as far as known
      • configureOption1

        public void configureOption1​(java.lang.String value)
        Description copied from interface: PortAdapter
        Set the first port option. Only to be used after construction, but before the openPort call.
        Specified by:
        configureOption1 in interface PortAdapter
        Parameters:
        value - to set the option to
      • configureOption2

        public void configureOption2​(java.lang.String value)
        Description copied from interface: PortAdapter
        Set the second port option. Only to be used after construction, but before the openPort call.
        Specified by:
        configureOption2 in interface PortAdapter
        Parameters:
        value - to set the option to
      • configureOption3

        public void configureOption3​(java.lang.String value)
        Description copied from interface: PortAdapter
        Set the third port option. Only to be used after construction, but before the openPort call.
        Specified by:
        configureOption3 in interface PortAdapter
        Parameters:
        value - to set the option to
      • configureOption4

        public void configureOption4​(java.lang.String value)
        Description copied from interface: PortAdapter
        Set the fourth port option. Only to be used after construction, but before the openPort call.
        Specified by:
        configureOption4 in interface PortAdapter
        Parameters:
        value - to set the option to
      • getOptions

        public java.lang.String[] getOptions()
        Get a list of all the options configured against this adapter.
        Specified by:
        getOptions in interface PortAdapter
        Returns:
        Array of option identifier strings
      • setOptionState

        public void setOptionState​(java.lang.String option,
                                   java.lang.String value)
        Set the value of an option.
        Specified by:
        setOptionState in interface PortAdapter
        Parameters:
        option - the name string of the option
        value - the string value to set the option to
      • getOptionState

        public java.lang.String getOptionState​(java.lang.String option)
        Get the string value of a specific option.
        Specified by:
        getOptionState in interface PortAdapter
        Parameters:
        option - the name of the option to query
        Returns:
        the option value
      • getOptionChoices

        public java.lang.String[] getOptionChoices​(java.lang.String option)
        Get a list of the various choices allowed with a given option.
        Specified by:
        getOptionChoices in interface PortAdapter
        Parameters:
        option - the name of the option to query
        Returns:
        list of valid values for the option, null if none are available
      • isOptionTypeText

        public boolean isOptionTypeText​(java.lang.String option)
        Description copied from interface: PortAdapter
        Should this option be represented by a text field (as opposed to a JCombobox)
        Specified by:
        isOptionTypeText in interface PortAdapter
        Parameters:
        option - Name of the option to check
        Returns:
        true for text representation preferred
      • isOptionTypePassword

        public boolean isOptionTypePassword​(java.lang.String option)
        Description copied from interface: PortAdapter
        Should this option be represented by a password field
        Specified by:
        isOptionTypePassword in interface PortAdapter
        Parameters:
        option - Name of the option to check
        Returns:
        true for text representation preferred
      • setManufacturer

        public void setManufacturer​(java.lang.String manufacturer)
        Description copied from interface: PortAdapter
        Set the system manufacturer's name.
        Specified by:
        setManufacturer in interface PortAdapter
        Parameters:
        manufacturer - the manufacturer's name
      • setDisabled

        public void setDisabled​(boolean disabled)
        Set the connection disabled or enabled. By default connections are enabled. If the implementing class does not use a SystemConnectionMemo, this method must be overridden. Overriding methods must call super.setDisabled(boolean) to ensure the configuration change state is correctly set.
        Specified by:
        setDisabled in interface PortAdapter
        Parameters:
        disabled - true if connection should be disabled
      • setSystemPrefix

        public void setSystemPrefix​(java.lang.String systemPrefix)
        Description copied from interface: PortAdapter
        Set the system prefix for this adapter.
        Specified by:
        setSystemPrefix in interface PortAdapter
        Parameters:
        systemPrefix - the new system prefix
      • getUserName

        public java.lang.String getUserName()
        Description copied from interface: PortAdapter
        Get the user name for this adapter.
        Specified by:
        getUserName in interface PortAdapter
        Returns:
        the username or null
      • setUserName

        public void setUserName​(java.lang.String userName)
        Description copied from interface: PortAdapter
        Set the user name for this adapter.
        Specified by:
        setUserName in interface PortAdapter
        Parameters:
        userName - the new user name
      • recover

        public void recover()
        This is called when a connection is initially lost. After checking the allowConnectionRecovery flag, closes the connection, resets the open flag and attempts a reconnection.
        Specified by:
        recover in interface PortAdapter
      • closeConnection

        protected void closeConnection()
        Abstract class for controllers to close the connection. Called prior to any re-connection attempts.
      • reconnect

        protected void reconnect()
        Attempts to reconnect to a failed port. Starts a reconnect thread
      • resetupConnection

        protected void resetupConnection()
        Abstract class for controllers to re-setup a connection. Called on connection reconnect success.
      • reconnectFromLoop

        protected void reconnectFromLoop​(int retryNum)
        Abstract class for ports to attempt a single re-connection attempt. Called from within main reconnect thread.
        Parameters:
        retryNum - Reconnection attempt number.
      • setReconnectMaxAttempts

        public void setReconnectMaxAttempts​(int maxAttempts)
        Set the maximum number of reconnection attempts. -1 will set an infinite number of attempts.
        Specified by:
        setReconnectMaxAttempts in interface PortAdapter
        Parameters:
        maxAttempts - total maximum reconnection attempts.
      • getReconnectMaxAttempts

        public int getReconnectMaxAttempts()
        Get the maximum number of reconnection attempts which should be made. A value of -1 means no maximum value, i.e. infinite attempts.
        Specified by:
        getReconnectMaxAttempts in interface PortAdapter
        Returns:
        total number of attempts which should be made.
      • safeSleep

        protected static void safeSleep​(long milliseconds,
                                        java.lang.String s)
      • isDirty

        public boolean isDirty()
        Description copied from interface: PortAdapter
        Determine if configuration needs to be written to disk.
        Specified by:
        isDirty in interface PortAdapter
        Returns:
        true if configuration needs to be saved, false otherwise
      • isRestartRequired

        public boolean isRestartRequired()
        Description copied from interface: PortAdapter
        Determine if application needs to be restarted for configuration changes to be applied.
        Specified by:
        isRestartRequired in interface PortAdapter
        Returns:
        true if application needs to restart, false otherwise
      • purgeStream

        public static void purgeStream​(@Nonnull
                                       java.io.InputStream serialStream)
                                throws java.io.IOException
        Service method to purge a stream of initial contents while opening the connection.
        Parameters:
        serialStream - input data
        Throws:
        java.io.IOException - if the stream is e.g. closed due to failure to open the port completely
      • getSystemConnectionMemo

        public SystemConnectionMemo getSystemConnectionMemo()
        Get the SystemConnectionMemo associated with this object.

        This method should only be overridden to ensure that a specific subclass of SystemConnectionMemo is returned. The recommended pattern is: public MySystemConnectionMemo getSystemConnectionMemo() { return (MySystemConnectionMemo) super.getSystemConnectionMemo(); }

        Specified by:
        getSystemConnectionMemo in interface PortAdapter
        Returns:
        the currently associated SystemConnectionMemo