Package org.zeromq
Class ZMQ.Context
java.lang.Object
org.zeromq.ZMQ.Context
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Enclosing class:
- ZMQ
Container for all sockets in a single process,
acting as the transport for inproc sockets,
which are the fastest way to connect threads in one process.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Destroys the ØMQ context context.boolean
Closes a Selector that was created within this context.boolean
Deprecated.int
The size of the 0MQ thread pool to handle I/O operations.boolean
getIPv6()
int
The maximum number of sockets allowed on the contextboolean
isBlocky()
boolean
isClosed()
boolean
isIPv6()
boolean
Returns true if terminate() has been called on ctx.poller()
Create a new Poller within this context, with a default size.poller
(int size) Create a new Poller within this context, with a specified initial size.selector()
Create a new Selector within this context.boolean
setBlocky
(boolean block) boolean
setIOThreads
(int ioThreads) Set the size of the 0MQ thread pool to handle I/O operations.boolean
setIPv6
(boolean ipv6) boolean
setMaxSockets
(int maxSockets) Sets the maximum number of sockets allowed on the contextsocket
(int type) Deprecated.socket
(SocketType type) Creates a ØMQ socket within the specified context and return an opaque handle to the newly created socket.void
term()
This is an explicit "destructor".
-
Field Details
-
closed
-
ctx
-
-
Constructor Details
-
Context
protected Context(int ioThreads) Class constructor.- Parameters:
ioThreads
- size of the threads pool to handle I/O operations.
-
-
Method Details
-
isTerminated
public boolean isTerminated()Returns true if terminate() has been called on ctx. -
getIOThreads
public int getIOThreads()The size of the 0MQ thread pool to handle I/O operations. -
setIOThreads
public boolean setIOThreads(int ioThreads) Set the size of the 0MQ thread pool to handle I/O operations. -
getMaxSockets
public int getMaxSockets()The maximum number of sockets allowed on the context -
setMaxSockets
public boolean setMaxSockets(int maxSockets) Sets the maximum number of sockets allowed on the context -
getBlocky
Deprecated.useisBlocky()
instead -
isBlocky
public boolean isBlocky() -
setBlocky
public boolean setBlocky(boolean block) -
isIPv6
public boolean isIPv6() -
getIPv6
public boolean getIPv6() -
setIPv6
public boolean setIPv6(boolean ipv6) -
term
public void term()This is an explicit "destructor". It can be called to ensure the corresponding 0MQ Context has been disposed of. -
isClosed
public boolean isClosed() -
socket
Creates a ØMQ socket within the specified context and return an opaque handle to the newly created socket.
The type argument specifies the socket type, which determines the semantics of communication over the socket.
The newly created socket is initially unbound, and not associated with any endpoints.
In order to establish a message flow a socket must first be connected to at least one endpoint withZMQ.Socket.connect(String)
, or at least one endpoint must be created for accepting incoming connections withZMQ.Socket.bind(String)
.- Parameters:
type
- the socket type.- Returns:
- the newly created Socket.
-
socket
Deprecated. -
selector
Create a new Selector within this context.- Returns:
- the newly created Selector.
-
close
Closes a Selector that was created within this context.- Parameters:
selector
- the Selector to close.- Returns:
- true if the selector was closed. otherwise false (mostly because it was not created by the context).
-
poller
Create a new Poller within this context, with a default size. DO NOT FORGET TO CLOSE THE POLLER AFTER USE withZMQ.Poller.close()
- Returns:
- the newly created Poller.
-
poller
Create a new Poller within this context, with a specified initial size. DO NOT FORGET TO CLOSE THE POLLER AFTER USE withZMQ.Poller.close()
- Parameters:
size
- the poller initial size.- Returns:
- the newly created Poller.
-
close
public void close()Destroys the ØMQ context context. Context termination is performed in the following steps:- Any blocking operations currently in progress on sockets open within context
shall return immediately with an error code of ETERM.
With the exception of
ZMQ.Socket.close()
, any further operations on sockets open within context shall fail with an error code of ETERM. - After interrupting all blocking calls, this method shall block until the following conditions are satisfied:
- All sockets open within context have been closed with
ZMQ.Socket.close()
. - For each socket within context, all messages sent by the application with
ZMQ.Socket.send(java.lang.String)
have either been physically transferred to a network peer, or the socket's linger period set with theZMQ.Socket.setLinger(int)
socket option has expired.
- All sockets open within context have been closed with
Warning
As ZMQ_LINGER defaults to "infinite", by default this method will block indefinitely if there are any pending connects or sends. We strongly recommend to- set ZMQ_LINGER to zero on all sockets
- close all sockets, before calling this method
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Any blocking operations currently in progress on sockets open within context
shall return immediately with an error code of ETERM.
With the exception of
-
isBlocky()
instead