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

public class TcpClientIOProcessor extends UniqueIOProcessor
Class to process TCP client communication. Includes functionality for automatic data logging. Implementation is based on Java class Socket.
  • Constructor Details

    • TcpClientIOProcessor

      public TcpClientIOProcessor(JposDevice dev, String addr) throws jpos.JposException
      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 entries
      addr - 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.JposException
      Sets 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.JposException
      Sets TCP specific communication parameter.
      Parameters:
      ownport - Own port address
      connectTimeout - Connect timeout in milliseconds. Must be > 0
      Throws:
      jpos.JposException - If port address < 0 or port address > 65535
    • setTarget

      public String setTarget(String target) throws jpos.JposException
      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 class UniqueIOProcessor
      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.JposException
      Description 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 class UniqueIOProcessor
      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.JposException
      Description 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 class UniqueIOProcessor
      Returns:
      Unit count
      Throws:
      jpos.JposException - if something goes wrong
    • read

      public byte[] read(int count) throws jpos.JposException
      Description 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 class UniqueIOProcessor
      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.JposException
      Description copied from class: UniqueIOProcessor
      Empties input and output buffer
      Overrides:
      flush in class UniqueIOProcessor
      Throws:
      jpos.JposException - Iif something goes wrong
    • open

      public void open(boolean noErrorLog) throws jpos.JposException
      Description 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 class UniqueIOProcessor
      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.JposException
      Description copied from class: UniqueIOProcessor
      Finished any communication.
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class UniqueIOProcessor
      Throws:
      jpos.JposException - If an IO error occurs