Package de.gmxhome.conrad.jpos.jpos_base
Class TcpClientIOProcessor
java.lang.Object
de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
de.gmxhome.conrad.jpos.jpos_base.TcpClientIOProcessor
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
SSLClientIOProcessor
Class to process TCP client communication. Includes functionality for automatic
data logging. Implementation is based on Java class Socket.
-
Field Summary
Fields inherited from class de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
Dev, InitialPort, IOProcessorError, LoggingData, LoggingPrefix, LoggingType, LoggingTypeEscapeString, LoggingTypeHexString, LoggingTypeNoLogging, Port, Source, Target, Timeout
-
Constructor Summary
ConstructorsConstructorDescriptionTcpClientIOProcessor(JposDevice dev, String addr)
Stores JposDevice and tcp address of derived IO processors. -
Method Summary
Modifier and TypeMethodDescriptionint
Retrieves no.void
close()
Finished any communication.void
flush()
Empties input and output buffervoid
open(boolean noErrorLog)
Opens processor for communication to specific source / target.byte[]
read(int count)
Reads a frame of given maximum byte length from communication source.void
setParam(int ownport)
Sets TCP specific communication parameter.void
setParam(int ownport, int connectTimeout)
Sets TCP specific communication parameter.Sets communication target.int
write(byte[] buffer)
Write a frame to the communication target.Methods inherited from class de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
getSource, getTarget, location, logerror, logerror, logerror, setLoggingType, setTimeout, toLogString
-
Constructor Details
-
TcpClientIOProcessor
Stores JposDevice and tcp address of derived IO processors. The device will be used for logging while the tcp address specifies the communication object.- Parameters:
dev
- Device that uses the proceessor. Processor uses loging of device to produce logging entriesaddr
- Communication object, e.g. 127.0.0.1:23456 for IPv4 and [12:34:56:78:9a:bc:de:f0]:23456 for IPv6.- Throws:
jpos.JposException
- If addr if not a valid tcp address in format IP:port.
-
-
Method Details
-
setParam
public void setParam(int ownport) throws jpos.JposExceptionSets TCP specific communication parameter.- Parameters:
ownport
- Own port address- Throws:
jpos.JposException
- If port address < 0 or port address > 65535
-
setParam
public void setParam(int ownport, int connectTimeout) throws jpos.JposExceptionSets TCP specific communication parameter.- Parameters:
ownport
- Own port addressconnectTimeout
- Connect timeout in milliseconds. Must be > 0- Throws:
jpos.JposException
- If port address < 0 or port address > 65535
-
setTarget
Description copied from class:UniqueIOProcessor
Sets communication target. Depending on the IO processor type, setting communication target can be mandatory before calling method open.- Overrides:
setTarget
in classUniqueIOProcessor
- Parameters:
target
- communication target- Returns:
- target
- Throws:
jpos.JposException
- if target is not a valid communication target.
-
write
public int write(byte[] buffer) throws jpos.JposExceptionDescription copied from class:UniqueIOProcessor
Write a frame to the communication target. If called from a derived class, the byte array must be passed through unchanged for correct logging.- Overrides:
write
in classUniqueIOProcessor
- Parameters:
buffer
- byte buffer containing the frame- Returns:
- Number of bytes written to the target
- Throws:
jpos.JposException
- if something goes wrong
-
available
public int available() throws jpos.JposExceptionDescription copied from class:UniqueIOProcessor
Retrieves no. of readable units from communication source. If called from a derived class, LoggingData must be filled with the count to be returned.- Overrides:
available
in classUniqueIOProcessor
- Returns:
- Unit count
- Throws:
jpos.JposException
- if something goes wrong
-
read
public byte[] read(int count) throws jpos.JposExceptionDescription copied from class:UniqueIOProcessor
Reads a frame of given maximum byte length from communication source. If called from a derived class, LoggingData must be filled with the byte array to be returned. If LoggingData is longer than the maximum length, the remaining bytes will be discarded.- Overrides:
read
in classUniqueIOProcessor
- Parameters:
count
- Maximum no. of bytes to be read- Returns:
- byte[] containing received bytes. In case of timeout, less than count bytes will be returned, in extreme case, the array has length zero.
- Throws:
jpos.JposException
- if something goes wrong
-
flush
public void flush() throws jpos.JposExceptionDescription copied from class:UniqueIOProcessor
Empties input and output buffer- Overrides:
flush
in classUniqueIOProcessor
- Throws:
jpos.JposException
- Iif something goes wrong
-
open
public void open(boolean noErrorLog) throws jpos.JposExceptionDescription copied from class:UniqueIOProcessor
Opens processor for communication to specific source / target. Communication parameters must be set previously by specific setup method(s).- Overrides:
open
in classUniqueIOProcessor
- Parameters:
noErrorLog
- if set, no logging occurs in error case to avoid a flood of error messages.- Throws:
jpos.JposException
- if an IO error occurs
-
close
public void close() throws jpos.JposExceptionDescription copied from class:UniqueIOProcessor
Finished any communication.- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in classUniqueIOProcessor
- Throws:
jpos.JposException
- If an IO error occurs
-