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 TypeMethodDescriptionintRetrieves no.voidclose()Finished any communication.voidflush()Empties input and output buffervoidopen(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.voidsetParam(int ownport)Sets TCP specific communication parameter.voidsetParam(int ownport, int connectTimeout)Sets TCP specific communication parameter.Sets communication target.intwrite(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:UniqueIOProcessorSets communication target. Depending on the IO processor type, setting communication target can be mandatory before calling method open.- Overrides:
setTargetin 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:UniqueIOProcessorWrite a frame to the communication target. If called from a derived class, the byte array must be passed through unchanged for correct logging.- Overrides:
writein 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:UniqueIOProcessorRetrieves no. of readable units from communication source. If called from a derived class, LoggingData must be filled with the count to be returned.- Overrides:
availablein classUniqueIOProcessor- Returns:
- Unit count
- Throws:
jpos.JposException- if something goes wrong
-
read
public byte[] read(int count) throws jpos.JposExceptionDescription copied from class:UniqueIOProcessorReads 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:
readin 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:UniqueIOProcessorEmpties input and output buffer- Overrides:
flushin classUniqueIOProcessor- Throws:
jpos.JposException- Iif something goes wrong
-
open
public void open(boolean noErrorLog) throws jpos.JposExceptionDescription copied from class:UniqueIOProcessorOpens processor for communication to specific source / target. Communication parameters must be set previously by specific setup method(s).- Overrides:
openin 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:UniqueIOProcessorFinished any communication.- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classUniqueIOProcessor- Throws:
jpos.JposException- If an IO error occurs
-