Package org.zeromq
Class ZMQ.Context
- java.lang.Object
-
- org.zeromq.ZMQ.Context
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Enclosing class:
- ZMQ
public static class ZMQ.Context extends java.lang.Object implements java.io.Closeable
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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Context(int ioThreads)
Class constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
Destroys the ØMQ context context.boolean
close(java.nio.channels.Selector selector)
Closes a Selector that was created within this context.boolean
getBlocky()
Deprecated.useisBlocky()
insteadint
getIOThreads()
The size of the 0MQ thread pool to handle I/O operations.boolean
getIPv6()
int
getMaxSockets()
The maximum number of sockets allowed on the contextjava.lang.Thread.UncaughtExceptionHandler
getNotificationExceptionHandler()
java.lang.Thread.UncaughtExceptionHandler
getUncaughtExceptionHandler()
boolean
isBlocky()
boolean
isClosed()
boolean
isIPv6()
boolean
isTerminated()
Returns true if terminate() has been called on ctx.ZMQ.Poller
poller()
Create a new Poller within this context, with a default size.ZMQ.Poller
poller(int size)
Create a new Poller within this context, with a specified initial size.java.nio.channels.Selector
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 contextvoid
setNotificationExceptionHandler(java.lang.Thread.UncaughtExceptionHandler handler)
InPoller.run()
, some non-fatal exceptions can be thrown.void
setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler handler)
Set the handler invoked when aPoller
abruptly terminates due to an uncaught exception.ZMQ.Socket
socket(int type)
Deprecated.ZMQ.Socket
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 Detail
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
ctx
private final Ctx ctx
-
-
Method Detail
-
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 public boolean 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)
-
setUncaughtExceptionHandler
public void setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler handler)
Set the handler invoked when aPoller
abruptly terminates due to an uncaught exception.It default to the value of
Thread.getDefaultUncaughtExceptionHandler()
- Parameters:
handler
- The object to use as this thread's uncaught exception handler. If null then this thread has no explicit handler.
-
getUncaughtExceptionHandler
public java.lang.Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
- Returns:
- The handler invoked when a
Poller
abruptly terminates due to an uncaught exception.
-
setNotificationExceptionHandler
public void setNotificationExceptionHandler(java.lang.Thread.UncaughtExceptionHandler handler)
InPoller.run()
, some non-fatal exceptions can be thrown. This handler will be notified, so they can be logged.Default to
Throwable.printStackTrace()
- Parameters:
handler
- The object to use as this thread's handler for recoverable exceptions notifications.
-
getNotificationExceptionHandler
public java.lang.Thread.UncaughtExceptionHandler getNotificationExceptionHandler()
- Returns:
- The handler invoked when a non-fatal exceptions is thrown in zmq.poll.Poller#run()
-
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
public ZMQ.Socket socket(SocketType type)
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 public ZMQ.Socket socket(int type)
Deprecated.
-
selector
public java.nio.channels.Selector selector()
Create a new Selector within this context.- Returns:
- the newly created Selector.
-
close
public boolean close(java.nio.channels.Selector selector)
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
public ZMQ.Poller 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
public ZMQ.Poller poller(int size)
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
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Any blocking operations currently in progress on sockets open within context
shall return immediately with an error code of ETERM.
With the exception of
-
-