@Override public void run() { try { if (closed) { return; } if (null == zmq) { zmq = new ZContext(ioThreadCount); shutdownCtx = true; } socket = zmq.createSocket(socketType); socket.setIdentity(id.toString().getBytes()); configure(socket); pollin = new ZMQ.PollItem(socket, ZMQ.Poller.POLLIN); if (log.isDebugEnabled()) { zloop.verbose(true); } zloop.addPoller(pollin, inputHandler, null); start(socket); zloop.start(); zmq.destroySocket(socket); } catch (Exception e) { b.onError(e); } }
public void removePoller(PollItem pollItem) { Iterator<SPoller> it = pollers.iterator(); while (it.hasNext()) { SPoller p = it.next(); if (pollItem.equals(p.item)) { it.remove(); dirty = true; } } if (verbose) { System.out.printf( "I: zloop: cancel %s poller (%s, %s)", pollItem.getSocket() != null ? pollItem.getSocket().getType() : "RAW", pollItem.getSocket(), pollItem.getRawSocket()); } }
if (pollset.getItem(itemNbr).isError()) { if (verbose) { System.out.printf( "I: zloop: can't poll %s socket (%s, %s)\n", poller.item.getSocket() != null ? poller.item.getSocket().getType() : "RAW", poller.item.getSocket(), poller.item.getRawSocket()); if (pollset.getItem(itemNbr).readyOps() > 0) { if (verbose) { System.out.printf( "I: zloop: call %s socket handler (%s, %s)\n", poller.item.getSocket() != null ? poller.item.getSocket().getType() : "RAW", poller.item.getSocket(), poller.item.getRawSocket());
@Override public void run() { if (closed) { return; } if (null == zmq) { zmq = new ZContext(ioThreadCount); shutdownCtx = true; } socket = zmq.createSocket(socketType); socket.setIdentity(id.toString().getBytes()); configure(socket); pollin = new ZMQ.PollItem(socket, ZMQ.Poller.POLLIN); if (log.isTraceEnabled()) { zloop.verbose(true); } zloop.addPoller(pollin, inputHandler, null); start(socket); zloop.start(); zmq.destroySocket(socket); }
/** * Unregister a Socket for polling on the specified events. * * @param socket the Socket to be unregistered */ private void unregisterInternal(Object socket) { for (int i = 0; i < next; ++i) { PollItem item = items[i]; if (item == null) { continue; } if (item.socket == socket || item.getRawSocket() == socket) { items[i] = null; freeSlots.add(i); --used; break; } } }
public int addPoller(PollItem pollItem, IZLoopHandler handler, Object arg) { if (pollItem.getRawSocket() == null && pollItem.getSocket() == null) { return -1; } SPoller poller = new SPoller(pollItem, handler, arg); pollers.add(poller); dirty = true; if (verbose) { System.out.printf( "I: zloop: register %s poller (%s, %s)\n", pollItem.getSocket() != null ? pollItem.getSocket().getType() : "RAW", pollItem.getSocket(), pollItem.getRawSocket()); } return 0; }
@Override public boolean equals(Object obj) { if (!(obj instanceof PollItem)) { return false; } PollItem target = (PollItem) obj; if (socket != null && socket == target.socket) { return true; } if (getRawSocket() != null && getRawSocket() == target.getRawSocket()) { return true; } return false; } }
/** * Check whether the specified element in the poll set was signaled for error. * * @param index * * @return true if the element was signaled. */ public boolean pollerr(int index) { if (index < 0 || index >= this.next) { return false; } return items[index].isError(); } }
/** * Register a Socket for polling on the specified events. * * Automatically grow the internal representation if needed. * * @param channel * the Channel we are registering. * @param events * a mask composed by XORing POLLIN, POLLOUT and POLLERR. * @return the index identifying this Channel in the poll set. */ public int register(SelectableChannel channel, int events) { return registerInternal(new PollItem(channel, events)); }
/** * Register a Socket for polling on the specified events. * * Automatically grow the internal representation if needed. * * @param socket * the Socket we are registering. * @param events * a mask composed by XORing POLLIN, POLLOUT and POLLERR. * @return the index identifying this Socket in the poll set. */ public int register(Socket socket, int events) { return registerInternal(new PollItem(socket, events)); }
/** * Check whether the specified element in the poll set was signaled for output. * * @param index * * @return true if the element was signaled. */ public boolean pollout(int index) { if (index < 0 || index >= this.next) { return false; } return items[index].isWritable(); }
/** * Check whether the specified element in the poll set was signaled for input. * * @param index * * @return true if the element was signaled. */ public boolean pollin(int index) { if (index < 0 || index >= this.next) { return false; } return items[index].isReadable(); }
/** * Register a Channel for polling on the specified events. * * Automatically grow the internal representation if needed. * * @param channel the Channel we are registering. * @param events a mask composed by XORing POLLIN, POLLOUT and POLLERR. * @return the index identifying this Channel in the poll set. */ public int register(SelectableChannel channel, int events) { return registerInternal(new PollItem(channel, events)); }
/** * Register a Socket for polling on the specified events. * * Automatically grow the internal representation if needed. * * @param socket the Socket we are registering. * @param events a mask composed by XORing POLLIN, POLLOUT and POLLERR. * @return the index identifying this Socket in the poll set. */ public int register(Socket socket, int events) { return registerInternal(new PollItem(socket, events)); }