Package org.zeromq
Class ZFrame
java.lang.Object
org.zeromq.ZFrame
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Destructor.Creates a new frame that duplicates an existing frameboolean
byte[]
getData()
getGroup()
Gets the group used for RADIO/DISH sockets.int
Return frame routing ID, if the frame came from a ZMQ_SERVER socket.boolean
hasData()
Convenience method to ascertain if this frame contains some message dataint
hashCode()
boolean
hasMore()
boolean
hasSameData
(ZFrame other) Returns true if both frames have byte - for byte identical datavoid
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 framevoid
Sets new contents for frameboolean
send
(ZMQ.Socket socket, int flags) Internal 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.void
Sets the group used for RADIO/DISH sockets.void
setRoutingId
(int routingId) Set routing ID on frame.int
size()
Returns byte size of frame, if set, else 0boolean
String equals.strhex()
toString()
Returns a human - readable representation of frame's data
-
Field Details
-
MORE
public static final int MORE- See Also:
-
REUSE
public static final int REUSE- See Also:
-
DONTWAIT
public static final int DONTWAIT- See Also:
-
more
private boolean more -
data
private byte[] data -
routingId
private int routingId -
group
-
-
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
Class Constructor Copies String into frame data- Parameters:
data
- String to copy into ZFrame object as bytes, decoded usingZMQ.CHARSET
-
ZFrame
Class Constructor Uses internal Msg class to access routingId- Parameters:
msg
- internal Msg class to copy into Zframe
-
-
Method Details
-
getRoutingId
public int getRoutingId()Return frame routing ID, if the frame came from a ZMQ_SERVER socket. Else returns zero.- Returns:
- the routing ID
-
setRoutingId
public void setRoutingId(int routingId) Set routing ID on frame. This is used if/when the frame is sent to a ZMQ_SERVER socket.- Parameters:
routingId
- the routing ID
-
getGroup
Gets the group used for RADIO/DISH sockets.- Returns:
- the group name, or null.
-
setGroup
Sets the group used for RADIO/DISH sockets.- Parameters:
group
- the group name, or null to unset it.
-
destroy
public void destroy()Destructor. -
getData
public byte[] getData()- Returns:
- the data
-
getString
-
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
Internal method to call org.zeromq.Socket send() method.- Parameters:
socket
- 0MQ socket to send onflags
- Valid send() method flags, defined in org.zeromq.ZMQ class- Returns:
- True if success, else False
-
sendAndKeep
Sends frame to socket if it contains any data. Frame contents are kept after the send.- Parameters:
socket
- 0MQ socket to send frameflags
- Valid send() method flags, defined in org.zeromq.ZMQ class- Returns:
- True if success, else False
-
sendAndKeep
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
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 frameflags
- Valid send() method flags, defined in org.zeromq.ZMQ class- Returns:
- True if success, else False
-
sendAndDestroy
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
Creates a new frame that duplicates an existing frame- Returns:
- Duplicate of frame; message contents copied into new byte array
-
hasSameData
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
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
- Returns:
- frame data as a printable hex string
-
streq
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
-
hashCode
public int hashCode() -
toString
Returns a human - readable representation of frame's data -
recvFrame
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
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 fromflags
- Pass flags to 0MQ socket.recv call- Returns:
- received frame, else null
-
print
-