Package org.zeromq

Class ZMQ

java.lang.Object
org.zeromq.ZMQ

public class ZMQ extends Object
ZeroMQ JNI Bindings.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Inner class: Context.
    static enum 
    Inner class: Error.
    static class 
    Inner class: Event.
    static class 
    Inner class: Poller.
    static class 
     
    static class 
    Inner class: Socket.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Flag to specify a DEALER socket (aka XREQ).
    static final int
     
    static final int
    Deprecated.
    static final int
    EVENT_ACCEPT_FAILED: could not accept client connection.
    static final int
    EVENT_ACCEPTED: connection accepted to bound interface.
    static final int
    EVENT_ALL: all events known by the java binding.
    static final int
    EVENT_BIND_FAILED: socket could not bind to an address.
    static final int
    EVENT_CLOSE_FAILED: connection couldn't be closed.
    static final int
    EVENT_CLOSED: connection closed.
    static final int
    EVENT_CONNECT_DELAYED: synchronous connect failed, it's being polled.
    static final int
    EVENT_CONNECT_RETRIED: asynchronous connect / reconnection attempt.
    static final int
    EVENT_CONNECTED: connection established.
    static final int
    EVENT_DISCONNECTED: broken session.
    static final int
    EVENT_LISTENING: socket bound to an address, ready to accept connections.
    static final int
    EVENT_MONITOR_STOPPED: monitor has been stopped.
    static final int
    Flag to specify a FORWARDER device.
    static final int
    Socket flag to indicate a nonblocking send or recv mode.
    static final int
    Flag to specify a exclusive pair of items.
    static final int
    Flag to specify a PUB socket, receiving side must be a SUB or XSUB.
    static final int
    Flag to specify the receiving part of a PUSH socket.
    static final int
    Flag to specify a PUSH socket, receiving side must be a PULL.
    static final int
    Flag to specify a QUEUE device.
    static final int
    Flag to specify the receiving part of a REQ socket.
    static final int
    Flag to specify a REQ socket, receiving side must be a REP.
    static final int
    Flag to specify ROUTER socket (aka XREP).
    static final int
    Socket flag to indicate that more message parts are coming.
    static final int
    Flag to specify a STREAMER device.
    static final int
    Flag to specify the receiving part of the PUB or XPUB socket.
    static final int
    Deprecated.
    static final int
    Flag to specify a XPUB socket, receiving side must be a SUB or XSUB.
    static final int
    Deprecated.
    As of release 3.0 of zeromq, replaced by ROUTER
    static final int
    Deprecated.
    As of release 3.0 of zeromq, replaced by DEALER
    static final int
    Flag to specify the receiving part of the PUB or XPUB socket.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ZMQ()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    context(int ioThreads)
    Create a new Context.
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    protected static long
     
    static int
     
    static int
     
    static int
     
    static int
     
    static String
     
    protected static int
    make_version(int major, int minor, int patch)
     
    static int
    makeVersion(int major, int minor, int patch)
     
    static int
    poll(ZMQ.PollItem[] items, int count, long timeout)
    Poll on polling items until timeout
    static int
    poll(ZMQ.PollItem[] items, long timeout)
    Poll on polling items until timeout
    static void
    proxy(ZMQ.Socket frontend, ZMQ.Socket backend, ZMQ.Socket capture)
    Starts the built-in 0MQ proxy in the current application thread.
    protected static int
     
    protected static int
     
    protected static int
     
    protected static int
     

    Methods inherited from class java.lang.Object

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

    • NOBLOCK

      public static final int NOBLOCK
      Socket flag to indicate a nonblocking send or recv mode.
      See Also:
    • DONTWAIT

      public static final int DONTWAIT
      See Also:
    • SNDMORE

      public static final int SNDMORE
      Socket flag to indicate that more message parts are coming.
      See Also:
    • PAIR

      public static final int PAIR
      Flag to specify a exclusive pair of items.
      See Also:
    • PUB

      public static final int PUB
      Flag to specify a PUB socket, receiving side must be a SUB or XSUB.
      See Also:
    • SUB

      public static final int SUB
      Flag to specify the receiving part of the PUB or XPUB socket.
      See Also:
    • REQ

      public static final int REQ
      Flag to specify a REQ socket, receiving side must be a REP.
      See Also:
    • REP

      public static final int REP
      Flag to specify the receiving part of a REQ socket.
      See Also:
    • DEALER

      public static final int DEALER
      Flag to specify a DEALER socket (aka XREQ). DEALER is really a combined ventilator / sink that does load-balancing on output and fair-queuing on input with no other semantics. It is the only socket type that lets you shuffle messages out to N nodes and shuffle the replies back, in a raw bidirectional asynch pattern.
      See Also:
    • XREQ

      public static final int XREQ
      Deprecated.
      As of release 3.0 of zeromq, replaced by DEALER
      Old alias for DEALER flag. Flag to specify a XREQ socket, receiving side must be a XREP.
      See Also:
    • ROUTER

      public static final int ROUTER
      Flag to specify ROUTER socket (aka XREP). ROUTER is the socket that creates and consumes request-reply routing envelopes. It is the only socket type that lets you route messages to specific connections if you know their identities.
      See Also:
    • XREP

      public static final int XREP
      Deprecated.
      As of release 3.0 of zeromq, replaced by ROUTER
      Old alias for ROUTER flag. Flag to specify the receiving part of a XREQ socket.
      See Also:
    • PULL

      public static final int PULL
      Flag to specify the receiving part of a PUSH socket.
      See Also:
    • PUSH

      public static final int PUSH
      Flag to specify a PUSH socket, receiving side must be a PULL.
      See Also:
    • XPUB

      public static final int XPUB
      Flag to specify a XPUB socket, receiving side must be a SUB or XSUB. Subscriptions can be received as a message. Subscriptions start with a '1' byte. Unsubscriptions start with a '0' byte.
      See Also:
    • XSUB

      public static final int XSUB
      Flag to specify the receiving part of the PUB or XPUB socket. Allows
      See Also:
    • STREAMER

      public static final int STREAMER
      Flag to specify a STREAMER device.
      See Also:
    • FORWARDER

      public static final int FORWARDER
      Flag to specify a FORWARDER device.
      See Also:
    • QUEUE

      public static final int QUEUE
      Flag to specify a QUEUE device.
      See Also:
    • UPSTREAM

      @Deprecated public static final int UPSTREAM
      Deprecated.
      See Also:
    • DOWNSTREAM

      @Deprecated public static final int DOWNSTREAM
      Deprecated.
      See Also:
    • EVENT_CONNECTED

      public static final int EVENT_CONNECTED
      EVENT_CONNECTED: connection established. The EVENT_CONNECTED event triggers when a connection has been established to a remote peer. This can happen either synchronous or asynchronous. Value is the FD of the newly connected socket.
      See Also:
    • EVENT_CONNECT_DELAYED

      public static final int EVENT_CONNECT_DELAYED
      EVENT_CONNECT_DELAYED: synchronous connect failed, it's being polled. The EVENT_CONNECT_DELAYED event triggers when an immediate connection attempt is delayed and its completion is being polled for. Value has no meaning.
      See Also:
    • EVENT_CONNECT_RETRIED

      public static final int EVENT_CONNECT_RETRIED
      EVENT_CONNECT_RETRIED: asynchronous connect / reconnection attempt. The EVENT_CONNECT_RETRIED event triggers when a connection attempt is being handled by reconnect timer. The reconnect interval's recomputed for each attempt. Value is the reconnect interval.
      See Also:
    • EVENT_LISTENING

      public static final int EVENT_LISTENING
      EVENT_LISTENING: socket bound to an address, ready to accept connections. The EVENT_LISTENING event triggers when a socket's successfully bound to a an interface. Value is the FD of the newly bound socket.
      See Also:
    • EVENT_BIND_FAILED

      public static final int EVENT_BIND_FAILED
      EVENT_BIND_FAILED: socket could not bind to an address. The EVENT_BIND_FAILED event triggers when a socket could not bind to a given interface. Value is the errno generated by the bind call.
      See Also:
    • EVENT_ACCEPTED

      public static final int EVENT_ACCEPTED
      EVENT_ACCEPTED: connection accepted to bound interface. The EVENT_ACCEPTED event triggers when a connection from a remote peer has been established with a socket's listen address. Value is the FD of the accepted socket.
      See Also:
    • EVENT_ACCEPT_FAILED

      public static final int EVENT_ACCEPT_FAILED
      EVENT_ACCEPT_FAILED: could not accept client connection. The EVENT_ACCEPT_FAILED event triggers when a connection attempt to a socket's bound address fails. Value is the errno generated by accept.
      See Also:
    • EVENT_CLOSED

      public static final int EVENT_CLOSED
      EVENT_CLOSED: connection closed. The EVENT_CLOSED event triggers when a connection's underlying descriptor has been closed. Value is the former FD of the for the closed socket. FD has been closed already!
      See Also:
    • EVENT_CLOSE_FAILED

      public static final int EVENT_CLOSE_FAILED
      EVENT_CLOSE_FAILED: connection couldn't be closed. The EVENT_CLOSE_FAILED event triggers when a descriptor could not be released back to the OS. Implementation note: ONLY FOR IPC SOCKETS. Value is the errno generated by unlink.
      See Also:
    • EVENT_DISCONNECTED

      public static final int EVENT_DISCONNECTED
      EVENT_DISCONNECTED: broken session. The EVENT_DISCONNECTED event triggers when the stream engine (tcp and ipc specific) detects a corrupted / broken session. Value is the FD of the socket.
      See Also:
    • EVENT_MONITOR_STOPPED

      public static final int EVENT_MONITOR_STOPPED
      EVENT_MONITOR_STOPPED: monitor has been stopped. The EVENT_MONITOR_STOPPED event triggers when the monitor for a socket is stopped.
      See Also:
    • EVENT_ALL

      public static final int EVENT_ALL
      EVENT_ALL: all events known by the java binding. The EVENT_ALL constant can be used to set up a monitor for all events known by the java binding. One could add more flags
      See Also:
  • Constructor Details

    • ZMQ

      public ZMQ()
  • Method Details

    • getMajorVersion

      public static int getMajorVersion()
      Returns:
      Major version number of the ZMQ library.
    • getMinorVersion

      public static int getMinorVersion()
      Returns:
      Major version number of the ZMQ library.
    • getPatchVersion

      public static int getPatchVersion()
      Returns:
      Major version number of the ZMQ library.
    • getFullVersion

      public static int getFullVersion()
      Returns:
      Full version number of the ZMQ library used for comparing versions.
    • makeVersion

      public static int makeVersion(int major, int minor, int patch)
      Parameters:
      major - Version major component.
      minor - Version minor component.
      patch - Version patch component.
      Returns:
      Comparible single int version number.
    • getVersionString

      public static String getVersionString()
      Returns:
      String version number in the form major.minor.patch.
    • proxy

      public static void proxy(ZMQ.Socket frontend, ZMQ.Socket backend, ZMQ.Socket capture)
      Starts the built-in 0MQ proxy in the current application thread. The proxy connects a frontend socket to a backend socket. Conceptually, data flows from frontend to backend. Depending on the socket types, replies may flow in the opposite direction. The direction is conceptual only; the proxy is fully symmetric and there is no technical difference between frontend and backend. Before calling ZMQ.proxy() you must set any socket options, and connect or bind both frontend and backend sockets. The two conventional proxy models are: ZMQ.proxy() runs in the current thread and returns only if/when the current context is closed.
      Parameters:
      frontend - ZMQ.Socket
      backend - ZMQ.Socket
      capture - If the capture socket is not NULL, the proxy shall send all messages, received on both frontend and backend, to the capture socket. The capture socket should be a ZMQ_PUB, ZMQ_DEALER, ZMQ_PUSH, or ZMQ_PAIR socket.
      Since:
      3.2.2
    • poll

      public static int poll(ZMQ.PollItem[] items, long timeout)
      Poll on polling items until timeout
      Parameters:
      items - polling items
      timeout - timeout in millisecond
      Returns:
      number of events
    • poll

      public static int poll(ZMQ.PollItem[] items, int count, long timeout)
      Poll on polling items until timeout
      Parameters:
      items - polling items
      count - active item count
      timeout - timeout in millisecond
      Returns:
      number of events
    • version_full

      protected static int version_full()
    • version_major

      protected static int version_major()
    • version_minor

      protected static int version_minor()
    • version_patch

      protected static int version_patch()
    • make_version

      protected static int make_version(int major, int minor, int patch)
    • ENOTSUP

      protected static long ENOTSUP()
    • EPROTONOSUPPORT

      protected static long EPROTONOSUPPORT()
    • ENOBUFS

      protected static long ENOBUFS()
    • ENETDOWN

      protected static long ENETDOWN()
    • EADDRINUSE

      protected static long EADDRINUSE()
    • EADDRNOTAVAIL

      protected static long EADDRNOTAVAIL()
    • ECONNREFUSED

      protected static long ECONNREFUSED()
    • EINPROGRESS

      protected static long EINPROGRESS()
    • EHOSTUNREACH

      protected static long EHOSTUNREACH()
    • EMTHREAD

      protected static long EMTHREAD()
    • EFSM

      protected static long EFSM()
    • ENOCOMPATPROTO

      protected static long ENOCOMPATPROTO()
    • ETERM

      protected static long ETERM()
    • ENOTSOCK

      protected static long ENOTSOCK()
    • context

      public static ZMQ.Context context(int ioThreads)
      Create a new Context.
      Parameters:
      ioThreads - Number of threads to use, usually 1 is sufficient for most use cases.
      Returns:
      the Context