org.zeromq
Class ZFrame

java.lang.Object
  extended by 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. Based on zframe.c in czmq

Author:
rsmith (at) rsbatechnology (dot) co (dot) uk

Field Summary
static int DONTWAIT
           
static int MORE
           
static int REUSE
           
 
Constructor Summary
protected ZFrame()
          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
 void destroy()
          Destructor.
 ZFrame duplicate()
          Creates a new frame that duplicates an existing frame
 boolean equals(Object o)
           
 byte[] getData()
           
 boolean hasData()
          Convenience method to ascertain if this frame contains some message data
 int hashCode()
           
 boolean hasMore()
           
 boolean hasSameData(ZFrame other)
          Returns true if both frames have byte - for byte identical data
 void print(String prefix)
           
static ZFrame recvFrame(ZMQ.Socket socket)
          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)
          Method to call org.zeromq.Socket send() method.
 boolean sendAndDestroy(ZMQ.Socket socket)
          Sends frame to socket if it contains data.
 boolean sendAndDestroy(ZMQ.Socket socket, int flags)
          Sends frame to socket if it contains data.
 boolean sendAndKeep(ZMQ.Socket socket)
          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 size()
          Returns byte size of frame, if set, else 0
 boolean streq(String str)
          String equals.
 String strhex()
          Returns frame data as a printable hex string
 String toString()
          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 Detail

MORE

public static final int MORE
See Also:
Constant Field Values

REUSE

public static final int REUSE
See Also:
Constant Field Values

DONTWAIT

public static final int DONTWAIT
See Also:
Constant Field Values
Constructor Detail

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 -
Method Detail

destroy

public void destroy()
Destructor.


getData

public byte[] getData()
Returns:
the data

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)
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(byte[] data)
Sets new contents for frame

Parameters:
data - New byte array contents for frame

reset

public void reset(String data)
Sets new contents for frame

Parameters:
data - String contents for frame

strhex

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

Returns:

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

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)


Copyright © 2013. All Rights Reserved.