Package org.zeromq

Class ZMQ.Context

java.lang.Object
org.zeromq.ZMQ.Context
All Implemented Interfaces:
Closeable, AutoCloseable
Enclosing class:
ZMQ

public static class ZMQ.Context extends Object implements 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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final AtomicBoolean
     
    private final Ctx
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Context(int ioThreads)
    Class constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Destroys the ØMQ context context.
    boolean
    close(Selector selector)
    Closes a Selector that was created within this context.
    boolean
    Deprecated.
    use isBlocky() instead
    int
    The size of the 0MQ thread pool to handle I/O operations.
    boolean
     
    int
    The maximum number of sockets allowed on the context
    boolean
     
    boolean
     
    boolean
     
    boolean
    Returns true if terminate() has been called on ctx.
    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.
    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 context
    socket(int type)
    Deprecated.
    Creates a ØMQ socket within the specified context and return an opaque handle to the newly created socket.
    void
    This is an explicit "destructor".

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 public boolean getBlocky()
      Deprecated.
      use isBlocky() 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

      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 with ZMQ.Socket.connect(String), or at least one endpoint must be created for accepting incoming connections with ZMQ.Socket.bind(String).
      Parameters:
      type - the socket type.
      Returns:
      the newly created Socket.
    • socket

      @Deprecated public ZMQ.Socket socket(int type)
      Deprecated.
    • selector

      public Selector selector()
      Create a new Selector within this context.
      Returns:
      the newly created Selector.
    • close

      public boolean close(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 with ZMQ.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 with ZMQ.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:

      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 interface AutoCloseable
      Specified by:
      close in interface Closeable