PageRenderTime 99ms CodeModel.GetById 3ms app.highlight 85ms RepoModel.GetById 1ms app.codeStats 0ms

/JAwaPI/src/org/zeromq/ZMQ.java

https://github.com/s-faychatelard/API
Java | 1600 lines | 630 code | 204 blank | 766 comment | 54 complexity | ec2cdc78a08f214eab6195fc9ad0379e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*
   2    Copyright (c) 1991-2011 iMatix Corporation <www.imatix.com>
   3    Copyright other contributors as noted in the AUTHORS file.
   4
   5                
   6    This file is part of 0MQ.
   7
   8    0MQ is free software; you can redistribute it and/or modify it under
   9    the terms of the GNU Lesser General Public License as published by
  10    the Free Software Foundation; either version 3 of the License, or
  11    (at your option) any later version.
  12            
  13    0MQ is distributed in the hope that it will be useful,
  14    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16    GNU Lesser General Public License for more details.
  17        
  18    You should have received a copy of the GNU Lesser General Public License
  19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20*/
  21package org.zeromq;
  22
  23
  24import java.nio.channels.SelectableChannel;
  25import zmq.Ctx;
  26import zmq.DecoderBase;
  27import zmq.EncoderBase;
  28import zmq.SocketBase;
  29import zmq.ZError;
  30
  31public class ZMQ {
  32    
  33    /**
  34     * Socket flag to indicate that more message parts are coming.
  35     */
  36    public static final int SNDMORE = zmq.ZMQ.ZMQ_SNDMORE;
  37    
  38    // Values for flags in Socket's send and recv functions.
  39    /**
  40     * Socket flag to indicate a nonblocking send or recv mode.
  41     */
  42    public static final int DONTWAIT = zmq.ZMQ.ZMQ_DONTWAIT;
  43    public static final int NOBLOCK = zmq.ZMQ.ZMQ_DONTWAIT;
  44    
  45    // Socket types, used when creating a Socket.
  46    /**
  47     * Flag to specify a exclusive pair of sockets.
  48     */
  49    public static final int PAIR = zmq.ZMQ.ZMQ_PAIR;
  50    /**
  51     * Flag to specify a PUB socket, receiving side must be a SUB or XSUB.
  52     */
  53    public static final int PUB = zmq.ZMQ.ZMQ_PUB;
  54    /**
  55     * Flag to specify the receiving part of the PUB or XPUB socket.
  56     */
  57    public static final int SUB = zmq.ZMQ.ZMQ_SUB;
  58    /**
  59     * Flag to specify a REQ socket, receiving side must be a REP.
  60     */
  61    public static final int REQ = zmq.ZMQ.ZMQ_REQ;
  62    /**
  63     * Flag to specify the receiving part of a REQ socket.
  64     */
  65    public static final int REP = zmq.ZMQ.ZMQ_REP;
  66    /**
  67     * Flag to specify a DEALER socket (aka XREQ). 
  68     * DEALER is really a combined ventilator / sink 
  69     * that does load-balancing on output and fair-queuing on input 
  70     * with no other semantics. It is the only socket type that lets 
  71     * you shuffle messages out to N nodes and shuffle the replies 
  72     * back, in a raw bidirectional asynch pattern.
  73     */
  74    public static final int DEALER = zmq.ZMQ.ZMQ_DEALER;
  75    /**
  76    * Old alias for DEALER flag.
  77    * Flag to specify a XREQ socket, receiving side must be a XREP.
  78    *
  79    * @deprecated  As of release 3.0 of zeromq, replaced by {@link #DEALER}
  80    */
  81    public static final int XREQ = DEALER;
  82    /**
  83     * Flag to specify ROUTER socket (aka XREP).
  84     * ROUTER is the socket that creates and consumes request-reply 
  85     * routing envelopes. It is the only socket type that lets you route 
  86     * messages to specific connections if you know their identities.
  87     */
  88    public static final int ROUTER = zmq.ZMQ.ZMQ_ROUTER;
  89    /**
  90     * Old alias for ROUTER flag.
  91     * Flag to specify the receiving part of a XREQ socket.
  92     *
  93     * @deprecated  As of release 3.0 of zeromq, replaced by {@link #ROUTER}
  94     */
  95    public static final int XREP = ROUTER;
  96    /**
  97     * Flag to specify the receiving part of a PUSH socket.
  98     */
  99    public static final int PULL = zmq.ZMQ.ZMQ_PULL;
 100    /**
 101     * Flag to specify a PUSH socket, receiving side must be a PULL.
 102     */
 103    public static final int PUSH = zmq.ZMQ.ZMQ_PUSH;
 104    /**
 105     * Flag to specify a XPUB socket, receiving side must be a SUB or XSUB.
 106     * Subscriptions can be received as a message. Subscriptions start with
 107     * a '1' byte. Unsubscriptions start with a '0' byte.
 108     */
 109    public static final int XPUB = zmq.ZMQ.ZMQ_XPUB;
 110    /**
 111     * Flag to specify the receiving part of the PUB or XPUB socket. Allows
 112     */
 113    public static final int XSUB = zmq.ZMQ.ZMQ_XSUB;
 114
 115    /**
 116     * Flag to specify a STREAMER device.
 117     */
 118    public static final int STREAMER = zmq.ZMQ.ZMQ_STREAMER ;
 119    /**
 120     * Flag to specify a FORWARDER device.
 121     */
 122    public static final int FORWARDER = zmq.ZMQ.ZMQ_FORWARDER ;
 123    /**
 124     * Flag to specify a QUEUE device.
 125     */
 126    public static final int QUEUE = zmq.ZMQ.ZMQ_QUEUE ;
 127    
 128    /**
 129     * @see org.zeromq.ZMQ#PULL
 130     */
 131    @Deprecated
 132    public static final int UPSTREAM = PULL;
 133    /**
 134     * @see org.zeromq.ZMQ#PUSH
 135     */
 136    @Deprecated
 137    public static final int DOWNSTREAM = PUSH;
 138
 139    /**
 140     * ZMQ Events
 141     */
 142    public static final int EVENT_CONNECTED = zmq.ZMQ.ZMQ_EVENT_CONNECTED;
 143    public static final int EVENT_DELAYED = zmq.ZMQ.ZMQ_EVENT_CONNECT_DELAYED;
 144    public static final int EVENT_RETRIED = zmq.ZMQ.ZMQ_EVENT_CONNECT_RETRIED;
 145    public static final int EVENT_CONNECT_FAILED = zmq.ZMQ.ZMQ_EVENT_CONNECT_FAILED;
 146
 147    public static final int EVENT_LISTENING = zmq.ZMQ.ZMQ_EVENT_LISTENING;
 148    public static final int EVENT_BIND_FAILED = zmq.ZMQ.ZMQ_EVENT_BIND_FAILED;
 149
 150    public static final int EVENT_ACCEPTED = zmq.ZMQ.ZMQ_EVENT_ACCEPTED;
 151    public static final int EVENT_ACCEPT_FAILED = zmq.ZMQ.ZMQ_EVENT_ACCEPT_FAILED;
 152
 153    public static final int EVENT_CLOSED = zmq.ZMQ.ZMQ_EVENT_CLOSED;
 154    public static final int EVENT_CLOSE_FAILED = zmq.ZMQ.ZMQ_EVENT_CLOSE_FAILED;
 155    public static final int EVENT_DISCONNECTED = zmq.ZMQ.ZMQ_EVENT_DISCONNECTED;
 156
 157    public static final int EVENT_ALL = zmq.ZMQ.ZMQ_EVENT_ALL;
 158
 159    /**
 160     * Create a new Context.
 161     *
 162     * @param ioThreads
 163     *            Number of threads to use, usually 1 is sufficient for most use cases.
 164     * @return the Context
 165     */
 166    public static Context context(int ioThreads) {
 167        return new Context(ioThreads);
 168    }
 169
 170    public static class Context {
 171
 172        private final Ctx ctx;
 173
 174        /**
 175         * Class constructor.
 176         *
 177         * @param ioThreads
 178         *            size of the threads pool to handle I/O operations.
 179         */
 180        protected Context(int ioThreads) {
 181            ctx = zmq.ZMQ.zmq_init(ioThreads);
 182        }
 183
 184        /**
 185         * This is an explicit "destructor". It can be called to ensure the corresponding 0MQ
 186         * Context has been disposed of.
 187         */
 188
 189        public void term() {
 190            ctx.terminate();
 191        }
 192
 193        /**
 194         * Create a new Socket within this context.
 195         *
 196         * @param type
 197         *            the socket type.
 198         * @return the newly created Socket.
 199         */
 200        public Socket socket(int type) {
 201            return new Socket(this, type);
 202        }
 203
 204        /**
 205         * Create a new Poller within this context, with a default size.
 206         *
 207         * @return the newly created Poller.
 208         * @deprecated Use poller constructor
 209         */
 210        public Poller poller () {
 211            return new Poller (this);
 212        }
 213
 214        /**
 215         * Create a new Poller within this context, with a specified initial size.
 216         *
 217         * @param size
 218         *            the poller initial size.
 219         * @return the newly created Poller.
 220         * @deprecated Use poller constructor
 221         */
 222        public Poller poller (int size) {
 223            return new Poller (this, size);
 224        }
 225
 226    }
 227
 228    public static class Socket {
 229
 230        //  This port range is defined by IANA for dynamic or private ports
 231        //  We use this when choosing a port for dynamic binding.
 232        private static final int DYNFROM = 0xc000;
 233        private static final int DYNTO = 0xffff;
 234
 235        private final Ctx ctx;
 236        private final SocketBase base;
 237
 238        /**
 239         * Class constructor.
 240         *
 241         * @param context
 242         *            a 0MQ context previously created.
 243         * @param type
 244         *            the socket type.
 245         */
 246        protected Socket(Context context, int type) {
 247            ctx = context.ctx;
 248            base = ctx.create_socket(type);
 249            mayRaise();
 250        }
 251
 252        protected Socket(SocketBase base_) {
 253            ctx = null;
 254            base = base_;
 255        }
 256
 257        protected SocketBase base() {
 258            return base;
 259        }
 260
 261        private final static void mayRaise ()
 262        {
 263            if (!ZError.is (0) && !ZError.is (ZError.EAGAIN))
 264                throw new ZMQException (ZError.errno ());
 265        }
 266
 267        private final static void mayRaiseNot (int codeToIgnore)
 268        {
 269            if (!ZError.is (codeToIgnore))
 270                mayRaise ();
 271        }
 272
 273
 274        /**
 275         * This is an explicit "destructor". It can be called to ensure the corresponding 0MQ Socket
 276         * has been disposed of.
 277         */
 278        public final void close() {
 279            base.close();
 280        }
 281        
 282        /**
 283         * The 'ZMQ_TYPE option shall retrieve the socket type for the specified
 284         * 'socket'.  The socket type is specified at socket creation time and
 285         * cannot be modified afterwards.
 286         *
 287         * @return the socket type.
 288         */
 289        public final int getType () {
 290            return base.getsockopt(zmq.ZMQ.ZMQ_TYPE);
 291        }
 292        
 293        /**
 294         * @see #setLinger(long)
 295         *
 296         * @return the linger period.
 297         */
 298        public final long getLinger() {
 299            return base.getsockopt(zmq.ZMQ.ZMQ_LINGER);
 300        }
 301
 302        /**
 303         * The 'ZMQ_LINGER' option shall retrieve the period for pending outbound
 304         * messages to linger in memory after closing the socket. Value of -1 means
 305         * infinite. Pending messages will be kept until they are fully transferred to
 306         * the peer. Value of 0 means that all the pending messages are dropped immediately
 307         * when socket is closed. Positive value means number of milliseconds to keep
 308         * trying to send the pending messages before discarding them.
 309         *
 310         * @param value
 311         *            the linger period in milliseconds.
 312         */
 313        public final void setLinger (long value) 
 314        {
 315            base.setsockopt (zmq.ZMQ.ZMQ_LINGER, (int) value);
 316            mayRaiseNot (ZError.ETERM);
 317        }
 318        
 319        /**
 320         * @see #setReconnectIVL(long)
 321         *
 322         * @return the reconnectIVL.
 323         */
 324        public final long getReconnectIVL() {
 325            return base.getsockopt(zmq.ZMQ.ZMQ_RECONNECT_IVL);
 326        }
 327        
 328        /**
 329         */
 330        public final void setReconnectIVL(long value) {
 331            base.setsockopt(zmq.ZMQ.ZMQ_RECONNECT_IVL, (int)value);
 332            mayRaiseNot (ZError.ETERM);
 333        }
 334        
 335
 336        /**
 337         * @see #setBacklog(long)
 338         *
 339         * @return the backlog.
 340         */
 341        public final long getBacklog() {
 342            return base.getsockopt(zmq.ZMQ.ZMQ_BACKLOG);
 343        }
 344        
 345
 346        /**
 347         */
 348        public final void setBacklog(long value) {
 349            base.setsockopt(zmq.ZMQ.ZMQ_BACKLOG, (int)value);
 350            mayRaiseNot (ZError.ETERM);
 351        }
 352        
 353
 354        /**
 355         * @see #setReconnectIVLMax(long)
 356         *
 357         * @return the reconnectIVLMax.
 358         */
 359        public final long getReconnectIVLMax () {
 360            return base.getsockopt(zmq.ZMQ.ZMQ_RECONNECT_IVL_MAX);
 361        }
 362        
 363        /**
 364         */
 365        public final void setReconnectIVLMax (long value) {
 366            base.setsockopt(zmq.ZMQ.ZMQ_RECONNECT_IVL_MAX, (int)value);
 367            mayRaiseNot (ZError.ETERM);
 368        }
 369        
 370
 371        /**
 372         * @see #setMaxMsgSize(long)
 373         *
 374         * @return the maxMsgSize.
 375         */
 376        public final long getMaxMsgSize() {
 377            return (Long)base.getsockoptx(zmq.ZMQ.ZMQ_MAXMSGSIZE);
 378        }
 379        
 380        /**
 381         */
 382        public final void setMaxMsgSize(long value) {
 383            base.setsockopt(zmq.ZMQ.ZMQ_MAXMSGSIZE, value);
 384            mayRaiseNot (ZError.ETERM);
 385        }
 386        
 387
 388        /**
 389         * @see #setSndHWM(long)
 390         *
 391         * @return the SndHWM.
 392         */
 393        public final long getSndHWM() {
 394            return base.getsockopt(zmq.ZMQ.ZMQ_SNDHWM);
 395        }
 396        
 397        /**
 398         */
 399        public final void setSndHWM(long value) {
 400            base.setsockopt(zmq.ZMQ.ZMQ_SNDHWM, (int)value);
 401            mayRaiseNot (ZError.ETERM);
 402        }
 403        
 404
 405        /**
 406         * @see #setRcvHWM(long)
 407         *
 408         * @return the recvHWM period.
 409         */
 410        public final long getRcvHWM() {
 411            return base.getsockopt(zmq.ZMQ.ZMQ_RCVHWM);
 412        }
 413        
 414        /**
 415         */
 416        public final void setRcvHWM(long value) {
 417            base.setsockopt(zmq.ZMQ.ZMQ_RCVHWM, (int)value);
 418            mayRaiseNot (ZError.ETERM);
 419        }
 420        
 421        
 422        /**
 423         * @see #setHWM(long)
 424         * 
 425         * @return the High Water Mark.
 426         */
 427        @Deprecated
 428        public final long getHWM() {
 429            return -1;
 430        }
 431
 432        /**
 433         * The 'ZMQ_HWM' option shall set the high water mark for the specified 'socket'. The high
 434         * water mark is a hard limit on the maximum number of outstanding messages 0MQ shall queue
 435         * in memory for any single peer that the specified 'socket' is communicating with.
 436         * 
 437         * If this limit has been reached the socket shall enter an exceptional state and depending
 438         * on the socket type, 0MQ shall take appropriate action such as blocking or dropping sent
 439         * messages. Refer to the individual socket descriptions in the man page of zmq_socket[3] for
 440         * details on the exact action taken for each socket type.
 441         * 
 442         * @param hwm
 443         *            the number of messages to queue.
 444         */
 445        public final void setHWM(long hwm) {
 446            setSndHWM (hwm);
 447            setRcvHWM (hwm);
 448        }
 449        
 450        /**
 451         * @see #setSwap(long)
 452         * 
 453         * @return the number of messages to swap at most.
 454         */
 455        @Deprecated
 456        public final long getSwap() {
 457            // not support at zeromq 3
 458            return -1L;
 459        }
 460        
 461
 462        /**
 463         * Get the Swap. The 'ZMQ_SWAP' option shall set the disk offload (swap) size for the
 464         * specified 'socket'. A socket which has 'ZMQ_SWAP' set to a non-zero value may exceed its
 465         * high water mark; in this case outstanding messages shall be offloaded to storage on disk
 466         * rather than held in memory.
 467         * 
 468         * @param value
 469         *            The value of 'ZMQ_SWAP' defines the maximum size of the swap space in bytes.
 470         */
 471        @Deprecated
 472        public final void setSwap(long value) {
 473            throw new UnsupportedOperationException ();
 474        }
 475
 476
 477        /**
 478         * @see #setAffinity(long)
 479         * 
 480         * @return the affinity.
 481         */
 482        public final long getAffinity() {
 483            return (Long)base.getsockoptx(zmq.ZMQ.ZMQ_AFFINITY);
 484        }
 485        
 486        /**
 487         * Get the Affinity. The 'ZMQ_AFFINITY' option shall set the I/O thread affinity for newly
 488         * created connections on the specified 'socket'.
 489         * 
 490         * Affinity determines which threads from the 0MQ I/O thread pool associated with the
 491         * socket's _context_ shall handle newly created connections. A value of zero specifies no
 492         * affinity, meaning that work shall be distributed fairly among all 0MQ I/O threads in the
 493         * thread pool. For non-zero values, the lowest bit corresponds to thread 1, second lowest
 494         * bit to thread 2 and so on. For example, a value of 3 specifies that subsequent
 495         * connections on 'socket' shall be handled exclusively by I/O threads 1 and 2.
 496         * 
 497         * See also  in the man page of zmq_init[3] for details on allocating the number of I/O threads for a
 498         * specific _context_.
 499         * 
 500         * @param value
 501         *            the io_thread affinity.
 502         */
 503        public final void setAffinity (long value) {
 504            base.setsockopt(zmq.ZMQ.ZMQ_AFFINITY, value);
 505            mayRaiseNot (ZError.ETERM);
 506        }
 507        
 508        /**
 509         * @see #setIdentity(byte[])
 510         * 
 511         * @return the Identitiy.
 512         */
 513        public final byte[] getIdentity() {
 514            return (byte[]) base.getsockoptx(zmq.ZMQ.ZMQ_IDENTITY);
 515        }
 516        
 517        /**
 518         * The 'ZMQ_IDENTITY' option shall set the identity of the specified 'socket'. Socket
 519         * identity determines if existing 0MQ infastructure (_message queues_, _forwarding
 520         * devices_) shall be identified with a specific application and persist across multiple
 521         * runs of the application.
 522         * 
 523         * If the socket has no identity, each run of an application is completely separate from
 524         * other runs. However, with identity set the socket shall re-use any existing 0MQ
 525         * infrastructure configured by the previous run(s). Thus the application may receive
 526         * messages that were sent in the meantime, _message queue_ limits shall be shared with
 527         * previous run(s) and so on.
 528         * 
 529         * Identity should be at least one byte and at most 255 bytes long. Identities starting with
 530         * binary zero are reserved for use by 0MQ infrastructure.
 531         * 
 532         * @param identity
 533         */
 534        public final void setIdentity(byte[] identity) {
 535            base.setsockopt(zmq.ZMQ.ZMQ_IDENTITY, identity);
 536            mayRaiseNot (ZError.ETERM);
 537        }
 538        
 539        /**
 540         * @see #setRate(long)
 541         * 
 542         * @return the Rate.
 543         */
 544        public final long getRate() {
 545            return base.getsockopt(zmq.ZMQ.ZMQ_RATE);
 546        }
 547        
 548
 549        /**
 550         * The 'ZMQ_RATE' option shall set the maximum send or receive data rate for multicast
 551         * transports such as in the man page of zmq_pgm[7] using the specified 'socket'.
 552         *
 553         * @param value maximum send or receive data rate for multicast, default 100
 554         */
 555        public final void setRate (long value) {
 556            throw new UnsupportedOperationException ();
 557        }
 558
 559
 560        /**
 561         * @see #setRecoveryInterval(long)
 562         * 
 563         * @return the RecoveryIntervall.
 564         */
 565        public final long getRecoveryInterval () {
 566            return base.getsockopt(zmq.ZMQ.ZMQ_RECOVERY_IVL);
 567        }
 568        
 569
 570        /**
 571         * The 'ZMQ_RECOVERY_IVL' option shall set the recovery interval for multicast transports
 572         * using the specified 'socket'. The recovery interval determines the maximum time in
 573         * seconds that a receiver can be absent from a multicast group before unrecoverable data
 574         * loss will occur.
 575         * 
 576         * CAUTION: Excersize care when setting large recovery intervals as the data needed for
 577         * recovery will be held in memory. For example, a 1 minute recovery interval at a data rate
 578         * of 1Gbps requires a 7GB in-memory buffer. {Purpose of this Method}
 579         * 
 580         * @param value recovery interval for multicast in milliseconds, default 10000
 581         */
 582        public final void setRecoveryInterval (long value) {
 583            throw new UnsupportedOperationException ();
 584        }
 585
 586        /**
 587         * @see #setMulticastLoop(boolean)
 588         * 
 589         * @return the Multicast Loop.
 590         */
 591        @Deprecated
 592        public final boolean hasMulticastLoop () {
 593            return false;
 594        }
 595        
 596        
 597        /**
 598         * The 'ZMQ_MCAST_LOOP' option shall control whether data sent via multicast transports
 599         * using the specified 'socket' can also be received by the sending host via loopback. A
 600         * value of zero disables the loopback functionality, while the default value of 1 enables
 601         * the loopback functionality. Leaving multicast loopback enabled when it is not required
 602         * can have a negative impact on performance. Where possible, disable 'ZMQ_MCAST_LOOP' in
 603         * production environments.
 604         * 
 605         * @param mcast_loop
 606         */
 607        @Deprecated
 608        public final void setMulticastLoop (boolean mcast_loop) {
 609            throw new UnsupportedOperationException ();
 610        }
 611        
 612        /**
 613         * @see #setMulticastHops(long)
 614         * 
 615         * @return the Multicast Hops.
 616         */
 617        public final long getMulticastHops () {
 618            return base.getsockopt(zmq.ZMQ.ZMQ_MULTICAST_HOPS);
 619        }
 620
 621        
 622        /**
 623         * Sets the time-to-live field in every multicast packet sent from this socket.
 624         * The default is 1 which means that the multicast packets don't leave the local
 625         * network.
 626         * 
 627         * @param value time-to-live field in every multicast packet, default 1
 628         */
 629        public final void setMulticastHops (long value) {
 630            throw new UnsupportedOperationException ();
 631        }
 632
 633        /**
 634         * @see #setReceiveTimeOut(int)
 635         * 
 636         * @return the Receive Timeout  in milliseconds.
 637         */
 638        public final int getReceiveTimeOut() {
 639            return base.getsockopt(zmq.ZMQ.ZMQ_RCVTIMEO);
 640        }
 641        
 642        /**
 643         * Sets the timeout for receive operation on the socket. If the value is 0, recv 
 644         * will return immediately, with null if there is no message to receive. 
 645         * If the value is -1, it will block until a message is available. For all other 
 646         * values, it will wait for a message for that amount of time before returning with
 647         * a null and an EAGAIN error.
 648         * 
 649         * @param value Timeout for receive operation in milliseconds. Default -1 (infinite)
 650         */
 651        public final void setReceiveTimeOut (int value) {
 652            base.setsockopt(zmq.ZMQ.ZMQ_RCVTIMEO, value);
 653            mayRaiseNot (ZError.ETERM);
 654        }
 655        
 656
 657        /**
 658         * @see #setSendTimeOut(int)
 659         * 
 660         * @return the Send Timeout in milliseconds.
 661         */
 662        public final int getSendTimeOut() {
 663            return (int)base.getsockopt(zmq.ZMQ.ZMQ_SNDTIMEO);
 664        }
 665        
 666        /**
 667         * Sets the timeout for send operation on the socket. If the value is 0, send
 668         * will return immediately, with a false if the message cannot be sent.
 669         * If the value is -1, it will block until the message is sent. For all other
 670         * values, it will try to send the message for that amount of time before
 671         * returning with false and an EAGAIN error.
 672         * 
 673         * @param value Timeout for send operation in milliseconds. Default -1 (infinite)
 674         */
 675        public final void setSendTimeOut(int value) {
 676            base.setsockopt(zmq.ZMQ.ZMQ_SNDTIMEO, value);
 677            mayRaiseNot (ZError.ETERM);
 678        }
 679        
 680
 681        /**
 682         * @see #setSendBufferSize(long)
 683         * 
 684         * @return the kernel send buffer size.
 685         */
 686        public final long getSendBufferSize() {
 687            return base.getsockopt(zmq.ZMQ.ZMQ_SNDBUF);
 688        }
 689        
 690        /**
 691         * The 'ZMQ_SNDBUF' option shall set the underlying kernel transmit buffer size for the
 692         * 'socket' to the specified size in bytes. A value of zero means leave the OS default
 693         * unchanged. For details please refer to your operating system documentation for the
 694         * 'SO_SNDBUF' socket option.
 695         * 
 696         * @param value underlying kernel transmit buffer size for the 'socket' in bytes
 697         *              A value of zero means leave the OS default unchanged.
 698         */
 699        public final void setSendBufferSize(long value) {
 700            base.setsockopt(zmq.ZMQ.ZMQ_SNDBUF, (int)value);
 701            mayRaiseNot (ZError.ETERM);
 702        }
 703        
 704        /**
 705         * @see #setReceiveBufferSize(long)
 706         * 
 707         * @return the kernel receive buffer size.
 708         */
 709        public final long getReceiveBufferSize() {
 710            return base.getsockopt(zmq.ZMQ.ZMQ_RCVBUF);
 711        }
 712        
 713        /**
 714         * The 'ZMQ_RCVBUF' option shall set the underlying kernel receive buffer size for the
 715         * 'socket' to the specified size in bytes.
 716         * For details refer to your operating system documentation for the 'SO_RCVBUF'
 717         * socket option.
 718         * 
 719         * @param value Underlying kernel receive buffer size for the 'socket' in bytes.
 720         *              A value of zero means leave the OS default unchanged.
 721         */
 722        public final void setReceiveBufferSize(long value) {
 723            base.setsockopt(zmq.ZMQ.ZMQ_RCVBUF, (int)value);
 724            mayRaiseNot (ZError.ETERM);
 725        }
 726        
 727        /**
 728         * The 'ZMQ_RCVMORE' option shall return a boolean value indicating if the multi-part
 729         * message currently being read from the specified 'socket' has more message parts to
 730         * follow. If there are no message parts to follow or if the message currently being read is
 731         * not a multi-part message a value of zero shall be returned. Otherwise, a value of 1 shall
 732         * be returned.
 733         * 
 734         * @return true if there are more messages to receive.
 735         */
 736        public final boolean hasReceiveMore () 
 737        {
 738            return base.getsockopt (zmq.ZMQ.ZMQ_RCVMORE) == 1;
 739        }
 740        
 741
 742        /**
 743         * The 'ZMQ_FD' option shall retrieve file descriptor associated with the 0MQ
 744         * socket. The descriptor can be used to integrate 0MQ socket into an existing
 745         * event loop. It should never be used for anything else than polling -- such as
 746         * reading or writing. The descriptor signals edge-triggered IN event when
 747         * something has happened within the 0MQ socket. It does not necessarily mean that
 748         * the messages can be read or written. Check ZMQ_EVENTS option to find out whether
 749         * the 0MQ socket is readable or writeable.
 750         * 
 751         * @return the underlying file descriptor.
 752         */
 753        public final SelectableChannel getFD() {
 754            return (SelectableChannel)base.getsockoptx(zmq.ZMQ.ZMQ_FD);
 755        }
 756        
 757        /**
 758         * The 'ZMQ_EVENTS' option shall retrieve event flags for the specified socket.
 759         * If a message can be read from the socket ZMQ_POLLIN flag is set. If message can
 760         * be written to the socket ZMQ_POLLOUT flag is set.
 761         * 
 762         * @return the mask of outstanding events.
 763         */
 764        public final int getEvents() {
 765            return base.getsockopt(zmq.ZMQ.ZMQ_EVENTS);
 766        }
 767        
 768
 769        /**
 770         * The 'ZMQ_SUBSCRIBE' option shall establish a new message filter on a 'ZMQ_SUB' socket.
 771         * Newly created 'ZMQ_SUB' sockets shall filter out all incoming messages, therefore you
 772         * should call this option to establish an initial message filter.
 773         * 
 774         * An empty 'option_value' of length zero shall subscribe to all incoming messages. A
 775         * non-empty 'option_value' shall subscribe to all messages beginning with the specified
 776         * prefix. Mutiple filters may be attached to a single 'ZMQ_SUB' socket, in which case a
 777         * message shall be accepted if it matches at least one filter.
 778         * 
 779         * @param topic
 780         */
 781        public final void subscribe(byte[] topic) {
 782            base.setsockopt(zmq.ZMQ.ZMQ_SUBSCRIBE, topic);
 783            mayRaiseNot (ZError.ETERM);
 784        }
 785        
 786
 787        /**
 788         * The 'ZMQ_UNSUBSCRIBE' option shall remove an existing message filter on a 'ZMQ_SUB'
 789         * socket. The filter specified must match an existing filter previously established with
 790         * the 'ZMQ_SUBSCRIBE' option. If the socket has several instances of the same filter
 791         * attached the 'ZMQ_UNSUBSCRIBE' option shall remove only one instance, leaving the rest in
 792         * place and functional.
 793         * 
 794         * @param topic
 795         */        
 796        public final void unsubscribe(byte[] topic) {
 797            base.setsockopt(zmq.ZMQ.ZMQ_UNSUBSCRIBE, topic);
 798            mayRaiseNot (ZError.ETERM);
 799        }
 800        
 801        /**
 802         * Set custom Encoder
 803         * @param cls
 804         */
 805        public final void setEncoder(Class<? extends EncoderBase> cls) {
 806            base.setsockopt(zmq.ZMQ.ZMQ_ENCODER, cls);
 807        }
 808        
 809        /**
 810         * Set custom Decoder
 811         * @param cls
 812         */
 813        public final void setDecoder(Class<? extends DecoderBase> cls) {
 814            base.setsockopt(zmq.ZMQ.ZMQ_DECODER, cls);
 815        }
 816
 817        /**
 818         * Sets the ROUTER socket behavior when an unroutable message is encountered.
 819         *
 820         * @param mandatory A value of false is the default and discards the message silently when it cannot be routed.
 821         *                  A value of true returns an EHOSTUNREACH error code if the message cannot be routed.
 822         */
 823        public final void setRouterMandatory (boolean mandatory) {
 824            base.setsockopt (zmq.ZMQ.ZMQ_ROUTER_MANDATORY, mandatory ? 1 : 0);
 825            mayRaiseNot (ZError.ETERM);
 826        }
 827
 828        /**
 829         * Sets the XPUB socket behavior on new subscriptions and unsubscriptions.
 830         *
 831         * @param verbose A value of false is the default and passes only new subscription messages to upstream.
 832         *                A value of true passes all subscription messages upstream.
 833         */
 834        public final void setXpubVerbose(boolean verbose) {
 835            base.setsockopt(zmq.ZMQ.ZMQ_XPUB_VERBOSE, verbose ? 1 : 0);
 836            mayRaiseNot (ZError.ETERM);
 837        }
 838
 839        /**
 840         * @see #setIPv4Only (boolean)
 841         *
 842         * @return the IPV4ONLY
 843         */
 844        public final boolean getIPv4Only () {
 845            return base.getsockopt (zmq.ZMQ.ZMQ_IPV4ONLY) == 1;
 846        }
 847
 848        /**
 849         * The 'ZMQ_IPV4ONLY' option shall set the underlying native socket type.
 850         * An IPv6 socket lets applications connect to and accept connections from both IPv4 and IPv6 hosts.
 851         *
 852         * @param v4only A value of true will use IPv4 sockets, while the value of false will use IPv6 sockets
 853         */
 854        public void setIPv4Only (boolean v4only) {
 855            base.setsockopt (zmq.ZMQ.ZMQ_IPV4ONLY, v4only ? 1 : 0);
 856            mayRaiseNot (ZError.ETERM);
 857        }
 858
 859        /**
 860         * @see #setTCPKeepAlive(int)
 861         *
 862         * @return the keep alive setting.
 863         */
 864        public int getTCPKeepAlive() {
 865
 866            return base.getsockopt(zmq.ZMQ.ZMQ_TCP_KEEPALIVE);
 867        }
 868
 869        /**
 870         * Override SO_KEEPALIVE socket option (where supported by OS) to enable keep-alive packets for a socket
 871         * connection. Possible values are -1, 0, 1. The default value -1 will skip all overrides and do the OS default.
 872         *
 873         * @param optVal The value of 'ZMQ_TCP_KEEPALIVE' to turn TCP keepalives on (1) or off (0).
 874         */
 875        public void setTCPKeepAlive(int optVal) {
 876            base.setsockopt(zmq.ZMQ.ZMQ_TCP_KEEPALIVE, (int)optVal);
 877            mayRaiseNot (ZError.ETERM);
 878        }
 879
 880        /**
 881         * Bind to network interface. Start listening for new connections.
 882         * 
 883         * @param addr
 884         *            the endpoint to bind to.
 885         */
 886        public final int bind (String addr) 
 887        {
 888            return bind (addr, DYNFROM, DYNTO);
 889        }
 890
 891        /**
 892         * Bind to network interface. Start listening for new connections.
 893         * 
 894         * @param addr
 895         *            the endpoint to bind to.
 896         * @param min
 897         *            The minimum port in the range of ports to try.
 898         * @param max
 899         *            The maximum port in the range of ports to try.
 900         */
 901        private final int bind (String addr, int min, int max) 
 902        {
 903            if (addr.endsWith (":*")) {
 904                int port = min;
 905                String prefix = addr.substring (0, addr.lastIndexOf (':') + 1);
 906                while (port <= max) {
 907                    addr = prefix + port;
 908                    //  Try to bind on the next plausible port
 909                    if (base.bind (addr))
 910                        return port;
 911                    port++;
 912                }
 913            } else {
 914                if (base.bind(addr)) {
 915                    int port = 0;
 916                    try {
 917                        port = Integer.parseInt (
 918                            addr.substring (addr.lastIndexOf (':') + 1));
 919                    } catch (NumberFormatException e) {
 920                    }
 921                    return port;
 922                }
 923            }
 924            mayRaise ();
 925            return -1;
 926        }
 927        
 928        /**
 929         * Bind to network interface to a random port. Start listening for new
 930         * connections.
 931         *
 932         * @param addr
 933         *            the endpoint to bind to.
 934         */
 935        public int bindToRandomPort (String addr) 
 936        {
 937            return bind (addr + ":*", DYNFROM, DYNTO);
 938        }
 939
 940        /**
 941         * Bind to network interface to a random port. Start listening for new
 942         * connections.
 943         *
 944         * @param addr
 945         *            the endpoint to bind to.
 946         * @param min
 947         *            The minimum port in the range of ports to try.
 948         * @param max
 949         *            The maximum port in the range of ports to try.
 950         */
 951        public int bindToRandomPort (String addr, int min, int max) 
 952        {
 953            return bind (addr + ":*", min, max);
 954        }
 955
 956        /**
 957         * Connect to remote application.
 958         * 
 959         * @param addr
 960         *            the endpoint to connect to.
 961         */
 962        public final void connect (String addr) {
 963            base.connect (addr);
 964            mayRaise ();
 965        }
 966
 967        /**
 968         * Disconnect to remote application.
 969         * 
 970         * @param addr
 971         *            the endpoint to disconnect to.
 972         */
 973        public final boolean disconnect (String addr) {
 974            boolean ret = base.term_endpoint (addr);
 975            mayRaise ();
 976            return ret;
 977        }
 978
 979        public final boolean send (String data) {
 980            return send (data.getBytes (), 0);
 981        }
 982        
 983        public final boolean sendMore (String data) {
 984            return send(data.getBytes (), zmq.ZMQ.ZMQ_SNDMORE);
 985        }
 986        
 987        public final boolean send (String data, int flags) {
 988            return send(data.getBytes (), flags);
 989        }
 990        
 991        public final boolean send (byte[] data) {
 992            return send(data, 0);
 993        }
 994        
 995        public final boolean sendMore (byte[] data) {
 996            return send(data, zmq.ZMQ.ZMQ_SNDMORE);
 997        }
 998
 999        
1000        public final boolean send (byte[] data, int flags) {
1001            zmq.Msg msg = new zmq.Msg(data);
1002            if (base.send(msg, flags))
1003                return true;
1004
1005            mayRaise ();
1006            return false;
1007        }
1008        
1009        /**
1010         * Receive a message.
1011         * 
1012         * @return the message received, as an array of bytes; null on error.
1013         */
1014        public final byte[] recv ()
1015        {
1016            return recv (0);
1017        }
1018        
1019        /**
1020         * Receive a message.
1021         * 
1022         * @param flags
1023         *            the flags to apply to the receive operation.
1024         * @return the message received, as an array of bytes; null on error.
1025         */
1026        public final byte[] recv (int flags)
1027        {
1028            zmq.Msg msg = base.recv(flags);
1029            
1030            if (msg != null) {
1031                return msg.data();
1032            }
1033            mayRaise ();
1034            
1035            return null;
1036        }
1037        
1038        /**
1039         * Receive a message in to a specified buffer.
1040         * 
1041         * @param buffer
1042         *            byte[] to copy zmq message payload in to.
1043         * @param offset
1044         *            offset in buffer to write data
1045         * @param len
1046         *            max bytes to write to buffer.  
1047         *            If len is smaller than the incoming message size, 
1048         *            the message will be truncated.
1049         * @param flags
1050         *            the flags to apply to the receive operation.
1051         * @return the number of bytes read, -1 on error
1052         */
1053        public final int recv (byte[] buffer, int offset, int len, int flags)
1054        {
1055            zmq.Msg msg = base.recv (flags);
1056            
1057            if (msg != null) {
1058                int size = Math.min (msg.size (), len);
1059                System.arraycopy (msg.data (), 0, buffer, offset, size);
1060                return size;
1061            }
1062
1063            mayRaise ();
1064            return -1;
1065        }
1066        
1067        /**
1068         * 
1069         * @return the message received, as a String object; null on no message.
1070         */
1071        public final String recvStr () {
1072            return recvStr (0);
1073        }
1074        
1075        /**
1076         * 
1077         * @param flags the flags to apply to the receive operation.
1078         * @return the message received, as a String object; null on no message.
1079         */
1080        public final String recvStr (int flags) 
1081        {
1082            byte [] msg = recv(flags);
1083            
1084            if (msg != null) {
1085                return new String (msg);
1086            }
1087
1088            return null;
1089        }
1090        
1091        public boolean monitor (String addr, int events) 
1092        {
1093            return base.monitor (addr, events);
1094        }
1095
1096    }
1097
1098    public static class Poller {
1099
1100        /**
1101         * These values can be ORed to specify what we want to poll for.
1102         */
1103        public static final int POLLIN = zmq.ZMQ.ZMQ_POLLIN;
1104        public static final int POLLOUT = zmq.ZMQ.ZMQ_POLLOUT;
1105        public static final int POLLERR = zmq.ZMQ.ZMQ_POLLERR;
1106        
1107        private static final int SIZE_DEFAULT = 32;
1108        private static final int SIZE_INCREMENT = 16;
1109        
1110        private PollItem [] items;
1111        private long timeout;
1112        private int next;
1113
1114        public Poller (int size) {
1115            this (null, size);
1116        }
1117
1118        /**
1119         * Class constructor.
1120         * 
1121         * @param context
1122         *            a 0MQ context previously created.
1123         * @param size
1124         *            the number of Sockets this poller will contain.
1125         */
1126        protected Poller (Context context, int size) {
1127            items = new PollItem[size];
1128            timeout = -1L;
1129            next = 0;
1130        }
1131
1132        /**
1133         * Class constructor.
1134         * 
1135         * @param context
1136         *            a 0MQ context previously created.
1137         */
1138        protected Poller (Context context) {
1139            this(context, SIZE_DEFAULT);
1140        }
1141        
1142        /**
1143         * Register a Socket for polling on all events.
1144         * 
1145         * @param socket
1146         *            the Socket we are registering.
1147         * @return the index identifying this Socket in the poll set.
1148         */
1149        public int register (Socket socket) {
1150            return register (socket, POLLIN | POLLOUT | POLLERR);
1151        }
1152        
1153        /**
1154         * Register a Socket for polling on the specified events.
1155         *
1156         * Automatically grow the internal representation if needed.
1157         * 
1158         * @param socket
1159         *            the Socket we are registering.
1160         * @param events
1161         *            a mask composed by XORing POLLIN, POLLOUT and POLLERR.
1162         * @return the index identifying this Socket in the poll set.
1163         */
1164        public int register (Socket socket, int events) {
1165
1166            return insert (new PollItem (socket, events));
1167        }
1168        
1169        /**
1170         * Register a Socket for polling on the specified events.
1171         *
1172         * Automatically grow the internal representation if needed.
1173         * 
1174         * @param channel
1175         *            the Channel we are registering.
1176         * @param events
1177         *            a mask composed by XORing POLLIN, POLLOUT and POLLERR.
1178         * @return the index identifying this Channel in the poll set.
1179         */
1180        public int register (SelectableChannel channel, int events) {
1181
1182            return insert (new PollItem (channel, events));
1183        }
1184
1185        /**
1186         * Register a Channel for polling on the specified events.
1187         *
1188         * Automatically grow the internal representation if needed.
1189         *
1190         * @param item
1191         *            the PollItem we are registering.
1192         * @return the index identifying this Channel in the poll set.
1193         */
1194        public int register (PollItem item) {
1195            return insert (item);
1196        }
1197
1198        private int insert (PollItem item)
1199        {
1200            int pos = next++;
1201            if (pos == items.length) {
1202                PollItem[] nitems = new PollItem[items.length + SIZE_INCREMENT];
1203                System.arraycopy (items, 0, nitems, 0, items.length);
1204                items = nitems;
1205            }
1206            items [pos] = item;
1207            return pos;
1208        }
1209        
1210        /**
1211         * Unregister a Socket for polling on the specified events.
1212         *
1213         * @param socket 
1214         *          the Socket to be unregistered
1215         */
1216        public void unregister (Socket socket) {
1217            for (int pos = 0; pos < items.length ;pos++) {
1218                PollItem item = items[pos];
1219                if (item.getSocket () == socket) {
1220                    remove (pos);
1221                    break;
1222                }
1223            }
1224        }
1225        
1226        /**
1227         * Unregister a Socket for polling on the specified events.
1228         *
1229         * @param channel 
1230         *          the Socket to be unregistered
1231         */
1232        public void unregister (SelectableChannel channel) {
1233            for (int pos = 0; pos < items.length ;pos++) {
1234                PollItem item = items[pos];
1235                if (item.getRawSocket () == channel) {
1236                    remove (pos);
1237                    break;
1238                }
1239            }
1240        }
1241
1242        private void remove (int pos)
1243        {
1244            next--;
1245            if (pos != next)
1246                items [pos] = items [next];
1247            items [next] = null;
1248        }
1249
1250        /**
1251         * Get the PollItem associated with an index.
1252         *
1253         * @param index
1254         *            the desired index.
1255         * @return the PollItem associated with that index (or null).
1256         */
1257        public PollItem getItem (int index)
1258        {
1259            if (index < 0 || index >= this.next)
1260                return null;
1261            return this.items[index];
1262        }
1263
1264        /**
1265         * Get the socket associated with an index.
1266         * 
1267         * @param index
1268         *            the desired index.
1269         * @return the Socket associated with that index (or null).
1270         */
1271        public Socket getSocket (int index) {
1272            if (index < 0 || index >= this.next)
1273                return null;
1274            return items[index].getSocket ();
1275        }
1276        
1277        /**
1278         * Get the current poll timeout.
1279         * 
1280         * @return the current poll timeout in milliseconds.
1281         * @deprecated Timeout handling has been moved to the poll() methods.
1282         */
1283        public long getTimeout () {
1284            return this.timeout;
1285        }
1286
1287        /**
1288         * Set the poll timeout.
1289         * 
1290         * @param timeout
1291         *            the desired poll timeout in milliseconds.
1292         * @deprecated Timeout handling has been moved to the poll() methods.
1293         */
1294        public void setTimeout (long timeout) {
1295            if (timeout < -1)
1296                return;
1297
1298            this.timeout = timeout;
1299        }
1300
1301        /**
1302         * Get the current poll set size.
1303         * 
1304         * @return the current poll set size.
1305         */
1306        public int getSize () {
1307            return items.length;
1308        }
1309
1310        /**
1311         * Get the index for the next position in the poll set size.
1312         * 
1313         * @return the index for the next position in the poll set size.
1314         */
1315        public int getNext () {
1316            return this.next;
1317        }
1318        
1319        /**
1320         * Issue a poll call. If the poller's internal timeout value
1321         * has been set, use that value as timeout; otherwise, block
1322         * indefinitely.
1323         * 
1324         * @return how many objects where signaled by poll ().
1325         */
1326        public int poll () {
1327            long tout = -1L;
1328            if (this.timeout > -1L) {
1329                tout = this.timeout;
1330            }
1331            return poll(tout);
1332        }
1333        
1334        /**
1335         * Issue a poll call, using the specified timeout value.
1336         * <p>
1337         * Since ZeroMQ 3.0, the timeout parameter is in <i>milliseconds<i>,
1338         * but prior to this the unit was <i>microseconds</i>.
1339         * 
1340         * @param tout
1341         *            the timeout, as per zmq_poll ();
1342         *            if -1, it will block indefinitely until an event
1343         *            happens; if 0, it will return immediately;
1344         *            otherwise, it will wait for at most that many
1345         *            milliseconds/microseconds (see above).
1346         *            
1347         * @see "http://api.zeromq.org/3-0:zmq-poll"
1348         *
1349         * @return how many objects where signaled by poll ()
1350         */
1351        public int poll(long tout) {
1352
1353            zmq.PollItem[] pollItems = new zmq.PollItem[next];
1354            for (int i = 0; i < next; i++)
1355                pollItems[i] = items[i].base ();
1356
1357            return zmq.ZMQ.zmq_poll (pollItems, next, tout);
1358        }
1359        
1360        /**
1361         * Check whether the specified element in the poll set was signaled for input.
1362         * 
1363         * @param index
1364         * 
1365         * @return true if the element was signaled.
1366         */
1367        public boolean pollin (int index) {
1368            if (index < 0 || index >= this.next) 
1369                return false;
1370            
1371            return items [index].isReadable(); 
1372        }
1373
1374        /**
1375         * Check whether the specified element in the poll set was signaled for output.
1376         * 
1377         * @param index
1378         * 
1379         * @return true if the element was signaled.
1380         */
1381        public boolean pollout (int index) {
1382            
1383            if (index < 0 || index >= this.next)
1384                return false;
1385            
1386            return items [index].isWritable ();
1387        }
1388
1389        /**
1390         * Check whether the specified element in the poll set was signaled for error.
1391         * 
1392         * @param index
1393         * 
1394         * @return true if the element was signaled.
1395         */
1396        public boolean pollerr (int index) {
1397            
1398            if (index < 0 || index >= this.next)
1399                return false;
1400            
1401            return items [index].isError();
1402        }
1403    }
1404    
1405    public static class PollItem {
1406
1407        private final zmq.PollItem base;
1408        private final Socket socket;
1409        
1410        public PollItem (Socket socket, int ops) {
1411            this.socket = socket;
1412            base = new zmq.PollItem (socket.base, ops);
1413        }
1414
1415        public PollItem (SelectableChannel channel, int ops) {
1416            base = new zmq.PollItem (channel, ops);
1417            socket = null;
1418        }
1419
1420        protected final zmq.PollItem base() {
1421            return base;
1422        }
1423
1424        public final SelectableChannel getRawSocket () {
1425            return base.getRawSocket ();
1426        }
1427
1428        public final Socket getSocket() {
1429            return socket;
1430        }
1431
1432        public final boolean isReadable() {
1433            return base.isReadable();
1434        }
1435
1436        public final boolean isWritable() {
1437            return base.isWritable ();
1438        }
1439
1440        public final boolean isError () {
1441            return base.isError ();
1442        }
1443
1444        public final int readyOps () {
1445            return base.readyOps ();
1446        }
1447
1448        @Override
1449        public boolean equals (Object obj)
1450        {
1451            if (!(obj instanceof PollItem))
1452                return false;
1453
1454            PollItem target = (PollItem) obj;
1455            if (socket != null && socket == target.socket)
1456                return true;
1457
1458            if (getRawSocket () != null && getRawSocket () == target.getRawSocket ())
1459                return true;
1460
1461            return false;
1462        }
1463    }
1464
1465    public enum Error {
1466        
1467        ENOTSUP(ZError.ENOTSUP),
1468        EPROTONOSUPPORT(ZError.EPROTONOSUPPORT),
1469        ENOBUFS(ZError.ENOBUFS),
1470        ENETDOWN(ZError.ENETDOWN),
1471        EADDRINUSE(ZError.EADDRINUSE),
1472        EADDRNOTAVAIL(ZError.EADDRNOTAVAIL),
1473        ECONNREFUSED(ZError.ECONNREFUSED),
1474        EINPROGRESS(ZError.EINPROGRESS),
1475        EMTHREAD(ZError.EMTHREAD),
1476        EFSM(ZError.EFSM),
1477        ENOCOMPATPROTO(ZError.ENOCOMPATPROTO),
1478        ETERM(ZError.ETERM);
1479
1480        private final long code;
1481
1482        Error(long code) {
1483            this.code = code;
1484        }
1485
1486        public long getCode() {
1487            return code;
1488        }
1489
1490        public static Error findByCode(int code) {
1491            for (Error e : Error.class.getEnumConstants()) {
1492                if (e.getCode() == code) {
1493                    return e;
1494                }
1495            }
1496            throw new IllegalArgumentException("Unknown " + Error.class.getName() + " enum code:" + code);
1497        }
1498    }
1499
1500    @Deprecated
1501    public static boolean device (int type_, Socket frontend, Socket backend)
1502    {
1503        return zmq.ZMQ.zmq_proxy (frontend.base, backend.base, null);
1504    }
1505
1506    /**
1507     * Starts the built-in ØM

Large files files are truncated, but you can click here to view the full file