Package org.zeromq

Class ZMonitor

java.lang.Object
org.zeromq.ZMonitor
All Implemented Interfaces:
Closeable, AutoCloseable

public class ZMonitor extends Object implements Closeable
The ZMonitor actor provides an API for obtaining socket events such as connected, listen, disconnected, etc. Socket events are only available for sockets connecting or bound to ipc:// and tcp:// endpoints.
  • Field Details

  • Constructor Details

    • ZMonitor

      public ZMonitor(ZContext ctx, ZMQ.Socket socket)
      Creates a monitoring actor for the given socket.
      Parameters:
      ctx - the context relative to this actor. Not null.
      socket - the socket to monitor for events. Not null.
  • Method Details

    • start

      public final ZMonitor start()
      Starts the monitoring. Event types have to be added before the start, or they will take no effect.
      Returns:
      this instance.
    • close

      public final void close() throws IOException
      Stops the monitoring and closes the actor. When returning from that call, ZMonitor will be no more active.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • destroy

      public final void destroy()
      Stops the monitoring and closes the actor. When returning from that call, ZMonitor will be no more active.
    • verbose

      public final ZMonitor verbose(boolean verbose)
      Sets verbosity of the monitor.
      Parameters:
      verbose - true for monitor to be verbose, otherwise false.
      Returns:
      this instance.
    • add

      public final ZMonitor add(ZMonitor.Event... events)
      Adds event types to monitor.
      Parameters:
      events - the types of events to monitor.
      Returns:
      this instance.
    • remove

      public final ZMonitor remove(ZMonitor.Event... events)
      Removes event types from monitor.
      Parameters:
      events - the types of events to stop monitoring.
      Returns:
      this instance.
    • nextEvent

      public final ZMonitor.ZEvent nextEvent()
      Gets the next event, blocking for it until available.
      Returns:
      the next monitored event or null if closed.
    • nextEvent

      public final ZMonitor.ZEvent nextEvent(boolean wait)
      Gets the next event, blocking for it until available if requested.
      Parameters:
      wait - true to block until next event is available, false to immediately return with null if there is no event.
      Returns:
      the next event or null if there is currently none.
    • nextEvent

      public final ZMonitor.ZEvent nextEvent(int timeout)
      Gets the next event, blocking for it until available if requested.
      Parameters:
      timeout - the time in milliseconds to wait for a message before returning null, -1 to block.
      Returns:
      the next event or null if there is currently none after the specified timeout.