PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/zeromq/ZMQ.java

https://github.com/tfishwick/jzmq
Java | 1895 lines | 695 code | 251 blank | 949 comment | 87 complexity | 6ec720a53585c2ed38bfe9da2f3496e2 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, BSD-3-Clause-No-Nuclear-License-2014

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

  1. /*
  2. Copyright (c) 2007-2010 iMatix Corporation
  3. This file is part of 0MQ.
  4. 0MQ is free software; you can redistribute it and/or modify it under
  5. the terms of the Lesser GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. 0MQ is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. Lesser GNU General Public License for more details.
  12. You should have received a copy of the Lesser GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package org.zeromq;
  16. import java.io.Closeable;
  17. import java.nio.ByteBuffer;
  18. import java.nio.channels.SelectableChannel;
  19. import java.util.LinkedList;
  20. import java.util.Random;
  21. import java.util.concurrent.atomic.AtomicBoolean;
  22. /**
  23. * ZeroMQ JNI Bindings.
  24. *
  25. * @author Gonzalo Diethelm
  26. *
  27. */
  28. public class ZMQ {
  29. static {
  30. // if no embedded native library, revert to loading from java.library.path
  31. if (!EmbeddedLibraryTools.LOADED_EMBEDDED_LIBRARY)
  32. System.loadLibrary("jzmq");
  33. }
  34. // Values for flags in Socket's send and recv functions.
  35. /**
  36. * Socket flag to indicate a nonblocking send or recv mode.
  37. */
  38. public static final int NOBLOCK = 1;
  39. public static final int DONTWAIT = 1;
  40. /**
  41. * Socket flag to indicate that more message parts are coming.
  42. */
  43. public static final int SNDMORE = 2;
  44. // Socket types, used when creating a Socket.
  45. /**
  46. * Flag to specify a exclusive pair of items.
  47. */
  48. public static final int PAIR = 0;
  49. /**
  50. * Flag to specify a PUB socket, receiving side must be a SUB or XSUB.
  51. */
  52. public static final int PUB = 1;
  53. /**
  54. * Flag to specify the receiving part of the PUB or XPUB socket.
  55. */
  56. public static final int SUB = 2;
  57. /**
  58. * Flag to specify a REQ socket, receiving side must be a REP.
  59. */
  60. public static final int REQ = 3;
  61. /**
  62. * Flag to specify the receiving part of a REQ socket.
  63. */
  64. public static final int REP = 4;
  65. /**
  66. * Flag to specify a DEALER socket (aka XREQ). DEALER is really a combined ventilator / sink that does
  67. * load-balancing on output and fair-queuing on input with no other semantics. It is the only socket type that lets
  68. * you shuffle messages out to N nodes and shuffle the replies back, in a raw bidirectional asynch pattern.
  69. */
  70. public static final int DEALER = 5;
  71. /**
  72. * Old alias for DEALER flag. Flag to specify a XREQ socket, receiving side must be a XREP.
  73. *
  74. * @deprecated As of release 3.0 of zeromq, replaced by {@link #DEALER}
  75. */
  76. public static final int XREQ = DEALER;
  77. /**
  78. * Flag to specify ROUTER socket (aka XREP). ROUTER is the socket that creates and consumes request-reply routing
  79. * envelopes. It is the only socket type that lets you route messages to specific connections if you know their
  80. * identities.
  81. */
  82. public static final int ROUTER = 6;
  83. /**
  84. * Old alias for ROUTER flag. Flag to specify the receiving part of a XREQ socket.
  85. *
  86. * @deprecated As of release 3.0 of zeromq, replaced by {@link #ROUTER}
  87. */
  88. public static final int XREP = ROUTER;
  89. /**
  90. * Flag to specify the receiving part of a PUSH socket.
  91. */
  92. public static final int PULL = 7;
  93. /**
  94. * Flag to specify a PUSH socket, receiving side must be a PULL.
  95. */
  96. public static final int PUSH = 8;
  97. /**
  98. * Flag to specify a XPUB socket, receiving side must be a SUB or XSUB. Subscriptions can be received as a message.
  99. * Subscriptions start with a '1' byte. Unsubscriptions start with a '0' byte.
  100. */
  101. public static final int XPUB = 9;
  102. /**
  103. * Flag to specify the receiving part of the PUB or XPUB socket. Allows
  104. */
  105. public static final int XSUB = 10;
  106. /**
  107. * Flag to specify a STREAMER device.
  108. */
  109. public static final int STREAMER = 1;
  110. /**
  111. * Flag to specify a FORWARDER device.
  112. */
  113. public static final int FORWARDER = 2;
  114. /**
  115. * Flag to specify a QUEUE device.
  116. */
  117. public static final int QUEUE = 3;
  118. /**
  119. * @see ZMQ#PULL
  120. */
  121. @Deprecated
  122. public static final int UPSTREAM = PULL;
  123. /**
  124. * @see ZMQ#PUSH
  125. */
  126. @Deprecated
  127. public static final int DOWNSTREAM = PUSH;
  128. /**
  129. * @return Major version number of the ZMQ library.
  130. */
  131. public static int getMajorVersion() {
  132. return version_major();
  133. }
  134. /**
  135. * @return Major version number of the ZMQ library.
  136. */
  137. public static int getMinorVersion() {
  138. return version_minor();
  139. }
  140. /**
  141. * @return Major version number of the ZMQ library.
  142. */
  143. public static int getPatchVersion() {
  144. return version_patch();
  145. }
  146. /**
  147. * @return Full version number of the ZMQ library used for comparing versions.
  148. */
  149. public static int getFullVersion() {
  150. return version_full();
  151. }
  152. /**
  153. * @param major Version major component.
  154. * @param minor Version minor component.
  155. * @param patch Version patch component.
  156. *
  157. * @return Comparible single int version number.
  158. */
  159. public static int makeVersion(final int major, final int minor, final int patch) {
  160. return make_version(major, minor, patch);
  161. }
  162. /**
  163. * @return String version number in the form major.minor.patch.
  164. */
  165. public static String getVersionString() {
  166. return String.format("%d.%d.%d", version_major(), version_minor(), version_patch());
  167. }
  168. /**
  169. * Starts the built-in 0MQ proxy in the current application thread. The proxy connects a frontend socket to a
  170. * backend socket. Conceptually, data flows from frontend to backend. Depending on the socket types, replies may
  171. * flow in the opposite direction. The direction is conceptual only; the proxy is fully symmetric and there is no
  172. * technical difference between frontend and backend.
  173. *
  174. * Before calling ZMQ.proxy() you must set any socket options, and connect or bind both frontend and backend
  175. * sockets. The two conventional proxy models are:
  176. *
  177. * ZMQ.proxy() runs in the current thread and returns only if/when the current context is closed.
  178. *
  179. * @param frontend ZMQ.Socket
  180. * @param backend ZMQ.Socket
  181. * @param capture If the capture socket is not NULL, the proxy shall send all messages, received on both frontend
  182. * and backend, to the capture socket. The capture socket should be a ZMQ_PUB, ZMQ_DEALER, ZMQ_PUSH, or
  183. * ZMQ_PAIR socket.
  184. * @since 3.2.2
  185. */
  186. public static void proxy(Socket frontend, Socket backend, Socket capture) {
  187. if (ZMQ.version_full() < ZMQ.make_version(3, 2, 2))
  188. throw new UnsupportedOperationException();
  189. run_proxy(frontend, backend, capture);
  190. }
  191. /**
  192. * Poll on polling items until timeout
  193. *
  194. * @param items polling items
  195. * @param timeout timeout in millisecond
  196. * @return number of events
  197. */
  198. public static int poll(PollItem[] items, long timeout) {
  199. return poll(items, items.length, timeout);
  200. }
  201. /**
  202. * Poll on polling items until timeout
  203. *
  204. * @param items polling items
  205. * @param count active item count
  206. * @param timeout timeout in millisecond
  207. * @return number of events
  208. */
  209. public static int poll(PollItem[] items, int count, long timeout) {
  210. return Poller.run_poll(items, count, timeout);
  211. }
  212. protected static native int version_full();
  213. protected static native int version_major();
  214. protected static native int version_minor();
  215. protected static native int version_patch();
  216. protected static native int make_version(int major, int minor, int patch);
  217. protected static native long ENOTSUP();
  218. protected static native long EPROTONOSUPPORT();
  219. protected static native long ENOBUFS();
  220. protected static native long ENETDOWN();
  221. protected static native long EADDRINUSE();
  222. protected static native long EADDRNOTAVAIL();
  223. protected static native long ECONNREFUSED();
  224. protected static native long EINPROGRESS();
  225. protected static native long EHOSTUNREACH();
  226. protected static native long EMTHREAD();
  227. protected static native long EFSM();
  228. protected static native long ENOCOMPATPROTO();
  229. protected static native long ETERM();
  230. protected static native long ENOTSOCK();
  231. private static native void run_proxy(Socket frontend, Socket backend, Socket capture);
  232. /**
  233. * Inner class: Error.
  234. */
  235. public enum Error {
  236. ENOTSUP(ENOTSUP()),
  237. EPROTONOSUPPORT(EPROTONOSUPPORT()),
  238. ENOBUFS(ENOBUFS()),
  239. ENETDOWN(ENETDOWN()),
  240. EADDRINUSE(EADDRINUSE()),
  241. EADDRNOTAVAIL(EADDRNOTAVAIL()),
  242. ECONNREFUSED(ECONNREFUSED()),
  243. EINPROGRESS(EINPROGRESS()),
  244. EHOSTUNREACH(EHOSTUNREACH()),
  245. EMTHREAD(EMTHREAD()),
  246. EFSM(EFSM()),
  247. ENOCOMPATPROTO(ENOCOMPATPROTO()),
  248. ETERM(ETERM()),
  249. ENOTSOCK(ENOTSOCK());
  250. private final long code;
  251. Error(long code) {
  252. this.code = code;
  253. }
  254. public long getCode() {
  255. return code;
  256. }
  257. public static Error findByCode(int code) {
  258. for (Error e : Error.class.getEnumConstants()) {
  259. if (e.getCode() == code) {
  260. return e;
  261. }
  262. }
  263. throw new IllegalArgumentException("Unknown " + Error.class.getName() + " enum code:" + code);
  264. }
  265. }
  266. /**
  267. * Create a new Context.
  268. *
  269. * @param ioThreads Number of threads to use, usually 1 is sufficient for most use cases.
  270. * @return the Context
  271. */
  272. public static Context context(int ioThreads) {
  273. return new Context(ioThreads);
  274. }
  275. /**
  276. * Inner class: Context.
  277. */
  278. public static class Context implements Closeable {
  279. private final AtomicBoolean closed = new AtomicBoolean(false);
  280. /**
  281. * This is an explicit "destructor". It can be called to ensure the corresponding 0MQ Context has been disposed
  282. * of.
  283. */
  284. public void term() {
  285. if(closed.compareAndSet(false, true)) {
  286. destroy();
  287. }
  288. }
  289. /**
  290. * Create a new Socket within this context.
  291. *
  292. * @param type the socket type.
  293. * @return the newly created Socket.
  294. */
  295. public Socket socket(int type) {
  296. return new Socket(this, type);
  297. }
  298. /**
  299. * Create a new Poller within this context, with a default size.
  300. *
  301. * @return the newly created Poller.
  302. * @deprecated use Poller constructor
  303. */
  304. public Poller poller() {
  305. return new Poller(this);
  306. }
  307. /**
  308. * Create a new Poller within this context, with a specified initial size.
  309. *
  310. * @param size the poller initial size.
  311. * @return the newly created Poller.
  312. * @deprecated use Poller constructor
  313. */
  314. public Poller poller(int size) {
  315. return new Poller(this, size);
  316. }
  317. /**
  318. * Class constructor.
  319. *
  320. * @param ioThreads size of the threads pool to handle I/O operations.
  321. */
  322. protected Context(int ioThreads) {
  323. construct(ioThreads);
  324. }
  325. /** Initialize the JNI interface */
  326. protected native void construct(int ioThreads);
  327. /** Free all resources used by JNI interface. */
  328. protected native void destroy();
  329. /**
  330. * Get the underlying context handle. This is private because it is only accessed from JNI, where Java access
  331. * controls are ignored.
  332. *
  333. * @return the internal 0MQ context handle.
  334. */
  335. private long getContextHandle() {
  336. return this.contextHandle;
  337. }
  338. /** Opaque data used by JNI driver. */
  339. private long contextHandle;
  340. public void close() {
  341. term();
  342. }
  343. }
  344. /**
  345. * Inner class: Socket.
  346. */
  347. public static class Socket implements Closeable {
  348. private final AtomicBoolean closed = new AtomicBoolean(false);
  349. /**
  350. * This is an explicit "destructor". It can be called to ensure the corresponding 0MQ Socket has been disposed
  351. * of.
  352. */
  353. public void close() {
  354. if(closed.compareAndSet(false, true)) {
  355. destroy();
  356. }
  357. }
  358. /**
  359. * The 'ZMQ_TYPE option shall retrieve the socket type for the specified 'socket'. The socket type is specified
  360. * at socket creation time and cannot be modified afterwards.
  361. *
  362. * @return the socket type.
  363. * @since 2.1.0
  364. */
  365. public int getType() {
  366. if (ZMQ.version_full() < ZMQ.make_version(2, 1, 0))
  367. return -1;
  368. return (int) getLongSockopt(TYPE);
  369. }
  370. /**
  371. * @see #setLinger(long)
  372. *
  373. * @return the linger period.
  374. * @since 2.1.0
  375. */
  376. public long getLinger() {
  377. if (ZMQ.version_full() < ZMQ.make_version(2, 1, 0))
  378. return -1;
  379. return getLongSockopt(LINGER);
  380. }
  381. /**
  382. * @see #setReconnectIVL(long)
  383. *
  384. * @return the reconnectIVL.
  385. * @since 3.0.0
  386. */
  387. public long getReconnectIVL() {
  388. if (ZMQ.version_full() < ZMQ.make_version(2, 1, 10))
  389. return -1;
  390. return getLongSockopt(RECONNECT_IVL);
  391. }
  392. /**
  393. * @see #setBacklog(long)
  394. *
  395. * @return the backlog.
  396. * @since 3.0.0
  397. */
  398. public long getBacklog() {
  399. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  400. return -1;
  401. return getLongSockopt(BACKLOG);
  402. }
  403. /**
  404. * @see #setReconnectIVLMax(long)
  405. *
  406. * @return the reconnectIVLMax.
  407. * @since 3.0.0
  408. */
  409. public long getReconnectIVLMax() {
  410. if (ZMQ.version_full() < ZMQ.make_version(2, 1, 10))
  411. return -1;
  412. return getLongSockopt(RECONNECT_IVL_MAX);
  413. }
  414. /**
  415. * @see #setMaxMsgSize(long)
  416. *
  417. * @return the maxMsgSize.
  418. * @since 3.0.0
  419. */
  420. public long getMaxMsgSize() {
  421. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  422. return -1;
  423. return getLongSockopt(MAXMSGSIZE);
  424. }
  425. /**
  426. * @see #setSndHWM(long)
  427. *
  428. * @return the SndHWM.
  429. * @since 3.0.0
  430. */
  431. public long getSndHWM() {
  432. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  433. return -1;
  434. return getLongSockopt(SNDHWM);
  435. }
  436. /**
  437. * @see #setRcvHWM(long)
  438. *
  439. * @return the recvHWM period.
  440. * @since 3.0.0
  441. */
  442. public long getRcvHWM() {
  443. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  444. return -1;
  445. return getLongSockopt(RCVHWM);
  446. }
  447. /**
  448. * @see #setHWM(long)
  449. *
  450. * @return the High Water Mark.
  451. */
  452. public long getHWM() {
  453. if (ZMQ.version_full() >= ZMQ.make_version(3, 0, 0))
  454. return -1;
  455. return getLongSockopt(HWM);
  456. }
  457. /**
  458. * @see #setSwap(long)
  459. *
  460. * @return the number of messages to swap at most.
  461. */
  462. public long getSwap() {
  463. if (ZMQ.version_full() >= ZMQ.make_version(3, 0, 0))
  464. return -1;
  465. return getLongSockopt(SWAP);
  466. }
  467. /**
  468. * @see #setAffinity(long)
  469. *
  470. * @return the affinity.
  471. */
  472. public long getAffinity() {
  473. return getLongSockopt(AFFINITY);
  474. }
  475. /**
  476. * @see #setTCPKeepAlive(long)
  477. *
  478. * @return the keep alive setting.
  479. */
  480. public long getTCPKeepAliveSetting() {
  481. if (ZMQ.version_full() < ZMQ.make_version(3, 2, 0))
  482. return -1;
  483. return getLongSockopt(KEEPALIVE);
  484. }
  485. /**
  486. * @see #setTCPKeepAliveIdle(long)
  487. *
  488. * @return the keep alive idle value.
  489. */
  490. public long getTCPKeepAliveIdle() {
  491. if (ZMQ.version_full() < ZMQ.make_version(3, 2, 0))
  492. return -1;
  493. return getLongSockopt(KEEPALIVEIDLE);
  494. }
  495. /**
  496. * @see #setTCPKeepAliveInterval(long)
  497. *
  498. * @return the keep alive interval.
  499. */
  500. public long getTCPKeepAliveInterval() {
  501. if (ZMQ.version_full() < ZMQ.make_version(3, 2, 0))
  502. return -1;
  503. return getLongSockopt(KEEPALIVEINTVL);
  504. }
  505. /**
  506. * @see #setTCPKeepAliveCount(long)
  507. *
  508. * @return the keep alive count.
  509. */
  510. public long getTCPKeepAliveCount() {
  511. if (ZMQ.version_full() < ZMQ.make_version(3, 2, 0))
  512. return -1;
  513. return getLongSockopt(KEEPALIVECNT);
  514. }
  515. /**
  516. * @see #setIdentity(byte[])
  517. *
  518. * @return the Identitiy.
  519. */
  520. public byte[] getIdentity() {
  521. return getBytesSockopt(IDENTITY);
  522. }
  523. /**
  524. * @see #setRate(long)
  525. *
  526. * @return the Rate.
  527. */
  528. public long getRate() {
  529. return getLongSockopt(RATE);
  530. }
  531. /**
  532. * @see #setRecoveryInterval(long)
  533. *
  534. * @return the RecoveryIntervall.
  535. */
  536. public long getRecoveryInterval() {
  537. return getLongSockopt(RECOVERY_IVL);
  538. }
  539. /**
  540. * @see #setMulticastLoop(boolean)
  541. *
  542. * @return the Multicast Loop.
  543. */
  544. public boolean hasMulticastLoop() {
  545. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  546. return false;
  547. return getLongSockopt(MCAST_LOOP) != 0;
  548. }
  549. /**
  550. * Sets the time-to-live field in every multicast packet sent from this socket. The default is 1 which means
  551. * that the multicast packets don't leave the local network.
  552. *
  553. * @param mcast_hops
  554. */
  555. public void setMulticastHops(long mcast_hops) {
  556. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  557. return;
  558. setLongSockopt(MULTICAST_HOPS, mcast_hops);
  559. }
  560. /**
  561. * @see #setMulticastHops(long)
  562. *
  563. * @return the Multicast Hops.
  564. */
  565. public long getMulticastHops() {
  566. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  567. return 1;
  568. return getLongSockopt(MULTICAST_HOPS);
  569. }
  570. /**
  571. * Sets the timeout for receive operation on the socket. If the value is 0, recv will return immediately, with a
  572. * EAGAIN error if there is no message to receive. If the value is -1, it will block until a message is
  573. * available. For all other values, it will wait for a message for that amount of time before returning with an
  574. * EAGAIN error.
  575. *
  576. * @param timeout Timeout for receive operation in milliseconds. Default -1 (infinite)
  577. */
  578. public void setReceiveTimeOut(int timeout) {
  579. if (ZMQ.version_full() < ZMQ.make_version(2, 2, 0))
  580. return;
  581. setLongSockopt(RCVTIMEO, timeout);
  582. }
  583. /**
  584. * @see #setReceiveTimeOut(long)
  585. *
  586. * @return the Receive Timeout in milliseconds
  587. */
  588. public int getReceiveTimeOut() {
  589. if (ZMQ.version_full() < ZMQ.make_version(2, 2, 0))
  590. return -1;
  591. return (int) getLongSockopt(RCVTIMEO);
  592. }
  593. /**
  594. * Sets the timeout for send operation on the socket. If the value is 0, send will return immediately, with a
  595. * EAGAIN error if the message cannot be sent. If the value is -1, it will block until the message is sent. For
  596. * all other values, it will try to send the message for that amount of time before returning with an EAGAIN
  597. * error.
  598. *
  599. * @param timeout Timeout for send operation in milliseconds. Default -1 (infinite)
  600. */
  601. public void setSendTimeOut(int timeout) {
  602. if (ZMQ.version_full() < ZMQ.make_version(2, 2, 0))
  603. return;
  604. setLongSockopt(SNDTIMEO, timeout);
  605. }
  606. /**
  607. * @see #setSendTimeOut(long)
  608. *
  609. * @return the Send Timeout. in milliseconds
  610. */
  611. public int getSendTimeOut() {
  612. if (ZMQ.version_full() < ZMQ.make_version(2, 2, 0))
  613. return -1;
  614. return (int) getLongSockopt(SNDTIMEO);
  615. }
  616. /**
  617. * @see #setSendBufferSize(long)
  618. *
  619. * @return the kernel send buffer size.
  620. */
  621. public long getSendBufferSize() {
  622. return getLongSockopt(SNDBUF);
  623. }
  624. /**
  625. * @see #setReceiveBufferSize(long)
  626. *
  627. * @return the kernel receive buffer size.
  628. */
  629. public long getReceiveBufferSize() {
  630. return getLongSockopt(RCVBUF);
  631. }
  632. /**
  633. * @see #setIPv4only(long)
  634. *
  635. * @return the IPv4 only socket.
  636. */
  637. public boolean getIPv4Only() {
  638. return getLongSockopt(IPV4ONLY) == 1;
  639. }
  640. /**
  641. * The 'ZMQ_RCVMORE' option shall return a boolean value indicating if the multi-part message currently being
  642. * read from the specified 'socket' has more message parts to follow. If there are no message parts to follow or
  643. * if the message currently being read is not a multi-part message a value of zero shall be returned. Otherwise,
  644. * a value of 1 shall be returned.
  645. *
  646. * @return true if there are more messages to receive.
  647. */
  648. public boolean hasReceiveMore() {
  649. return getLongSockopt(RCVMORE) != 0;
  650. }
  651. /**
  652. * The 'ZMQ_FD' option shall retrieve file descriptor associated with the 0MQ socket. The descriptor can be used
  653. * to integrate 0MQ socket into an existing event loop. It should never be used for anything else than polling
  654. * -- such as reading or writing. The descriptor signals edge-triggered IN event when something has happened
  655. * within the 0MQ socket. It does not necessarily mean that the messages can be read or written. Check
  656. * ZMQ_EVENTS option to find out whether the 0MQ socket is readable or writeable.
  657. *
  658. * @return the underlying file descriptor.
  659. * @since 2.1.0
  660. */
  661. public long getFD() {
  662. if (ZMQ.version_full() < ZMQ.make_version(2, 1, 0))
  663. return -1;
  664. return getLongSockopt(FD);
  665. }
  666. /**
  667. * The 'ZMQ_EVENTS' option shall retrieve event flags for the specified socket. If a message can be read from
  668. * the socket ZMQ_POLLIN flag is set. If message can be written to the socket ZMQ_POLLOUT flag is set.
  669. *
  670. * @return the mask of outstanding events.
  671. * @since 2.1.0
  672. */
  673. public long getEvents() {
  674. if (ZMQ.version_full() < ZMQ.make_version(2, 1, 0))
  675. return -1;
  676. return getLongSockopt(EVENTS);
  677. }
  678. /**
  679. * The 'ZMQ_LINGER' option shall retrieve the period for pending outbound messages to linger in memory after
  680. * closing the socket. Value of -1 means infinite. Pending messages will be kept until they are fully
  681. * transferred to the peer. Value of 0 means that all the pending messages are dropped immediately when socket
  682. * is closed. Positive value means number of milliseconds to keep trying to send the pending messages before
  683. * discarding them.
  684. *
  685. * @param linger the linger period.
  686. * @since 2.1.0
  687. */
  688. public void setLinger(long linger) {
  689. if (ZMQ.version_full() < ZMQ.make_version(2, 1, 0))
  690. return;
  691. setLongSockopt(LINGER, linger);
  692. }
  693. /**
  694. * @since 3.0.0
  695. */
  696. public void setReconnectIVL(long reconnectIVL) {
  697. if (ZMQ.version_full() < ZMQ.make_version(2, 1, 10))
  698. return;
  699. setLongSockopt(RECONNECT_IVL, reconnectIVL);
  700. }
  701. /**
  702. * @since 3.0.0
  703. */
  704. public void setBacklog(long backlog) {
  705. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  706. return;
  707. setLongSockopt(BACKLOG, backlog);
  708. }
  709. /**
  710. * @since 3.0.0
  711. */
  712. public void setReconnectIVLMax(long reconnectIVLMax) {
  713. if (ZMQ.version_full() < ZMQ.make_version(2, 1, 10))
  714. return;
  715. setLongSockopt(RECONNECT_IVL_MAX, reconnectIVLMax);
  716. }
  717. /**
  718. * @since 3.0.0
  719. */
  720. public void setMaxMsgSize(long maxMsgSize) {
  721. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  722. return;
  723. setLongSockopt(MAXMSGSIZE, maxMsgSize);
  724. }
  725. /**
  726. * @since 3.0.0
  727. */
  728. public void setSndHWM(long sndHWM) {
  729. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  730. return;
  731. setLongSockopt(SNDHWM, sndHWM);
  732. }
  733. /**
  734. * @since 3.0.0
  735. */
  736. public void setRcvHWM(long rcvHWM) {
  737. if (ZMQ.version_full() < ZMQ.make_version(3, 0, 0))
  738. return;
  739. setLongSockopt(RCVHWM, rcvHWM);
  740. }
  741. /**
  742. * The 'ZMQ_HWM' option shall set the high water mark for the specified 'socket'. The high water mark is a hard
  743. * limit on the maximum number of outstanding messages 0MQ shall queue in memory for any single peer that the
  744. * specified 'socket' is communicating with.
  745. *
  746. * If this limit has been reached the socket shall enter an exceptional state and depending on the socket type,
  747. * 0MQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket
  748. * descriptions in the man page of zmq_socket[3] for details on the exact action taken for each socket type.
  749. *
  750. * @param hwm the number of messages to queue.
  751. */
  752. public void setHWM(long hwm) {
  753. if (ZMQ.version_full() >= ZMQ.make_version(3, 0, 0))
  754. return;
  755. setLongSockopt(HWM, hwm);
  756. }
  757. /**
  758. * Get the Swap. The 'ZMQ_SWAP' option shall set the disk offload (swap) size for the specified 'socket'. A
  759. * socket which has 'ZMQ_SWAP' set to a non-zero value may exceed its high water mark; in this case outstanding
  760. * messages shall be offloaded to storage on disk rather than held in memory.
  761. *
  762. * @param swap The value of 'ZMQ_SWAP' defines the maximum size of the swap space in bytes.
  763. */
  764. public void setSwap(long swap) {
  765. if (ZMQ.version_full() >= ZMQ.make_version(3, 0, 0))
  766. return;
  767. setLongSockopt(SWAP, swap);
  768. }
  769. /**
  770. * Get the Affinity. The 'ZMQ_AFFINITY' option shall set the I/O thread affinity for newly created connections
  771. * on the specified 'socket'.
  772. *
  773. * Affinity determines which threads from the 0MQ I/O thread pool associated with the socket's _context_ shall
  774. * handle newly created connections. A value of zero specifies no affinity, meaning that work shall be
  775. * distributed fairly among all 0MQ I/O threads in the thread pool. For non-zero values, the lowest bit
  776. * corresponds to thread 1, second lowest bit to thread 2 and so on. For example, a value of 3 specifies that
  777. * subsequent connections on 'socket' shall be handled exclusively by I/O threads 1 and 2.
  778. *
  779. * See also in the man page of zmq_init[3] for details on allocating the number of I/O threads for a specific
  780. * _context_.
  781. *
  782. * @param affinity the affinity.
  783. */
  784. public void setAffinity(long affinity) {
  785. setLongSockopt(AFFINITY, affinity);
  786. }
  787. /**
  788. * Override SO_KEEPALIVE socket option (where supported by OS) to enable keep-alive packets for a socket
  789. * connection. Possible values are -1, 0, 1. The default value -1 will skip all overrides and do the OS default.
  790. *
  791. * @param optVal The value of 'ZMQ_TCP_KEEPALIVE' to turn TCP keepalives on (1) or off (0).
  792. */
  793. public void setTCPKeepAlive(long optVal) {
  794. if (ZMQ.version_full() >= ZMQ.make_version(3, 2, 0))
  795. setLongSockopt(KEEPALIVE, optVal);
  796. }
  797. /**
  798. * Override TCP_KEEPCNT socket option (where supported by OS). The default value -1 will skip all overrides and
  799. * do the OS default.
  800. *
  801. * @param optVal The value of 'ZMQ_TCP_KEEPALIVE_CNT' defines the number of keepalives before death.
  802. */
  803. public void setTCPKeepAliveCount(long optVal) {
  804. if (ZMQ.version_full() >= ZMQ.make_version(3, 2, 0))
  805. setLongSockopt(KEEPALIVECNT, optVal);
  806. }
  807. /**
  808. * Override TCP_KEEPINTVL socket option (where supported by OS). The default value -1 will skip all overrides
  809. * and do the OS default.
  810. *
  811. * @param optVal The value of 'ZMQ_TCP_KEEPALIVE_INTVL' defines the interval between keepalives. Unit is OS
  812. * dependant.
  813. */
  814. public void setTCPKeepAliveInterval(long optVal) {
  815. if (ZMQ.version_full() >= ZMQ.make_version(3, 2, 0))
  816. setLongSockopt(KEEPALIVEINTVL, optVal);
  817. }
  818. /**
  819. * Override TCP_KEEPCNT (or TCP_KEEPALIVE on some OS) socket option (where supported by OS). The default value
  820. * -1 will skip all overrides and do the OS default.
  821. *
  822. * @param optVal The value of 'ZMQ_TCP_KEEPALIVE_IDLE' defines the interval between the last data packet sent
  823. * over the socket and the first keepalive probe. Unit is OS dependant.
  824. */
  825. public void setTCPKeepAliveIdle(long optVal) {
  826. if (ZMQ.version_full() >= ZMQ.make_version(3, 2, 0))
  827. setLongSockopt(KEEPALIVEIDLE, optVal);
  828. }
  829. /**
  830. * The 'ZMQ_IDENTITY' option shall set the identity of the specified 'socket'. Socket identity determines if
  831. * existing 0MQ infastructure (_message queues_, _forwarding devices_) shall be identified with a specific
  832. * application and persist across multiple runs of the application.
  833. *
  834. * If the socket has no identity, each run of an application is completely separate from other runs. However,
  835. * with identity set the socket shall re-use any existing 0MQ infrastructure configured by the previous run(s).
  836. * Thus the application may receive messages that were sent in the meantime, _message queue_ limits shall be
  837. * shared with previous run(s) and so on.
  838. *
  839. * Identity should be at least one byte and at most 255 bytes long. Identities starting with binary zero are
  840. * reserved for use by 0MQ infrastructure.
  841. *
  842. * @param identity
  843. */
  844. public void setIdentity(byte[] identity) {
  845. setBytesSockopt(IDENTITY, identity);
  846. }
  847. /**
  848. * The 'ZMQ_SUBSCRIBE' option shall establish a new message filter on a 'ZMQ_SUB' socket. Newly created
  849. * 'ZMQ_SUB' sockets shall filter out all incoming messages, therefore you should call this option to establish
  850. * an initial message filter.
  851. *
  852. * An empty 'option_value' of length zero shall subscribe to all incoming messages. A non-empty 'option_value'
  853. * shall subscribe to all messages beginning with the specified prefix. Mutiple filters may be attached to a
  854. * single 'ZMQ_SUB' socket, in which case a message shall be accepted if it matches at least one filter.
  855. *
  856. * @param topic
  857. */
  858. public void subscribe(byte[] topic) {
  859. setBytesSockopt(SUBSCRIBE, topic);
  860. }
  861. /**
  862. * The 'ZMQ_UNSUBSCRIBE' option shall remove an existing message filter on a 'ZMQ_SUB' socket. The filter
  863. * specified must match an existing filter previously established with the 'ZMQ_SUBSCRIBE' option. If the socket
  864. * has several instances of the same filter attached the 'ZMQ_UNSUBSCRIBE' option shall remove only one
  865. * instance, leaving the rest in place and functional.
  866. *
  867. * @param topic
  868. */
  869. public void unsubscribe(byte[] topic) {
  870. setBytesSockopt(UNSUBSCRIBE, topic);
  871. }
  872. /**
  873. * The 'ZMQ_RATE' option shall set the maximum send or receive data rate for multicast transports such as in the
  874. * man page of zmq_pgm[7] using the specified 'socket'.
  875. *
  876. * @param rate
  877. */
  878. public void setRate(long rate) {
  879. setLongSockopt(RATE, rate);
  880. }
  881. /**
  882. * The 'ZMQ_RECOVERY_IVL' option shall set the recovery interval for multicast transports using the specified
  883. * 'socket'. The recovery interval determines the maximum time in seconds (before version 3.0.0) or milliseconds
  884. * (version 3.0.0 and after) that a receiver can be absent from a multicast group before unrecoverable data loss
  885. * will occur.
  886. *
  887. * CAUTION: Exercise care when setting large recovery intervals as the data needed for recovery will be held in
  888. * memory. For example, a 1 minute recovery interval at a data rate of 1Gbps requires a 7GB in-memory buffer.
  889. * {Purpose of this Method}
  890. *
  891. * @param recovery_ivl
  892. */
  893. public void setRecoveryInterval(long recovery_ivl) {
  894. setLongSockopt(RECOVERY_IVL, recovery_ivl);
  895. }
  896. /**
  897. * The 'ZMQ_MCAST_LOOP' option shall control whether data sent via multicast transports using the specified
  898. * 'socket' can also be received by the sending host via loopback. A value of zero disables the loopback
  899. * functionality, while the default value of 1 enables the loopback functionality. Leaving multicast loopback
  900. * enabled when it is not required can have a negative impact on performance. Where possible, disable
  901. * 'ZMQ_MCAST_LOOP' in production environments.
  902. *
  903. * @param mcast_loop
  904. */
  905. public void setMulticastLoop(boolean mcast_loop) {
  906. if (ZMQ.version_full() >= ZMQ.make_version(3, 0, 0))
  907. return;
  908. setLongSockopt(MCAST_LOOP, mcast_loop ? 1 : 0);
  909. }
  910. /**
  911. * The 'ZMQ_SNDBUF' option shall set the underlying kernel transmit buffer size for the 'socket' to the
  912. * specified size in bytes. A value of zero means leave the OS default unchanged. For details please refer to
  913. * your operating system documentation for the 'SO_SNDBUF' socket option.
  914. *
  915. * @param sndbuf
  916. */
  917. public void setSendBufferSize(long sndbuf) {
  918. setLongSockopt(SNDBUF, sndbuf);
  919. }
  920. /**
  921. * The 'ZMQ_RCVBUF' option shall set the underlying kernel receive buffer size for the 'socket' to the specified
  922. * size in bytes. A value of zero means leave the OS default unchanged. For details refer to your operating
  923. * system documentation for the 'SO_RCVBUF' socket option.
  924. *
  925. * @param rcvbuf
  926. */
  927. public void setReceiveBufferSize(long rcvbuf) {
  928. setLongSockopt(RCVBUF, rcvbuf);
  929. }
  930. /**
  931. * The 'ZMQ_IPV4ONLY' option shall set the underlying native socket type. An IPv6 socket lets applications
  932. * connect to and accept connections from both IPv4 and IPv6 hosts.
  933. *
  934. * @param v4only A value of true will use IPv4 sockets, while the value of false will use IPv6 sockets
  935. */
  936. public void setIPv4Only(boolean v4only) {
  937. setLongSockopt(IPV4ONLY, v4only ? 1L : 0L);
  938. }
  939. /**
  940. * Sets the ROUTER socket behavior when an unroutable message is encountered.
  941. *
  942. * @param mandatory A value of false is the default and discards the message silently when it cannot be routed.
  943. * A value of true returns an EHOSTUNREACH error code if the message cannot be routed.
  944. */
  945. public void setRouterMandatory(boolean mandatory) {
  946. setLongSockopt(ROUTER_MANDATORY, mandatory ? 1L : 0L);
  947. }
  948. /**
  949. * Sets the XPUB socket behavior on new subscriptions and unsubscriptions.
  950. *
  951. * @param verbose A value of false is the default and passes only new subscription messages to upstream.
  952. * A value of true passes all subscription messages upstream.
  953. * @since 3.2.2
  954. */
  955. public void setXpubVerbose(boolean verbose) {
  956. if (ZMQ.version_full() < ZMQ.make_version(3, 2, 2))
  957. return;
  958. setLongSockopt(XPUB_VERBOSE, verbose ? 1L : 0L);
  959. }
  960. /**
  961. * Bind to network interface. Start listening for new connections.
  962. *
  963. * @param addr the endpoint to bind to.
  964. */
  965. public native void bind(String addr);
  966. /**
  967. * Bind to network interface to a random port. Start listening for new connections.
  968. *
  969. * @param addr the endpoint to bind to.
  970. */
  971. public int bindToRandomPort(String addr) {
  972. return bindToRandomPort(addr, 2000, 20000, 100);
  973. }
  974. /**
  975. * Bind to network interface to a random port. Start listening for new connections.
  976. *
  977. * @param addr the endpoint to bind to.
  978. * @param min_port The minimum port in the range of ports to try.
  979. */
  980. public int bindToRandomPort(String addr, int min_port) {
  981. return bindToRandomPort(addr, min_port, 20000, 100);
  982. }
  983. /**
  984. * Bind to network interface to a random port. Start listening for new connections.
  985. *
  986. * @param addr the endpoint to bind to.
  987. * @param min_port The minimum port in the range of ports to try.
  988. * @param max_port The maximum port in the range of ports to try.
  989. */
  990. public int bindToRandomPort(String addr, int min_port, int max_port) {
  991. return bindToRandomPort(addr, min_port, max_port, 100);
  992. }
  993. /**
  994. * Bind to network interface to a random port. Start listening for new connections.
  995. *
  996. * @param addr the endpoint to bind to.
  997. * @param min_port The minimum port in the range of ports to try.
  998. * @param max_port The maximum port in the range of ports to try.
  999. * @param max_tries The number of attempt to bind.
  1000. */
  1001. public int bindToRandomPort(String addr, int min_port, int max_port, int max_tries) {
  1002. int port;
  1003. Random rand = new Random();
  1004. for (int i = 0; i < max_tries; i++) {
  1005. port = rand.nextInt(max_port - min_port + 1) + min_port;
  1006. try {
  1007. bind(String.format("%s:%s", addr, port));
  1008. return port;
  1009. } catch (ZMQException e) {
  1010. if (e.getErrorCode() != ZMQ.EADDRINUSE()) {
  1011. throw e;
  1012. }
  1013. continue;
  1014. }
  1015. }
  1016. throw new ZMQException("Could not bind socket to random port.", (int) ZMQ.EADDRINUSE());
  1017. }
  1018. /**
  1019. * Unbind from network interface. Stop listening for connections.
  1020. *
  1021. * @param addr the endpoint to unbind from.
  1022. */
  1023. public native void unbind(String addr);
  1024. /**
  1025. * Connect to remote application.
  1026. *
  1027. * @param addr the endpoint to connect to.
  1028. */
  1029. public native void connect(String addr);
  1030. /**
  1031. * Disconnect from a remote application.
  1032. *
  1033. * @param addr the endpoint to disconnect from.
  1034. */
  1035. public native void disconnect(String addr);
  1036. /**
  1037. * Send a message.
  1038. *
  1039. * @param msg the message to send, as an array of bytes.
  1040. * @param offset the offset of the message to send.
  1041. * @param flags the flags to apply to the send operation.
  1042. * @return true if send was successful, false otherwise.
  1043. */
  1044. public boolean send(byte[] msg, int offset, int flags) {
  1045. return send(msg, offset, msg.length, flags);
  1046. }
  1047. /**
  1048. *
  1049. * @param msg
  1050. * @param offset
  1051. * @param len
  1052. * @param flags
  1053. * @return
  1054. */
  1055. public native boolean send(byte[] msg, int offset, int len, int flags);
  1056. /**
  1057. * Perform a zero copy send. The buffer must be allocated using ByteBuffer.allocateDirect
  1058. *
  1059. * @param buffer
  1060. * @param len
  1061. * @param flags
  1062. * @return
  1063. */
  1064. public native boolean sendZeroCopy(ByteBuffer buffer, int len, int flags);
  1065. /**
  1066. * Send a message.
  1067. *
  1068. * @param msg the message to send, as an array of bytes.
  1069. * @param flags the flags to apply to the send operation.
  1070. * @return true if send was successful, false otherwise.
  1071. */
  1072. public boolean send(byte[] msg, int flags) {
  1073. return send(msg, 0, msg.length, flags);
  1074. }
  1075. /**
  1076. * Send a String.
  1077. *
  1078. * @param msg the message to send, as a String.
  1079. * @return true if send was successful, false otherwise.
  1080. */
  1081. public boolean send(String msg) {
  1082. byte[] b = msg.getBytes();
  1083. return send(b, 0, b.length, 0);
  1084. }
  1085. /**
  1086. * Send a String.
  1087. *
  1088. * @param msg the message to send, as a String.
  1089. * @return true if send was successful, false otherwise.
  1090. */
  1091. public boolean sendMore(String msg) {
  1092. byte[] b = msg.getBytes();
  1093. return send(b, 0, b.length, SNDMORE);
  1094. }
  1095. /**
  1096. * Send a String.
  1097. *
  1098. * @param msg the message to send, as a String.
  1099. * @param flags the flags to apply to the send operation.
  1100. * @return true if send was successful, false otherwise.
  1101. */
  1102. public boolean send(String msg, int flags) {
  1103. byte[] b = msg.getBytes();
  1104. return send(b, 0, b.length, flags);
  1105. }
  1106. /**
  1107. * Send a message
  1108. *
  1109. * @param bb ByteBuffer payload
  1110. * @param flags the flags to apply to the send operation
  1111. * @return the number of bytes sent
  1112. */
  1113. public native int sendByteBuffer(ByteBuffer bb, int flags);
  1114. /**
  1115. * Receive a message.
  1116. *
  1117. * @param flags the flags to apply to the receive operation.
  1118. * @return the message received, as an array of bytes; null on error.
  1119. */
  1120. public native byte[] recv(int flags);
  1121. /**
  1122. * Receive a message in to a specified buffer.
  1123. *
  1124. * @param buffer byte[] to copy zmq message payload in to.
  1125. * @param offset offset in buffer to write data
  1126. * @param len max bytes to write to buffer. If len is smaller than the incoming message size, the message will
  1127. * be truncated.
  1128. * @param flags the flags to apply to the receive operation.
  1129. * @return the number of bytes read, -1 on error
  1130. */
  1131. public native int recv(byte[] buffer, int offset, int len, int flags);
  1132. /**
  1133. * Zero copy recv
  1134. *
  1135. * @param buffer
  1136. * @param len
  1137. * @param flags
  1138. * @return bytes read, -1 on error
  1139. */
  1140. public native int recvZeroCopy(ByteBuffer buffer, int len, int flags);
  1141. /**
  1142. * Receive a message.
  1143. *
  1144. * @return the message received, as an array of bytes; null on error.
  1145. */
  1146. public final byte[] recv() {
  1147. return recv(0);
  1148. }
  1149. /**
  1150. * Receive a message as a String.
  1151. *
  1152. * @return the message received, as a String; null on error.
  1153. */
  1154. public String recvStr() {
  1155. return recvStr(0);
  1156. }
  1157. /**
  1158. * Receive a message as a String.
  1159. *
  1160. * @param flags the flags to apply to the receive operation.
  1161. * @return the message received, as a String; null on error.
  1162. */
  1163. public String recvStr(int flags) {
  1164. byte[] data = recv(flags);
  1165. if (data == null)
  1166. return null;
  1167. return new String(data);
  1168. }
  1169. /**
  1170. * Receive a message
  1171. *
  1172. * @param buffer
  1173. * @param flags
  1174. * @return bytes read, -1 on error
  1175. */
  1176. public native int recvByteBuffer(ByteBuffer buffer, int flags);
  1177. /**
  1178. * Class constructor.
  1179. *
  1180. * @param context a 0MQ context previously created.
  1181. * @param type the socket type.
  1182. */
  1183. protected Socket(Context context, int type) {
  1184. // We keep a local handle to context so that
  1185. // garbage collection won't be too greedy on it.
  1186. this.context = context;
  1187. construct(context, type);
  1188. }
  1189. /** Initialize the JNI interface */
  1190. protected native void construct(Context ctx, int type);
  1191. /** Free all resources used by JNI interface. */
  1192. protected native void destroy();
  1193. /**
  1194. * Get the socket option value, as a long.
  1195. *
  1196. * @param option ID of the option to set.
  1197. * @return The socket option value (as a long).
  1198. */
  1199. protected native long getLongSockopt(int option);
  1200. /**
  1201. * Get the socket option value, as a byte array.
  1202. *
  1203. * @param option ID of the option to set.
  1204. * @return The socket option value (as a byte array).
  1205. */
  1206. protected native byte[] getBytesSockopt(int option);
  1207. /**
  1208. * Set the socket option value, given as a long.
  1209. *
  1210. * @param option ID of the option to set.
  1211. * @param optval value (as a long) to set the option to.
  1212. */
  1213. protected native void setLongSockopt(int option, long optval);
  1214. /**
  1215. * Set the socket option value, given as a byte array.
  1216. *
  1217. * @param option ID of the option to set.
  1218. * @param optval value (as a byte array) to set the option to.
  1219. */
  1220. protected native void setBytesSockopt(int option, byte[] optval);
  1221. /**
  1222. * Get the underlying socket handle. This is private because it is only accessed from JNI, where Java access
  1223. * controls are ignored.
  1224. *
  1225. * @return the internal 0MQ socket handle.
  1226. */
  1227. private long getSocketHandle() {
  1228. return this.socketHandle;
  1229. }
  1230. /** Opaque data used by JNI driver. */
  1231. private long socketHandle;
  1232. private Context context = null;
  1233. // private Constants use the appropriate setter instead.
  1234. private static final int HWM = 1;
  1235. // public static final int LWM = 2; // No longer supported
  1236. private static final int SWAP = 3;
  1237. private static final int AFFINITY = 4;
  1238. private static final int IDENTITY = 5;
  1239. private static final int SUBSCRIBE = 6;
  1240. private static final int UNSUBSCRIBE = 7;
  1241. private static final int RATE = 8;
  1242. private static final int RECOVERY_IVL = 9;
  1243. private static final int MCAST_LOOP = 10;
  1244. private static final int SNDBUF = 11;
  1245. private static final int RCVBUF = 12;
  1246. private static final int RCVMORE = 13;
  1247. private static final int FD = 14;
  1248. private static final int EVENTS = 15;
  1249. private static final int TYPE = 16;
  1250. private static final int LINGER = 17;
  1251. private static final int RECONNECT_IVL = 18;
  1252. private static final int BACKLOG = 19;
  1253. private static final int RECONNECT_IVL_MAX = 21;
  1254. private static final int MAXMSGSIZE = 22;
  1255. private static final int SNDHWM = 23;
  1256. private static final int RCVHWM = 24;
  1257. private static final int MULTICAST_HOPS = 25;
  1258. private static final int RCVTIMEO = 27;
  1259. private static final int SNDTIMEO = 28;
  1260. private static final int IPV4ONLY = 31;
  1261. private static final int ROUTER_MANDATORY = 33;
  1262. private static final int KEEPALIVE = 34;
  1263. private static final int KEEPALIVECNT = 35;
  1264. private static final int KEEPALIVEIDLE = 36;
  1265. private static final int KEEPALIVEINTVL = 37;
  1266. private static final int XPUB_VERBOSE = 40;
  1267. }
  1268. public static class PollItem {
  1269. private Socket socket;
  1270. private SelectableChannel channel;
  1271. private int events;
  1272. private int revents;
  1273. public PollItem(Socket socket, int events) {
  1274. th

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