com.connecterra.ale.reader
Class CharacterStreamDeviceChannel
java.lang.Object
com.connecterra.ale.reader.DeviceChannel
com.connecterra.ale.reader.SocketDeviceChannel
com.connecterra.ale.reader.CharacterStreamDeviceChannel
public class CharacterStreamDeviceChannel
- extends com.connecterra.ale.reader.SocketDeviceChannel
A DeviceChannel implemented by a TCP connection initiated by the
device driver. It extends the SocketDeviceChannel to provide a
character-based interface and buffering on input.
Nested classes/interfaces inherited from class com.connecterra.ale.reader.SocketDeviceChannel |
com.connecterra.ale.reader.SocketDeviceChannel.BlockingSocketInputListener, com.connecterra.ale.reader.SocketDeviceChannel.SocketInputListener |
Methods inherited from class com.connecterra.ale.reader.SocketDeviceChannel |
addDeviceAttributes, addToPluginMeta, addToPluginMeta, close, getHostname, getInputStream, getOutputStream, getPort, getSocket, open, setBlockingListener, setListener, toString |
CharacterStreamDeviceChannel
public CharacterStreamDeviceChannel(PluginConfig config,
String portName)
throws com.connecterra.ale.resources.PluginLoadException
- Creates a new
CharacterStreamDeviceChannel
instance where the remote host is read from the
hostname
parameter and the remote port is read
from the parameter named by the portName
argument
in the given PluginConfig
. The timeout for socket
operations is read from the socketTimeout
parameter in the PluginConfig.
- Parameters:
config
- a PluginConfig
valueportName
- the String
key name of the
endpoint port parameter
- Throws:
com.connecterra.ale.resources.PluginLoadException
- if a configuration error occurs
CharacterStreamDeviceChannel
public CharacterStreamDeviceChannel(PluginConfig config)
throws com.connecterra.ale.resources.PluginLoadException
- Creates a new
CharacterStreamDeviceChannel
instance where the remote host is read from the
hostname
and
port
parameters in the given PluginConfig
.
The timeout for socket operations is read from the
socketTimeout
parameter in the PluginConfig.
- Parameters:
config
- a PluginConfig
value
- Throws:
com.connecterra.ale.resources.PluginLoadException
- if a configuration error occurs
getWriter
public Writer getWriter()
throws IOException
- Returns:
- a
Writer
for writing to an open
channel.
- Throws:
IOException
- if the channel is not open
getReader
public BufferedReader getReader()
throws IOException
- Returns a BufferedReader for reading from an open channel.
If this method is used by a driver which expects to receive
data asynchronously, and this method is used to read a
synchronous result from a command, then there is a pitfall to
avoid: if the device sent asynchronous data before the
synchronous command was received and processed, then the
command "response" may actually be the asynchronous data. The
reader should be aware of this, and be prepared to handle the
asynchronous data, either immediately or by queueing it for
later processing.
- Returns:
- a
BufferedReader
for reading from an open
channel.
- Throws:
IOException
- if the channel is not open
ready
public boolean ready()
throws IOException
- Overrides:
ready
in class com.connecterra.ale.reader.SocketDeviceChannel
- Returns:
- true if an input operation on the result of
CharacterStreamDeviceChannel.getReader()
is guaranteed not to block
- Throws:
IOException
- if the channel is not open