Package jmri.jmrix
Class AbstractNetworkPortController
- java.lang.Object
-
- jmri.jmrix.AbstractPortController
-
- jmri.jmrix.AbstractNetworkPortController
-
- All Implemented Interfaces:
NetworkPortAdapter,PortAdapter
- Direct Known Subclasses:
BiDiBNetworkPortController,DCCppNetworkPortController,EasyDccNetworkPortController,EcosPortController,JMRIClientPortController,LnNetworkPortController,MarklinPortController,MqttAdapter,NceNetworkPortController,NetworkDriverAdapter,RfidNetworkPortController,SerialNetworkPortAdapter,SRCPPortController,XNetNetworkPortController,Z21Adapter
public abstract class AbstractNetworkPortController extends AbstractPortController implements NetworkPortAdapter
Enables basic setup of a network client interface for a jmrix implementation.- See Also:
NetworkConfigException
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractPortController
AbstractPortController.Option
-
-
Field Summary
Fields Modifier and Type Field Description protected intconnTimeoutprotected java.lang.Stringm_HostNameprotected intm_portprotected java.net.SocketsocketConn-
Fields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, manufacturerName, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, reconnectMaxAttempts, reconnectMaxInterval
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractNetworkPortController(SystemConnectionMemo connectionMemo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidautoConfigure()protected voidcloseConnection()Abstract class for controllers to close the connection.voidconnect()Open the connection.voidconnect(java.lang.String host, int port)Connects to the end device using a hostname/ip address and portjava.lang.StringgetAdvertisementName()protected intgetConnectionTimeout()java.lang.StringgetCurrentPortName()Return the connection name for the network connection in the format of ip_address:portprotected java.lang.StringgetHostAddress()java.lang.StringgetHostName()java.io.DataInputStreamgetInputStream()Get the InputStream from the port.booleangetMdnsConfigure()java.io.DataOutputStreamgetOutputStream()Get the outputStream to the port.intgetPort()java.lang.StringgetServiceType()protected voidreconnectFromLoop(int retryNum)Abstract class for ports to attempt a single re-connection attempt.protected voidresetupConnection()Customizable method to deal with resetting a system connection after a successful recovery of a connection.voidsetAdvertisementName(java.lang.String AdName)protected voidsetConnectionTimeout(int t)protected voidsetHostAddress(java.lang.String s)Remember the associated IP Address This is used internally for mDNS configuration.voidsetHostName(java.lang.String s)Remember the associated host name.voidsetMdnsConfigure(boolean autoconfig)voidsetPort(int p)Remember the associated port number.voidsetPort(java.lang.String p)Remember the associated port name.voidsetServiceType(java.lang.String ServiceType)-
Methods inherited from class jmri.jmrix.AbstractPortController
configureOption1, configureOption2, configureOption3, configureOption4, dispose, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemConnectionMemo, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, purgeStream, reconnect, recover, safeSleep, setClosed, setDisabled, setManufacturer, setOpened, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName, status
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.NetworkPortAdapter
configure, status
-
Methods inherited from interface jmri.jmrix.PortAdapter
configureOption1, configureOption2, configureOption3, configureOption4, dispose, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemConnectionMemo, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, recover, setDisabled, setManufacturer, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName
-
-
-
-
Field Detail
-
m_HostName
protected java.lang.String m_HostName
-
m_port
protected int m_port
-
socketConn
protected java.net.Socket socketConn
-
connTimeout
protected int connTimeout
-
-
Constructor Detail
-
AbstractNetworkPortController
protected AbstractNetworkPortController(SystemConnectionMemo connectionMemo)
-
-
Method Detail
-
connect
public void connect(java.lang.String host, int port) throws java.io.IOException
Description copied from interface:NetworkPortAdapterConnects to the end device using a hostname/ip address and port- Specified by:
connectin interfaceNetworkPortAdapter- Parameters:
host- hostname / ip address.port- network port.- Throws:
java.io.IOException- on connection error.
-
connect
public void connect() throws java.io.IOException
Description copied from interface:PortAdapterOpen the connection.- Specified by:
connectin interfacePortAdapter- Throws:
java.io.IOException- if unable to connect
-
setHostName
public void setHostName(java.lang.String s)
Remember the associated host name.- Specified by:
setHostNamein interfaceNetworkPortAdapter- Parameters:
s- the host name; if empty will use MDNS to get host name
-
getHostName
public java.lang.String getHostName()
- Specified by:
getHostNamein interfaceNetworkPortAdapter
-
setHostAddress
protected void setHostAddress(java.lang.String s)
Remember the associated IP Address This is used internally for mDNS configuration. Public access to the IP address is through the hostname field.- Parameters:
s- the address; if empty, will use the host name
-
getHostAddress
protected java.lang.String getHostAddress()
-
setPort
public void setPort(int p)
Remember the associated port number.- Specified by:
setPortin interfaceNetworkPortAdapter- Parameters:
p- the port
-
setPort
public void setPort(java.lang.String p)
Description copied from interface:NetworkPortAdapterRemember the associated port name.- Specified by:
setPortin interfaceNetworkPortAdapter- Parameters:
p- port name.
-
getPort
public int getPort()
- Specified by:
getPortin interfaceNetworkPortAdapter
-
getCurrentPortName
public java.lang.String getCurrentPortName()
Return the connection name for the network connection in the format of ip_address:port- Specified by:
getCurrentPortNamein interfaceNetworkPortAdapter- Specified by:
getCurrentPortNamein interfacePortAdapter- Specified by:
getCurrentPortNamein classAbstractPortController- Returns:
- ip_address:port
-
setMdnsConfigure
public void setMdnsConfigure(boolean autoconfig)
- Specified by:
setMdnsConfigurein interfaceNetworkPortAdapter
-
getMdnsConfigure
public boolean getMdnsConfigure()
- Specified by:
getMdnsConfigurein interfaceNetworkPortAdapter
-
autoConfigure
public void autoConfigure()
- Specified by:
autoConfigurein interfaceNetworkPortAdapter
-
setAdvertisementName
public void setAdvertisementName(java.lang.String AdName)
- Specified by:
setAdvertisementNamein interfaceNetworkPortAdapter
-
getAdvertisementName
public java.lang.String getAdvertisementName()
- Specified by:
getAdvertisementNamein interfaceNetworkPortAdapter
-
setServiceType
public void setServiceType(java.lang.String ServiceType)
- Specified by:
setServiceTypein interfaceNetworkPortAdapter
-
getServiceType
public java.lang.String getServiceType()
- Specified by:
getServiceTypein interfaceNetworkPortAdapter
-
getInputStream
public java.io.DataInputStream getInputStream()
Get the InputStream from the port.- Specified by:
getInputStreamin interfacePortAdapter- Specified by:
getInputStreamin classAbstractPortController- Returns:
- the InputStream from the port
-
getOutputStream
public java.io.DataOutputStream getOutputStream()
Get the outputStream to the port.- Specified by:
getOutputStreamin interfacePortAdapter- Specified by:
getOutputStreamin classAbstractPortController- Returns:
- the outputStream to the port
-
closeConnection
protected void closeConnection()
Abstract class for controllers to close the connection. Called prior to any re-connection attempts.- Overrides:
closeConnectionin classAbstractPortController
-
resetupConnection
protected void resetupConnection()
Customizable method to deal with resetting a system connection after a successful recovery of a connection.- Overrides:
resetupConnectionin classAbstractPortController
-
reconnectFromLoop
protected void reconnectFromLoop(int retryNum)
Abstract class for ports to attempt a single re-connection attempt. Called from within main reconnect thread.- Overrides:
reconnectFromLoopin classAbstractPortController- Parameters:
retryNum- Reconnection attempt number.
-
setConnectionTimeout
protected void setConnectionTimeout(int t)
-
getConnectionTimeout
protected int getConnectionTimeout()
-
-