Package de.gmxhome.conrad.jpos.jpos_base
Class UniqueIOProcessor
java.lang.Object
de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
SerialIOProcessor
,TcpClientIOProcessor
,UdpBaseIOProcessor
Unique implementation for IO processing. Derived classes should add
support for serial (RS232), TCP and other IO operations
-
Field Summary
FieldsModifier and TypeFieldDescriptionDevice used for loggingprotected String
Initial communication target, used to check whether source (read) or target (write) shall be logged in read or write methods.static int
Extended error code for JposExceptions generated by IO processors.byte[]
Buffer with data to be logged in case of normal processing.protected String
Logging prefix.protected int
Logging type, one of LoggingTypeHexString, LoggingTypeEscapeString or LoggingTypeNoLogging.static int
Logging type constant for excape-string style logging.static int
Logging type constant for hex-dump-style logging.static int
Logging type constant for no data logging.protected String
Communication port of the processor.protected String
Communication source, used for reading data.protected String
Communication target, used for writing data.protected int
Read timeout in milliseconds. -
Constructor Summary
ConstructorsConstructorDescriptionUniqueIOProcessor(JposDevice dev, String port)
Stores JposDevice and port of derived IO processors. -
Method Summary
Modifier and TypeMethodDescriptionint
Retrieves no.void
close()
Finished any communication.void
flush()
Empties input and output bufferGets source of previously read data.Retrieves currently set target for writing data.protected String
location(boolean from)
Generates string to be inserted into logging message whenever the source or target port does not match the initial port.int
Generate a logging error message and throw an JposException.int
Generate a logging error message and throw the corresponding JposException.int
Generate a logging error message and throw an JposException.void
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.int
setLoggingType(int type)
Sets the logging type for data logging.Sets communication target.int
setTimeout(int timeout)
Sets read timeouttoLogString(byte[] buffer)
Generate log string from byte bufferint
write(byte[] buffer)
Write a frame to the communication target.
-
Field Details
-
Source
Communication source, used for reading data. For RS232, Source, Target and Port are the same. In case of network connections, they can be different. -
IOProcessorError
public static final int IOProcessorErrorExtended error code for JposExceptions generated by IO processors.- See Also:
- Constant Field Values
-
Target
Communication target, used for writing data. For RS232, Source, Target and Port are the same. In case of network connections, they can be different. -
InitialPort
Initial communication target, used to check whether source (read) or target (write) shall be logged in read or write methods. -
Port
Communication port of the processor. Can be the name of a COM port in case of RS232 or the (own) port number in case of TCP or UDP. -
LoggingPrefix
Logging prefix. String that will be used as prefix for all logging messages. Default: Port + ": " -
Timeout
protected int TimeoutRead timeout in milliseconds. Default: 0x10000000 (more than 8 years) -
LoggingType
protected int LoggingTypeLogging type, one of LoggingTypeHexString, LoggingTypeEscapeString or LoggingTypeNoLogging. Default LoggingTypeEscapeString. -
LoggingTypeHexString
public static final int LoggingTypeHexStringLogging type constant for hex-dump-style logging. If used, data will be logged as pairs of two-digit hexadecimal digits, e.g. "Hello\n" as 48 65 62 62 6F 0A.- See Also:
- Constant Field Values
-
LoggingTypeEscapeString
public static final int LoggingTypeEscapeStringLogging type constant for excape-string style logging. If used, 7-bit ASCII letters will be logged "as is", while all other values will be logged as 3-letter octal triples with leading backslash. The backslash will be duplicated, e.g. "Hello\n" as Hello\012- See Also:
- Constant Field Values
-
LoggingTypeNoLogging
public static final int LoggingTypeNoLoggingLogging type constant for no data logging. Data will be replaced by ...- See Also:
- Constant Field Values
-
Dev
Device used for logging -
LoggingData
public byte[] LoggingDataBuffer with data to be logged in case of normal processing. In case of exceptional processing, specific messages must be generated by classes.
-
-
Constructor Details
-
UniqueIOProcessor
Stores JposDevice and port of derived IO processors. The device will be used for logging while the port specifies the communication object.- Parameters:
dev
- Device that uses the processor. Processor uses logging of device to produce logging entriesport
- Communication object, e.g. COM3 or 127.0.0.1:23456- Throws:
jpos.JposException
- If port does not specify a valid communication object
-
-
Method Details
-
getSource
Gets source of previously read data.- Returns:
- Data source, null before data have been read
-
getTarget
Retrieves currently set target for writing data.- Returns:
- Current target device, null if target has not been specified.
-
setTarget
Sets communication target. Depending on the IO processor type, setting communication target can be mandatory before calling method open.- Parameters:
target
- communication target- Returns:
- target
- Throws:
jpos.JposException
- if target is not a valid communication target.
-
setTimeout
public int setTimeout(int timeout)Sets read timeout- Parameters:
timeout
- Timeout in milliseconds- Returns:
- timeout
-
setLoggingType
public int setLoggingType(int type)Sets the logging type for data logging.- Parameters:
type
- One of the LoggingType constants.- Returns:
- type
-
toLogString
Generate log string from byte buffer- Parameters:
buffer
- byte array containing input or output data- Returns:
- String corresponding to previously specified logging type
-
write
public int write(byte[] buffer) throws jpos.JposExceptionWrite a frame to the communication target. If called from a derived class, the byte array must be passed through unchanged for correct logging.- 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.JposExceptionRetrieves no. of readable units from communication source. If called from a derived class, LoggingData must be filled with the count to be returned.- Returns:
- Unit count
- Throws:
jpos.JposException
- if something goes wrong
-
read
public byte[] read(int count) throws jpos.JposExceptionReads 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.- 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
-
location
Generates string to be inserted into logging message whenever the source or target port does not match the initial port.- Parameters:
from
- True in case of reading date, false in case of writing data.- Returns:
- enpty string if current port matches initial port, " from getSource()" or " to getTarget()" otherwise.
-
flush
public void flush() throws jpos.JposExceptionEmpties input and output buffer- Throws:
jpos.JposException
- Iif something goes wrong
-
open
public void open(boolean noErrorLog) throws jpos.JposExceptionOpens processor for communication to specific source / target. Communication parameters must be set previously by specific setup method(s).- 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.JposExceptionFinished any communication.- Specified by:
close
in interfaceAutoCloseable
- Throws:
jpos.JposException
- If an IO error occurs
-
logerror
Generate a logging error message and throw the corresponding JposException.- Parameters:
what
- Describes witch operation falied (e.g. "Read", "Available"...)error
- The Jpos error constantwhy
- The error message.- Returns:
- Function never returns, it throws an exception always.
- Throws:
jpos.JposException
- The exception. Its message will be set to why.
-
logerror
Generate a logging error message and throw an JposException.- Parameters:
what
- Describes witch operation falied (e.g. "Read", "Available"...)error
- The Jpos error constantex
- JposException that lead to the error.- Returns:
- Function never returns, it throws an exception always.
- Throws:
jpos.JposException
- The exception. Its message will be set to ex.getMessage().
-
logerror
Generate a logging error message and throw an JposException.- Parameters:
what
- Describes witch operation falied (e.g. "Read", "Available"...)ex
- JposException that lead to the error.- Returns:
- Function never returns, it throws an exception always.
- Throws:
jpos.JposException
- The exception. Its message will be set to ex.getMessage().
-