Package zmq
Class Ctx
java.lang.Object
zmq.Ctx
Context object encapsulates all the global state associated with
the library.
It creates a reaper thread and some IO threads as defined by
ZMQ.ZMQ_IO_THREADS. The thread are created
using a thread factory that defined the UncaughtExceptionHandler as defined by setUncaughtExceptionHandler(UncaughtExceptionHandler)
and defined the thread as a daemon. If a custom thread factory is defined with setThreadFactory(BiFunction),
all that steps must be handled manually.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA class that holds the informations needed to forward channel in monitor sockets.static classprivate static classprivate static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate final Map<String, Ctx.Endpoint> private final Lockprivate final Errnoprivate Thread.UncaughtExceptionHandlerprivate Thread.UncaughtExceptionHandlerprivate Ctx.ChannelForwardHolderprivate intprivate booleanprivate static final AtomicIntegerprivate intprivate final Lockprivate final MultiMap<String, Ctx.PendingConnection> private Reaperprivate static final intprivate final Lockprivate intprivate IMailbox[]private final Lockprivate final List<SocketBase> private final AtomicBoolean(package private) static final intprivate booleanprivate final Mailboxprivate BiFunction<Runnable, String, Thread> private static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidbooleancheckTag()Deprecated.(package private) IOThreadchooseIoThread(long affinity) private voidClean all empty referencesbooleancloseSelector(Selector selector) private voidconnectInprocSockets(SocketBase bindSocket, Options bindOptions, Ctx.PendingConnection pendingConnection, Ctx.Side side) (package private) voidconnectPending(String addr, SocketBase bindSocket) createSocket(int type) private ThreadcreateThread(Runnable target, String name) private voiddestroy()(package private) voiddestroySocket(SocketBase socket) errno()(package private) Ctx.EndpointfindEndpoint(String addr) (package private) intforwardChannel(SelectableChannel channel) Forward a channel in a monitor socket.intget(int option) (package private) SelectableChannelgetForwardedChannel(Integer handle) Retrieve a channel, using the handle returned byforwardChannel(SelectableChannel).(package private) ZObjectprivate voidbooleanisActive()(package private) voidpendConnection(String addr, Ctx.Endpoint endpoint, Pipe[] pipes) (package private) booleanregisterEndpoint(String addr, Ctx.Endpoint endpoint) (package private) voidsendCommand(int tid, Command command) booleanset(int option, int optval) Set an optionvoidInPoller.run(), some non-fatal exceptions can be thrown.voidsetThreadFactory(BiFunction<Runnable, String, Thread> threadFactory) Used to define a custom thread factory.voidSet the handler invoked when aPollerabruptly terminates due to an uncaught exception.(package private) final voidshutdown()void(package private) booleanunregisterEndpoint(String addr, SocketBase socket) (package private) voidunregisterEndpoints(SocketBase socket)
-
Field Details
-
WAIT_FOREVER
private static final int WAIT_FOREVER- See Also:
-
active
private boolean active -
sockets
-
emptySlots
-
starting
-
terminating
private volatile boolean terminating -
slotSync
-
selectors
-
reaper
-
ioThreads
-
slotCount
private int slotCount -
slots
-
termMailbox
-
endpoints
-
endpointsSync
-
maxSocketId
-
maxSockets
private int maxSockets -
ioThreadCount
private int ioThreadCount -
threadFactory
-
blocky
private boolean blocky -
optSync
-
selectorSync
-
TERM_TID
static final int TERM_TID- See Also:
-
REAPER_TID
private static final int REAPER_TID- See Also:
-
pendingConnections
-
ipv6
private boolean ipv6 -
errno
-
exhandler
-
exnotification
-
forwardHolder
-
-
Constructor Details
-
Ctx
public Ctx()
-
-
Method Details
-
destroy
- Throws:
IOException
-
isActive
public boolean isActive()- Returns:
- false if
terminate()terminate() has been called.
-
checkTag
Deprecated.useisActive()instead- Returns:
- false if
terminate()terminate() has been called.
-
terminate
public void terminate() -
shutdown
final void shutdown() -
chechStarted
private void chechStarted() -
setUncaughtExceptionHandler
Set the handler invoked when aPollerabruptly terminates due to an uncaught exception. It defaults to the value ofThread.getDefaultUncaughtExceptionHandler()- Parameters:
handler- The object to use as this thread's uncaught exception handler. If null then this thread has no explicit handler and will use the one defined for theThreadGroup.- Throws:
IllegalStateException- If context was already initialized by the creation of a socket
-
getUncaughtExceptionHandler
- Returns:
- The handler invoked when a
Pollerabruptly terminates due to an uncaught exception.
-
setNotificationExceptionHandler
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.- Throws:
IllegalStateException- If context was already initialized by the creation of a socket
-
getNotificationExceptionHandler
- Returns:
- The handler invoked when a non-fatal exceptions is thrown in zmq.poll.Poller#run()
-
setThreadFactory
Used to define a custom thread factory. It can be used to create thread that will be bounded to a CPU for performance or tweaks the created thread. It the UncaughtExceptionHandler is not set, the created thread UncaughtExceptionHandler will not be changed, so the factory can also be used to set it.- Parameters:
threadFactory- the thread factory used byPoller- Throws:
IllegalStateException- If context was already initialized by the creation of a socket
-
getThreadFactory
- Returns:
- the current thread factory
-
set
public boolean set(int option, int optval) Set an option- Parameters:
option- the option to setoptval- the option value- Returns:
- true is the option is allowed for a context and the value is valid for the option
- Throws:
IllegalStateException- If context was already initialized by the creation of a socket, and the option can't be changed.
-
get
public int get(int option) -
createSocket
-
initSlots
private void initSlots() -
destroySocket
-
createSelector
-
closeSelector
-
getReaper
ZObject getReaper() -
sendCommand
-
chooseIoThread
-
registerEndpoint
-
unregisterEndpoint
-
unregisterEndpoints
-
findEndpoint
-
pendConnection
-
connectPending
-
connectInprocSockets
private void connectInprocSockets(SocketBase bindSocket, Options bindOptions, Ctx.PendingConnection pendingConnection, Ctx.Side side) -
errno
-
forwardChannel
Forward a channel in a monitor socket.- Parameters:
channel- a channel to forward- Returns:
- the handle of the channel to be forwarded, used to retrieve it in
getForwardedChannel(Integer)
-
getForwardedChannel
Retrieve a channel, using the handle returned byforwardChannel(SelectableChannel). As WeakReference are used, if the channel was discarded and a GC ran, it will not be found and this method will return null.- Parameters:
handle-- Returns:
-
cleanForwarded
private void cleanForwarded()Clean all empty references -
createThread
-
isActive()instead