Package jmri.jmrix
Class AbstractPortController
java.lang.Object
jmri.jmrix.AbstractPortController
- All Implemented Interfaces:
PortAdapter
- Direct Known Subclasses:
AbstractNetworkPortController,AbstractSerialPortController,AbstractStreamPortController,IpocsPortController,RaspberryPiAdapter,UsbPortAdapter,XBeeIOStream
Provide an abstract base for *PortController classes.
This is complicated by the lack of multiple inheritance. SerialPortAdapter is an Interface, and its implementing classes also inherit from various PortController types. But we want some common behaviors for those, so we put them here.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Stringprotected booleanprotected Stringprotected Stringprotected Stringprotected Stringprotected HashMap<String,AbstractPortController.Option> protected intInitial interval between reconnection attempts.protected intMaximum reconnection attempts that the port should make.protected intMaximum interval between reconnection attempts in seconds. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractPortController(SystemConnectionMemo connectionMemo) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAbstract class for controllers to close the connection.voidconfigureOption1(String value) Set the first port option.voidconfigureOption2(String value) Set the second port option.voidconfigureOption3(String value) Set the third port option.voidconfigureOption4(String value) Set the fourth port option.voiddispose()Clean up before removal.abstract StringbooleanReturn the disabled state of the adapter.abstract DataInputStreamGet the InputStream from the port.Get the system manufacturer's name.String[]getOptionChoices(String option) Get a list of the various choices allowed with a given option.getOptionDisplayName(String option) String[]Get a list of all the options configured against this adapter.getOptionState(String option) Get the string value of a specific option.abstract DataOutputStreamGet the outputStream to the port.intGet the maximum number of reconnection attempts which should be made.intGet the maximum interval between reconnection attempts.Get theSystemConnectionMemoassociated with this object.Get the system prefix for this adapter.Get the user name for this adapter.booleanisDirty()Determine if configuration needs to be written to disk.booleanisOptionAdvanced(String option) booleanisOptionTypePassword(String option) Should this option be represented by a password fieldbooleanisOptionTypeText(String option) Should this option be represented by a text field (as opposed to a JCombobox)booleanDetermine if application needs to be restarted for configuration changes to be applied.static voidpurgeStream(InputStream serialStream) Service method to purge a stream of initial contents while opening the connection.protected voidAttempts to reconnect to a failed port.protected voidreconnectFromLoop(int retryNum) Abstract class for ports to attempt a single re-connection attempt.voidrecover()This is called when a connection is initially lost.protected voidAbstract class for controllers to re-setup a connection.protected static voidprotected voidvoidsetDisabled(boolean disabled) Set the connection disabled or enabled.voidsetManufacturer(String manufacturer) Set the system manufacturer's name.protected voidvoidsetOptionState(String option, String value) Set the value of an option.voidsetReconnectMaxAttempts(int maxAttempts) Set the maximum number of reconnection attemptsvoidsetReconnectMaxInterval(int maxInterval) Set the maximum interval between reconnection attempts.voidsetSystemConnectionMemo(SystemConnectionMemo connectionMemo) Set theSystemConnectionMemoassociated with this object.voidsetSystemPrefix(String systemPrefix) Set the system prefix for this adapter.voidsetUserName(String userName) Set the user name for this adapter.booleanstatus()Query the status of this connection.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.jmrix.PortAdapter
configure, connect
-
Field Details
-
manufacturerName
-
opened
-
option1Name
-
option2Name
-
option3Name
-
option4Name
-
options
-
allowConnectionRecovery
-
reconnectinterval
Initial interval between reconnection attempts. Default 1 second. -
reconnectMaxAttempts
Maximum reconnection attempts that the port should make. Default 100 attempts. A value of -1 indicates unlimited attempts. -
reconnectMaxInterval
Maximum interval between reconnection attempts in seconds. Default 120 seconds.
-
-
Constructor Details
-
AbstractPortController
-
-
Method Details
-
getInputStream
Get the InputStream from the port.- Specified by:
getInputStreamin interfacePortAdapter- Returns:
- the InputStream from the port
-
getOutputStream
Get the outputStream to the port.- Specified by:
getOutputStreamin interfacePortAdapter- Returns:
- the outputStream to the port
-
dispose
Clean up before removal. Overriding methods must callsuper.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:
disposein interfacePortAdapter
-
status
Query the status of this connection. This is a question of configuration, not transient hardware status.- Specified by:
statusin interfacePortAdapter- Returns:
- true if OK, at least as far as known
-
setOpened
-
setClosed
-
getCurrentPortName
- Specified by:
getCurrentPortNamein interfacePortAdapter
-
configureOption1
Description copied from interface:PortAdapterSet the first port option. Only to be used after construction, but before the openPort call.- Specified by:
configureOption1in interfacePortAdapter- Parameters:
value- to set the option to
-
configureOption2
Description copied from interface:PortAdapterSet the second port option. Only to be used after construction, but before the openPort call.- Specified by:
configureOption2in interfacePortAdapter- Parameters:
value- to set the option to
-
configureOption3
Description copied from interface:PortAdapterSet the third port option. Only to be used after construction, but before the openPort call.- Specified by:
configureOption3in interfacePortAdapter- Parameters:
value- to set the option to
-
configureOption4
Description copied from interface:PortAdapterSet the fourth port option. Only to be used after construction, but before the openPort call.- Specified by:
configureOption4in interfacePortAdapter- Parameters:
value- to set the option to
-
getOption1Name
- Specified by:
getOption1Namein interfacePortAdapter
-
getOption2Name
- Specified by:
getOption2Namein interfacePortAdapter
-
getOption3Name
- Specified by:
getOption3Namein interfacePortAdapter
-
getOption4Name
- Specified by:
getOption4Namein interfacePortAdapter
-
getOptions
Get a list of all the options configured against this adapter.- Specified by:
getOptionsin interfacePortAdapter- Returns:
- Array of option identifier strings
-
setOptionState
Set the value of an option.- Specified by:
setOptionStatein interfacePortAdapter- Parameters:
option- the name string of the optionvalue- the string value to set the option to
-
getOptionState
Get the string value of a specific option.- Specified by:
getOptionStatein interfacePortAdapter- Parameters:
option- the name of the option to query- Returns:
- the option value
-
getOptionChoices
Get a list of the various choices allowed with a given option.- Specified by:
getOptionChoicesin interfacePortAdapter- Parameters:
option- the name of the option to query- Returns:
- list of valid values for the option, null if none are available
-
isOptionTypeText
Description copied from interface:PortAdapterShould this option be represented by a text field (as opposed to a JCombobox)- Specified by:
isOptionTypeTextin interfacePortAdapter- Parameters:
option- Name of the option to check- Returns:
- true for text representation preferred
-
isOptionTypePassword
Description copied from interface:PortAdapterShould this option be represented by a password field- Specified by:
isOptionTypePasswordin interfacePortAdapter- Parameters:
option- Name of the option to check- Returns:
- true for text representation preferred
-
getOptionDisplayName
- Specified by:
getOptionDisplayNamein interfacePortAdapter
-
isOptionAdvanced
- Specified by:
isOptionAdvancedin interfacePortAdapter
-
getManufacturer
Description copied from interface:PortAdapterGet the system manufacturer's name.- Specified by:
getManufacturerin interfacePortAdapter- Returns:
- manufacturer's name
-
setManufacturer
Description copied from interface:PortAdapterSet the system manufacturer's name.- Specified by:
setManufacturerin interfacePortAdapter- Parameters:
manufacturer- the manufacturer's name
-
getDisabled
Description copied from interface:PortAdapterReturn the disabled state of the adapter.- Specified by:
getDisabledin interfacePortAdapter- Returns:
- true if disabled
-
setDisabled
Set the connection disabled or enabled. By default connections are enabled. If the implementing class does not use aSystemConnectionMemo, this method must be overridden. Overriding methods must callsuper.setDisabled(boolean)to ensure the configuration change state is correctly set.- Specified by:
setDisabledin interfacePortAdapter- Parameters:
disabled- true if connection should be disabled
-
getSystemPrefix
Description copied from interface:PortAdapterGet the system prefix for this adapter.- Specified by:
getSystemPrefixin interfacePortAdapter- Returns:
- the system prefix or null
-
setSystemPrefix
Description copied from interface:PortAdapterSet the system prefix for this adapter.- Specified by:
setSystemPrefixin interfacePortAdapter- Parameters:
systemPrefix- the new system prefix
-
getUserName
Description copied from interface:PortAdapterGet the user name for this adapter.- Specified by:
getUserNamein interfacePortAdapter- Returns:
- the username or null
-
setUserName
Description copied from interface:PortAdapterSet the user name for this adapter.- Specified by:
setUserNamein interfacePortAdapter- Parameters:
userName- the new user name
-
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:
recoverin interfacePortAdapter
-
closeConnection
Abstract class for controllers to close the connection. Called prior to any re-connection attempts. -
reconnect
Attempts to reconnect to a failed port. Starts a reconnect thread -
resetupConnection
Abstract class for controllers to re-setup a connection. Called on connection reconnect success. -
reconnectFromLoop
Abstract class for ports to attempt a single re-connection attempt. Called from within main reconnect thread.- Parameters:
retryNum- Reconnection attempt number.
-
setReconnectMaxInterval
Set the maximum interval between reconnection attempts.- Specified by:
setReconnectMaxIntervalin interfacePortAdapter- Parameters:
maxInterval- in seconds.
-
setReconnectMaxAttempts
Set the maximum number of reconnection attempts. -1 will set an infinite number of attempts.- Specified by:
setReconnectMaxAttemptsin interfacePortAdapter- Parameters:
maxAttempts- total maximum reconnection attempts.
-
getReconnectMaxInterval
Get the maximum interval between reconnection attempts.- Specified by:
getReconnectMaxIntervalin interfacePortAdapter- Returns:
- maximum interval in seconds.
-
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:
getReconnectMaxAttemptsin interfacePortAdapter- Returns:
- total number of attempts which should be made.
-
safeSleep
-
isDirty
Description copied from interface:PortAdapterDetermine if configuration needs to be written to disk.- Specified by:
isDirtyin interfacePortAdapter- Returns:
- true if configuration needs to be saved, false otherwise
-
isRestartRequired
Description copied from interface:PortAdapterDetermine if application needs to be restarted for configuration changes to be applied.- Specified by:
isRestartRequiredin interfacePortAdapter- Returns:
- true if application needs to restart, false otherwise
-
purgeStream
Service method to purge a stream of initial contents while opening the connection.- Parameters:
serialStream- input data- Throws:
IOException- if the stream is e.g. closed due to failure to open the port completely
-
getSystemConnectionMemo
Get theSystemConnectionMemoassociated 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:
getSystemConnectionMemoin interfacePortAdapter- Returns:
- the currently associated SystemConnectionMemo
-
setSystemConnectionMemo
@OverridingMethodsMustInvokeSuper public void setSystemConnectionMemo(@Nonnull SystemConnectionMemo connectionMemo) Set theSystemConnectionMemoassociated with this object.Overriding implementations must call
super.setSystemConnectionMemo(memo)at some point to ensure the SystemConnectionMemo gets set.- Specified by:
setSystemConnectionMemoin interfacePortAdapter- Parameters:
connectionMemo- the SystemConnectionMemo to associate with this PortController
-