Package org.zeromq
Class ZContext
java.lang.Object
org.zeromq.ZContext
- All Implemented Interfaces:
Closeable
,AutoCloseable
ZContext provides a high-level ZeroMQ context management class
The ZContext class wraps java org.zeromq.Context objects, which in turn wrap native 0MQ contexts. It manages open
sockets in the context and automatically closes these before terminating the context. It provides a simple way to set
the linger timeout on sockets, and configure contexts for number of I/O threads. Sets-up signal (interrupt) handling
for the process.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
createSocket
(int type) Creates a new managed socket within this ZContext instance.void
destroy()
Destructor.void
Destroys managed socket within this context and remove from sockets listint
int
boolean
isMain()
void
setContext
(ZMQ.Context ctx) void
setIoThreads
(int ioThreads) void
setLinger
(int linger) void
setMain
(boolean main) static ZContext
Creates new shadow context.
-
Constructor Details
-
ZContext
public ZContext()Class Constructor
-
-
Method Details
-
destroy
public void destroy()Destructor. Call this to gracefully terminate context and close any managed 0MQ sockets -
createSocket
Creates a new managed socket within this ZContext instance. Use this to get automatic management of the socket at shutdown- Parameters:
type
- socket type (see ZMQ static class members)- Returns:
- Newly created Socket object
-
destroySocket
Destroys managed socket within this context and remove from sockets list- Parameters:
s
- org.zeromq.Socket object to destroy
-
shadow
Creates new shadow context. Shares same underlying org.zeromq.Context instance but has own list of managed sockets, io thread count etc.- Parameters:
ctx
- Original ZContext to create shadow of- Returns:
- New ZContext
-
getIoThreads
public int getIoThreads()- Returns:
- the ioThreads
-
setIoThreads
public void setIoThreads(int ioThreads) - Parameters:
ioThreads
- the ioThreads to set
-
getLinger
public int getLinger()- Returns:
- the linger
-
setLinger
public void setLinger(int linger) - Parameters:
linger
- the linger to set
-
isMain
public boolean isMain()- Returns:
- the main
-
setMain
public void setMain(boolean main) - Parameters:
main
- the main to set
-
getContext
- Returns:
- the context
-
setContext
- Parameters:
ctx
- sets the underlying org.zeromq.Context associated with this ZContext wrapper object
-
getSockets
- Returns:
- the sockets
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-