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

/JAwaPI/src/org/jeromq/ZMQ.java

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

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