Package org.zeromq

Class ZFrame

java.lang.Object
org.zeromq.ZFrame

public class ZFrame extends Object
ZFrame The ZFrame class provides methods to send and receive single message frames across 0MQ sockets. A 'frame' corresponds to one underlying zmq_msg_t in the libzmq code. When you read a frame from a socket, the more() method indicates if the frame is part of an unfinished multipart message. The send() method normally destroys the frame, but with the ZFRAME_REUSE flag, you can send the same frame many times. Frames are binary, and this class has no special support for text data.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private byte[]
     
    static final int
     
    private boolean
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Class Constructor Creates an empty frame.
     
    ZFrame(byte[] data)
    Class Constructor Copies message data into ZFrame object
     
    ZFrame(String data)
    Class Constructor Copies String into frame data
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Destructor.
    Creates a new frame that duplicates an existing frame
    boolean
     
    byte[]
     
    getString(Charset charset)
     
    boolean
    Convenience method to ascertain if this frame contains some message data
    int
     
    boolean
     
    boolean
    Returns true if both frames have byte - for byte identical data
    void
    print(String prefix)
     
    private byte[]
    recv(ZMQ.Socket socket, int flags)
    Internal method to call recv on the socket.
    static ZFrame
    Receives single frame from socket, returns the received frame object, or null if the recv was interrupted.
    static ZFrame
    recvFrame(ZMQ.Socket socket, int flags)
    Receive a new frame off the socket, Returns newly-allocated frame, or null if there was no input waiting, or if the read was interrupted.
    void
    reset(byte[] data)
    Sets new contents for frame
    void
    reset(String data)
    Sets new contents for frame
    boolean
    send(ZMQ.Socket socket, int flags)
    Internal method to call org.zeromq.Socket send() method.
    boolean
    Sends frame to socket if it contains data.
    boolean
    sendAndDestroy(ZMQ.Socket socket, int flags)
    Sends frame to socket if it contains data.
    boolean
    Sends frame to socket if it contains any data.
    boolean
    sendAndKeep(ZMQ.Socket socket, int flags)
    Sends frame to socket if it contains any data.
    int
    Returns byte size of frame, if set, else 0
    boolean
    String equals.
     
    Returns a human - readable representation of frame's data

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • ZFrame

      protected ZFrame()
      Class Constructor Creates an empty frame. (Useful when reading frames from a 0MQ Socket)
    • ZFrame

      public ZFrame(byte[] data)
      Class Constructor Copies message data into ZFrame object
      Parameters:
      data - Data to copy into ZFrame object
    • ZFrame

      public ZFrame(String data)
      Class Constructor Copies String into frame data
      Parameters:
      data - String to copy into ZFrame object as bytes, decoded using ZMQ.CHARSET
  • Method Details

    • destroy

      public void destroy()
      Destructor.
    • getData

      public byte[] getData()
      Returns:
      the data
    • getString

      public String getString(Charset charset)
    • hasMore

      public boolean hasMore()
      Returns:
      More flag, true if last read had MORE message parts to come
    • size

      public int size()
      Returns byte size of frame, if set, else 0
      Returns:
      Number of bytes in frame data, else 0
    • hasData

      public boolean hasData()
      Convenience method to ascertain if this frame contains some message data
      Returns:
      True if frame contains data
    • send

      public boolean send(ZMQ.Socket socket, int flags)
      Internal method to call org.zeromq.Socket send() method.
      Parameters:
      socket - 0MQ socket to send on
      flags - Valid send() method flags, defined in org.zeromq.ZMQ class
      Returns:
      True if success, else False
    • sendAndKeep

      public boolean sendAndKeep(ZMQ.Socket socket, int flags)
      Sends frame to socket if it contains any data. Frame contents are kept after the send.
      Parameters:
      socket - 0MQ socket to send frame
      flags - Valid send() method flags, defined in org.zeromq.ZMQ class
      Returns:
      True if success, else False
    • sendAndKeep

      public boolean sendAndKeep(ZMQ.Socket socket)
      Sends frame to socket if it contains any data. Frame contents are kept after the send. Uses default behaviour of Socket.send() method, with no flags set
      Parameters:
      socket - 0MQ socket to send frame
      Returns:
      True if success, else False
    • sendAndDestroy

      public boolean sendAndDestroy(ZMQ.Socket socket, int flags)
      Sends frame to socket if it contains data. Use this method to send a frame and destroy the data after.
      Parameters:
      socket - 0MQ socket to send frame
      flags - Valid send() method flags, defined in org.zeromq.ZMQ class
      Returns:
      True if success, else False
    • sendAndDestroy

      public boolean sendAndDestroy(ZMQ.Socket socket)
      Sends frame to socket if it contains data. Use this method to send an isolated frame and destroy the data after. Uses default behaviour of Socket.send() method, with no flags set
      Parameters:
      socket - 0MQ socket to send frame
      Returns:
      True if success, else False
    • duplicate

      public ZFrame duplicate()
      Creates a new frame that duplicates an existing frame
      Returns:
      Duplicate of frame; message contents copied into new byte array
    • hasSameData

      public boolean hasSameData(ZFrame other)
      Returns true if both frames have byte - for byte identical data
      Parameters:
      other - The other ZFrame to compare
      Returns:
      True if both ZFrames have same byte-identical data, else false
    • reset

      public void reset(String data)
      Sets new contents for frame
      Parameters:
      data - New byte array contents for frame
    • reset

      public void reset(byte[] data)
      Sets new contents for frame
      Parameters:
      data - New byte array contents for frame
    • strhex

      public String strhex()
      Returns:
      frame data as a printable hex string
    • streq

      public boolean streq(String str)
      String equals. Uses String compareTo for the comparison (lexigraphical)
      Parameters:
      str - String to compare with frame data
      Returns:
      True if frame body data matches given string
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a human - readable representation of frame's data
      Overrides:
      toString in class Object
      Returns:
      A text string or hex-encoded string if data contains any non-printable ASCII characters
    • recv

      private byte[] recv(ZMQ.Socket socket, int flags)
      Internal method to call recv on the socket. Does not trap any ZMQExceptions but expects caling routine to handle them.
      Parameters:
      socket - 0MQ socket to read from
      Returns:
      byte[] data
    • recvFrame

      public static ZFrame recvFrame(ZMQ.Socket socket)
      Receives single frame from socket, returns the received frame object, or null if the recv was interrupted. Does a blocking recv, if you want to not block then use recvFrame(socket, ZMQ.DONTWAIT);
      Parameters:
      socket - Socket to read from
      Returns:
      received frame, else null
    • recvFrame

      public static ZFrame recvFrame(ZMQ.Socket socket, int flags)
      Receive a new frame off the socket, Returns newly-allocated frame, or null if there was no input waiting, or if the read was interrupted.
      Parameters:
      socket - Socket to read from
      flags - Pass flags to 0MQ socket.recv call
      Returns:
      received frame, else null
    • print

      public void print(String prefix)