Package org.zeromq

Class ZMQ.Poller

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Enclosing class:
    ZMQ

    public static class ZMQ.Poller
    extends java.lang.Object
    implements java.io.Closeable
    Provides a mechanism for applications to multiplex input/output events in a level-triggered fashion over a set of sockets
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private ZMQ.Context context  
      private java.util.List<ZMQ.PollItem> items  
      static int POLLERR
      For standard sockets, this flag is passed through ZMQ.poll(Selector, zmq.poll.PollItem[], long) to the underlying poll() system call and generally means that some sort of error condition is present on the socket specified by fd.
      static int POLLIN
      For ØMQ sockets, at least one message may be received from the socket without blocking.
      static int POLLOUT
      For ØMQ sockets, at least one message may be sent to the socket without blocking.
      private java.nio.channels.Selector selector  
      private static int SIZE_DEFAULT  
      private static int SIZE_INCREMENT  
      private long timeout  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Poller​(ZMQ.Context context)
      Class constructor.
      protected Poller​(ZMQ.Context context, int size)
      Class constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void close()  
      ZMQ.PollItem getItem​(int index)
      Get the PollItem associated with an index.
      int getNext()
      Deprecated.
      use getSize instead
      int getSize()
      Get the current poll set size.
      ZMQ.Socket getSocket​(int index)
      Get the socket associated with an index.
      long getTimeout()
      Deprecated.
      Timeout handling has been moved to the poll() methods.
      int poll()
      Issue a poll call.
      int poll​(long tout)
      Issue a poll call, using the specified timeout value.
      boolean pollerr​(int index)
      Check whether the specified element in the poll set was signaled for error.
      boolean pollin​(int index)
      Check whether the specified element in the poll set was signaled for input.
      boolean pollout​(int index)
      Check whether the specified element in the poll set was signaled for output.
      int register​(java.nio.channels.SelectableChannel channel)
      Register a Channel for polling on all events.
      int register​(java.nio.channels.SelectableChannel channel, int events)
      Register a Socket for polling on the specified events.
      int register​(ZMQ.PollItem item)
      Register a Channel for polling on the specified events.
      int register​(ZMQ.Socket socket)
      Register a Socket for polling on all events.
      int register​(ZMQ.Socket socket, int events)
      Register a Socket for polling on the specified events.
      private int registerInternal​(ZMQ.PollItem item)
      Register a Socket for polling on the specified events.
      void setTimeout​(long timeout)
      Deprecated.
      Timeout handling has been moved to the poll() methods.
      void unregister​(java.nio.channels.SelectableChannel channel)
      Unregister a Socket for polling on the specified events.
      void unregister​(ZMQ.Socket socket)
      Unregister a Socket for polling on the specified events.
      private void unregisterInternal​(java.lang.Object socket)
      Unregister a Socket for polling on the specified events.
      • Methods inherited from class java.lang.Object

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

      • POLLIN

        public static final int POLLIN
        For ØMQ sockets, at least one message may be received from the socket without blocking.
        For standard sockets this is equivalent to the POLLIN flag of the poll() system call and generally means that at least one byte of data may be read from fd without blocking.
        See Also:
        Constant Field Values
      • POLLOUT

        public static final int POLLOUT
        For ØMQ sockets, at least one message may be sent to the socket without blocking.
        For standard sockets this is equivalent to the POLLOUT flag of the poll() system call and generally means that at least one byte of data may be written to fd without blocking.
        See Also:
        Constant Field Values
      • selector

        private final java.nio.channels.Selector selector
      • timeout

        private long timeout
    • Constructor Detail

      • Poller

        protected Poller​(ZMQ.Context context,
                         int size)
        Class constructor.
        Parameters:
        context - a 0MQ context previously created.
        size - the number of Sockets this poller will contain.
      • Poller

        protected Poller​(ZMQ.Context context)
        Class constructor.
        Parameters:
        context - a 0MQ context previously created.
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • register

        public int register​(ZMQ.Socket socket)
        Register a Socket for polling on all events.
        Parameters:
        socket - the Socket we are registering.
        Returns:
        the index identifying this Socket in the poll set.
      • register

        public int register​(java.nio.channels.SelectableChannel channel)
        Register a Channel for polling on all events.
        Parameters:
        channel - the Channel we are registering.
        Returns:
        the index identifying this Channel in the poll set.
      • register

        public int register​(ZMQ.Socket socket,
                            int events)
        Register a Socket for polling on the specified events.

        Automatically grow the internal representation if needed.

        Parameters:
        socket - the Socket we are registering.
        events - a mask composed by XORing POLLIN, POLLOUT and POLLERR.
        Returns:
        the index identifying this Socket in the poll set.
      • register

        public int register​(java.nio.channels.SelectableChannel channel,
                            int events)
        Register a Socket for polling on the specified events.

        Automatically grow the internal representation if needed.

        Parameters:
        channel - the Channel we are registering.
        events - a mask composed by XORing POLLIN, POLLOUT and POLLERR.
        Returns:
        the index identifying this Channel in the poll set.
      • register

        public int register​(ZMQ.PollItem item)
        Register a Channel for polling on the specified events.

        Automatically grow the internal representation if needed.

        Parameters:
        item - the PollItem we are registering.
        Returns:
        the index identifying this Channel in the poll set.
      • registerInternal

        private int registerInternal​(ZMQ.PollItem item)
        Register a Socket for polling on the specified events.

        Automatically grow the internal representation if needed.

        Parameters:
        item - the PollItem we are registering.
        Returns:
        the index identifying this Socket in the poll set.
      • unregister

        public void unregister​(ZMQ.Socket socket)
        Unregister a Socket for polling on the specified events.
        Parameters:
        socket - the Socket to be unregistered
      • unregister

        public void unregister​(java.nio.channels.SelectableChannel channel)
        Unregister a Socket for polling on the specified events.
        Parameters:
        channel - the Socket to be unregistered
      • unregisterInternal

        private void unregisterInternal​(java.lang.Object socket)
        Unregister a Socket for polling on the specified events.
        Parameters:
        socket - the Socket to be unregistered
      • getItem

        public ZMQ.PollItem getItem​(int index)
        Get the PollItem associated with an index.
        Parameters:
        index - the desired index.
        Returns:
        the PollItem associated with that index (or null).
      • getSocket

        public ZMQ.Socket getSocket​(int index)
        Get the socket associated with an index.
        Parameters:
        index - the desired index.
        Returns:
        the Socket associated with that index (or null).
      • getTimeout

        @Deprecated
        public long getTimeout()
        Deprecated.
        Timeout handling has been moved to the poll() methods.
        Get the current poll timeout.
        Returns:
        the current poll timeout in milliseconds.
      • setTimeout

        @Deprecated
        public void setTimeout​(long timeout)
        Deprecated.
        Timeout handling has been moved to the poll() methods.
        Set the poll timeout.
        Parameters:
        timeout - the desired poll timeout in milliseconds.
      • getSize

        public int getSize()
        Get the current poll set size.
        Returns:
        the current poll set size.
      • getNext

        @Deprecated
        public int getNext()
        Deprecated.
        use getSize instead
        Get the index for the next position in the poll set size.
        Returns:
        the index for the next position in the poll set size.
      • poll

        public int poll()
        Issue a poll call. If the poller's internal timeout value has been set, use that value as timeout; otherwise, block indefinitely.
        Returns:
        how many objects where signaled by poll ().
      • poll

        public int poll​(long tout)
        Issue a poll call, using the specified timeout value.

        Since ZeroMQ 3.0, the timeout parameter is in milliseconds, but prior to this the unit was microseconds.

        Parameters:
        tout - the timeout, as per zmq_poll (); if -1, it will block indefinitely until an event happens; if 0, it will return immediately; otherwise, it will wait for at most that many milliseconds/microseconds (see above).
        Returns:
        how many objects where signaled by poll ()
        See Also:
        "http://api.zeromq.org/3-0:zmq-poll"
      • pollin

        public boolean pollin​(int index)
        Check whether the specified element in the poll set was signaled for input.
        Parameters:
        index - of element
        Returns:
        true if the element was signaled.
      • pollout

        public boolean pollout​(int index)
        Check whether the specified element in the poll set was signaled for output.
        Parameters:
        index - of element
        Returns:
        true if the element was signaled.
      • pollerr

        public boolean pollerr​(int index)
        Check whether the specified element in the poll set was signaled for error.
        Parameters:
        index - of element
        Returns:
        true if the element was signaled.