Package zmq

Class Ctx


public class Ctx extends Object
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.
  • Field Details

  • Constructor Details

    • Ctx

      public Ctx()
  • Method Details

    • destroy

      private void destroy() throws IOException
      Throws:
      IOException
    • isActive

      public boolean isActive()
      Returns:
      false if terminate()terminate() has been called.
    • checkTag

      @Deprecated public boolean checkTag()
      Deprecated.
      use isActive() instead
      Returns:
      false if terminate()terminate() has been called.
    • terminate

      public void terminate()
    • shutdown

      final void shutdown()
    • chechStarted

      private void chechStarted()
    • setUncaughtExceptionHandler

      public void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler handler)
      Set the handler invoked when a Poller abruptly terminates due to an uncaught exception. It defaults 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 and will use the one defined for the ThreadGroup.
      Throws:
      IllegalStateException - If context was already initialized by the creation of a socket
    • getUncaughtExceptionHandler

      public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
      Returns:
      The handler invoked when a Poller abruptly terminates due to an uncaught exception.
    • setNotificationExceptionHandler

      public void setNotificationExceptionHandler(Thread.UncaughtExceptionHandler handler)
      In Poller.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

      public Thread.UncaughtExceptionHandler getNotificationExceptionHandler()
      Returns:
      The handler invoked when a non-fatal exceptions is thrown in zmq.poll.Poller#run()
    • setThreadFactory

      public void setThreadFactory(BiFunction<Runnable,String,Thread> threadFactory)
      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 by Poller
      Throws:
      IllegalStateException - If context was already initialized by the creation of a socket
    • getThreadFactory

      public BiFunction<Runnable,String,Thread> getThreadFactory()
      Returns:
      the current thread factory
    • set

      public boolean set(int option, int optval)
      Set an option
      Parameters:
      option - the option to set
      optval - 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

      public SocketBase createSocket(int type)
    • initSlots

      private void initSlots()
    • destroySocket

      void destroySocket(SocketBase socket)
    • createSelector

      public Selector createSelector()
    • closeSelector

      public boolean closeSelector(Selector selector)
    • getReaper

      ZObject getReaper()
    • sendCommand

      void sendCommand(int tid, Command command)
    • chooseIoThread

      IOThread chooseIoThread(long affinity)
    • registerEndpoint

      boolean registerEndpoint(String addr, Ctx.Endpoint endpoint)
    • unregisterEndpoint

      boolean unregisterEndpoint(String addr, SocketBase socket)
    • unregisterEndpoints

      void unregisterEndpoints(SocketBase socket)
    • findEndpoint

      Ctx.Endpoint findEndpoint(String addr)
    • pendConnection

      void pendConnection(String addr, Ctx.Endpoint endpoint, Pipe[] pipes)
    • connectPending

      void connectPending(String addr, SocketBase bindSocket)
    • connectInprocSockets

      private void connectInprocSockets(SocketBase bindSocket, Options bindOptions, Ctx.PendingConnection pendingConnection, Ctx.Side side)
    • errno

      public Errno errno()
    • forwardChannel

      int forwardChannel(SelectableChannel channel)
      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

      SelectableChannel getForwardedChannel(Integer handle)
      Retrieve a channel, using the handle returned by forwardChannel(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

      private Thread createThread(Runnable target, String name)