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 int
connTimeout
protected java.lang.String
m_HostName
protected int
m_port
protected java.net.Socket
socketConn
-
Fields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, manufacturerName, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, reconnectMaxAttempts, reconnectMaxInterval
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractNetworkPortController(SystemConnectionMemo connectionMemo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
autoConfigure()
protected void
closeConnection()
Abstract class for controllers to close the connection.void
connect()
Open the connection.void
connect(java.lang.String host, int port)
Connects to the end device using a hostname/ip address and portjava.lang.String
getAdvertisementName()
protected int
getConnectionTimeout()
java.lang.String
getCurrentPortName()
Return the connection name for the network connection in the format of ip_address:portprotected java.lang.String
getHostAddress()
java.lang.String
getHostName()
java.io.DataInputStream
getInputStream()
Get the InputStream from the port.boolean
getMdnsConfigure()
java.io.DataOutputStream
getOutputStream()
Get the outputStream to the port.int
getPort()
java.lang.String
getServiceType()
protected void
reconnectFromLoop(int retryNum)
Abstract class for ports to attempt a single re-connection attempt.protected void
resetupConnection()
Customizable method to deal with resetting a system connection after a successful recovery of a connection.void
setAdvertisementName(java.lang.String AdName)
protected void
setConnectionTimeout(int t)
protected void
setHostAddress(java.lang.String s)
Remember the associated IP Address This is used internally for mDNS configuration.void
setHostName(java.lang.String s)
Remember the associated host name.void
setMdnsConfigure(boolean autoconfig)
void
setPort(int p)
Remember the associated port number.void
setPort(java.lang.String p)
Remember the associated port name.void
setServiceType(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:NetworkPortAdapter
Connects to the end device using a hostname/ip address and port- Specified by:
connect
in 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:PortAdapter
Open the connection.- Specified by:
connect
in interfacePortAdapter
- Throws:
java.io.IOException
- if unable to connect
-
setHostName
public void setHostName(java.lang.String s)
Remember the associated host name.- Specified by:
setHostName
in interfaceNetworkPortAdapter
- Parameters:
s
- the host name; if empty will use MDNS to get host name
-
getHostName
public java.lang.String getHostName()
- Specified by:
getHostName
in 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:
setPort
in interfaceNetworkPortAdapter
- Parameters:
p
- the port
-
setPort
public void setPort(java.lang.String p)
Description copied from interface:NetworkPortAdapter
Remember the associated port name.- Specified by:
setPort
in interfaceNetworkPortAdapter
- Parameters:
p
- port name.
-
getPort
public int getPort()
- Specified by:
getPort
in interfaceNetworkPortAdapter
-
getCurrentPortName
public java.lang.String getCurrentPortName()
Return the connection name for the network connection in the format of ip_address:port- Specified by:
getCurrentPortName
in interfaceNetworkPortAdapter
- Specified by:
getCurrentPortName
in interfacePortAdapter
- Specified by:
getCurrentPortName
in classAbstractPortController
- Returns:
- ip_address:port
-
setMdnsConfigure
public void setMdnsConfigure(boolean autoconfig)
- Specified by:
setMdnsConfigure
in interfaceNetworkPortAdapter
-
getMdnsConfigure
public boolean getMdnsConfigure()
- Specified by:
getMdnsConfigure
in interfaceNetworkPortAdapter
-
autoConfigure
public void autoConfigure()
- Specified by:
autoConfigure
in interfaceNetworkPortAdapter
-
setAdvertisementName
public void setAdvertisementName(java.lang.String AdName)
- Specified by:
setAdvertisementName
in interfaceNetworkPortAdapter
-
getAdvertisementName
public java.lang.String getAdvertisementName()
- Specified by:
getAdvertisementName
in interfaceNetworkPortAdapter
-
setServiceType
public void setServiceType(java.lang.String ServiceType)
- Specified by:
setServiceType
in interfaceNetworkPortAdapter
-
getServiceType
public java.lang.String getServiceType()
- Specified by:
getServiceType
in interfaceNetworkPortAdapter
-
getInputStream
public java.io.DataInputStream getInputStream()
Get the InputStream from the port.- Specified by:
getInputStream
in interfacePortAdapter
- Specified by:
getInputStream
in classAbstractPortController
- Returns:
- the InputStream from the port
-
getOutputStream
public java.io.DataOutputStream getOutputStream()
Get the outputStream to the port.- Specified by:
getOutputStream
in interfacePortAdapter
- Specified by:
getOutputStream
in 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:
closeConnection
in classAbstractPortController
-
resetupConnection
protected void resetupConnection()
Customizable method to deal with resetting a system connection after a successful recovery of a connection.- Overrides:
resetupConnection
in 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:
reconnectFromLoop
in classAbstractPortController
- Parameters:
retryNum
- Reconnection attempt number.
-
setConnectionTimeout
protected void setConnectionTimeout(int t)
-
getConnectionTimeout
protected int getConnectionTimeout()
-
-