public class ZContext
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Field and Description |
---|---|
private ZMQ.Context |
context
Reference to underlying Context object
|
private int |
ioThreads
Number of io threads allocated to this context, default 1
|
private int |
linger
Linger timeout, default 0
|
private boolean |
main
Indicates if context object is owned by main thread
(useful for multi-threaded applications)
|
private int |
pipehwm
Send/receive HWM for pipes
|
private int |
rcvhwm
ZMQ_RCVHWM for normal sockets
|
private java.util.Set<java.nio.channels.Selector> |
selectors
List of selectors managed by this ZContext
|
private java.util.Set<ZContext> |
shadows
List of ZContext in the shadows
|
private int |
sndhwm
ZMQ_SNDHWM for normal sockets
|
private java.util.Set<ZMQ.Socket> |
sockets
List of sockets managed by this ZContext
|
Modifier | Constructor and Description |
---|---|
|
ZContext()
Class Constructor
|
|
ZContext(int ioThreads) |
private |
ZContext(ZContext parent,
int ioThreads) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
closeSelector(java.nio.channels.Selector selector)
Deprecated.
createSelector() was exposed by mistake. while waiting for the API to disappear, this method is provided to allow releasing resources. |
(package private) void |
closeSocket(ZMQ.Socket s)
Close managed socket within this context and remove from sockets list.
|
ZMQ.Poller |
createPoller(int size) |
java.nio.channels.Selector |
createSelector()
Deprecated.
this was exposed by mistake.
|
ZMQ.Socket |
createSocket(int type)
Deprecated.
|
ZMQ.Socket |
createSocket(SocketType type)
Creates a new managed socket within this ZContext instance.
|
void |
destroy()
Destructor.
|
void |
destroySocket(ZMQ.Socket s)
Deprecated.
Not to be used any more.
ZMQ.Socket handle
the close itself. It also override linger settings. |
ZMQ.Socket |
fork(ZThread.IAttachedRunnable runnable,
java.lang.Object... args)
Create an attached thread, An attached thread gets a ctx and a PAIR pipe back to its
parent.
|
ZMQ.Context |
getContext() |
int |
getIoThreads() |
int |
getLinger() |
java.lang.Thread.UncaughtExceptionHandler |
getNotificationExceptionHandler() |
java.util.List<ZMQ.Socket> |
getSockets()
Return a copy of the list of currently open sockets.
|
java.lang.Thread.UncaughtExceptionHandler |
getUncaughtExceptionHandler() |
boolean |
isClosed() |
boolean |
isEmpty() |
boolean |
isMain() |
(package private) java.nio.channels.Selector |
selector()
Creates a selector.
|
void |
setContext(ZMQ.Context ctx)
Deprecated.
This value should not be changed after the ZContext is initialized.
|
void |
setIoThreads(int ioThreads)
Deprecated.
This value should not be changed after the context is initialized.
|
void |
setLinger(int linger) |
void |
setMain(boolean main)
Deprecated.
This value should not be changed after the context is initialized.
|
void |
setNotificationExceptionHandler(java.lang.Thread.UncaughtExceptionHandler handler)
In
Poller.run() , some non-fatal exceptions can be thrown. |
void |
setRcvHWM(int rcvhwm)
Set initial receive HWM for all new normal sockets created in context.
|
void |
setSndHWM(int sndhwm)
Set initial receive HWM for all new normal sockets created in context.
|
void |
setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler handler)
Set the handler invoked when a
Poller abruptly terminates due to an uncaught exception. |
ZContext |
shadow()
Creates new shadow context.
|
static ZContext |
shadow(ZContext ctx)
Deprecated.
use the instance method directly
|
private final ZMQ.Context context
private final java.util.Set<ZMQ.Socket> sockets
private final java.util.Set<java.nio.channels.Selector> selectors
private final java.util.Set<ZContext> shadows
private final int ioThreads
private final boolean main
private volatile int linger
private int pipehwm
private volatile int sndhwm
private volatile int rcvhwm
public ZContext()
public ZContext(int ioThreads)
private ZContext(ZContext parent, int ioThreads)
public void destroy()
public ZMQ.Socket createSocket(SocketType type)
The newly created socket will inherited it's linger value from the one defined for this context.
type
- socket type@Deprecated public ZMQ.Socket createSocket(int type)
createSocket(SocketType)
type
- socket type (see ZMQ static class members)@Deprecated public void destroySocket(ZMQ.Socket s)
ZMQ.Socket
handle
the close itself. It also override linger settings.s
- ZMQ.Socket
object to destroyvoid closeSocket(ZMQ.Socket s)
ZMQ.Socket
created by
this context will call it on termination.s
- ZMQ.Socket
object to destroy@Deprecated public java.nio.channels.Selector createSelector()
closeSelector(Selector)
.java.nio.channels.Selector selector()
@Deprecated public void closeSelector(java.nio.channels.Selector selector)
createSelector()
was exposed by mistake. while waiting for the API to disappear, this method is provided to allow releasing resources.selector
- the selector to close. It needs to have been created by createSelector()
.public ZMQ.Poller createPoller(int size)
@Deprecated public static ZContext shadow(ZContext ctx)
ctx
- Original ZContext to create shadow ofpublic ZContext shadow()
public ZMQ.Socket fork(ZThread.IAttachedRunnable runnable, java.lang.Object... args)
runnable
- attached threadargs
- forked runnable argspublic int getIoThreads()
@Deprecated public void setIoThreads(int ioThreads)
ioThreads
- the number of ioThreads to setpublic int getLinger()
public void setLinger(int linger)
linger
- the linger that will inherited by created socket.public void setRcvHWM(int rcvhwm)
rcvhwm
- the rcvhwmpublic void setSndHWM(int sndhwm)
sndhwm
- the sndhwmpublic void setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler handler)
Poller
abruptly terminates due to an uncaught exception.
It default to the value of Thread.getDefaultUncaughtExceptionHandler()
handler
- The object to use as this thread's uncaught exception handler. If null then this thread has no explicit handler.public java.lang.Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
Poller
abruptly terminates due to an uncaught exception.public void setNotificationExceptionHandler(java.lang.Thread.UncaughtExceptionHandler handler)
Poller.run()
, some non-fatal exceptions can be thrown. This handler will be notified, so they can
be logged.
Default to Throwable.printStackTrace()
handler
- The object to use as this thread's handler for recoverable exceptions notifications.public java.lang.Thread.UncaughtExceptionHandler getNotificationExceptionHandler()
public boolean isMain()
public boolean isEmpty()
@Deprecated public void setMain(boolean main)
main
- whether or not the context is being set to mainpublic ZMQ.Context getContext()
@Deprecated public void setContext(ZMQ.Context ctx)
ctx
- sets the underlying zmq.Context associated with this ZContext wrapper objectpublic java.util.List<ZMQ.Socket> getSockets()
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public boolean isClosed()