use of org.zeromq.ZMQ.PollItem in project aion by aionnetwork.
the class ZLoop method addPoller.
// --------------------------------------------------------------------------
// Register pollitem with the reactor. When the pollitem is ready, will call
// the handler, passing the arg. Returns 0 if OK, -1 if there was an error.
// If you register the pollitem more than once, each instance will invoke its
// corresponding handler.
public int addPoller(PollItem item_, IZLoopHandler handler, Object arg) {
PollItem item = item_;
if (item.getRawSocket() == null && item.getSocket() == null)
return -1;
SPoller poller = new SPoller(item_, handler, arg);
pollers.add(poller);
dirty = true;
if (verbose)
System.out.printf("I: zloop: register %s poller (%s, %s)\n", item.getSocket() != null ? item.getSocket().getType() : "RAW", item.getSocket(), item.getRawSocket());
return 0;
}
use of org.zeromq.ZMQ.PollItem in project aion by aionnetwork.
the class ZLoop method removePoller.
// --------------------------------------------------------------------------
// Cancel a pollitem from the reactor, specified by socket or FD. If both
// are specified, uses only socket. If multiple poll items exist for same
// socket/FD, cancels ALL of them.
public void removePoller(PollItem item_) {
PollItem item = item_;
Iterator<SPoller> it = pollers.iterator();
while (it.hasNext()) {
SPoller p = it.next();
if (item.equals(p.item)) {
it.remove();
dirty = true;
}
}
if (verbose)
System.out.printf("I: zloop: cancel %s poller (%s, %s)", item.getSocket() != null ? item.getSocket().getType() : "RAW", item.getSocket(), item.getRawSocket());
}
use of org.zeromq.ZMQ.PollItem in project jeromq by zeromq.
the class lbbroker3 method main.
/**
* And the main task now sets-up child tasks, then starts its reactor.
* If you press Ctrl-C, the reactor exits and the main task shuts down.
*/
public static void main(String[] args) {
// Prepare our context and sockets
try (ZContext context = new ZContext()) {
LBBroker arg = new LBBroker();
arg.frontend = context.createSocket(SocketType.ROUTER);
arg.backend = context.createSocket(SocketType.ROUTER);
arg.frontend.bind("ipc://frontend.ipc");
arg.backend.bind("ipc://backend.ipc");
int clientNbr;
for (clientNbr = 0; clientNbr < NBR_CLIENTS; clientNbr++) ZThread.start(new ClientTask());
for (int workerNbr = 0; workerNbr < NBR_WORKERS; workerNbr++) ZThread.start(new WorkerTask());
// Queue of available workers
arg.workers = new LinkedList<ZFrame>();
// Prepare reactor and fire it up
ZLoop reactor = new ZLoop(context);
PollItem item = new PollItem(arg.backend, ZMQ.Poller.POLLIN);
reactor.addPoller(item, backendHandler, arg);
reactor.start();
}
}
use of org.zeromq.ZMQ.PollItem in project jeromq by zeromq.
the class clonesrv5 method run.
public void run() {
// Register our handlers with reactor
PollItem poller = new PollItem(snapshot, ZMQ.Poller.POLLIN);
loop.addPoller(poller, new Snapshots(), this);
poller = new PollItem(collector, ZMQ.Poller.POLLIN);
loop.addPoller(poller, new Collector(), this);
loop.addTimer(1000, 0, new FlushTTL(), this);
loop.start();
loop.destroy();
ctx.destroy();
}
use of org.zeromq.ZMQ.PollItem in project jeromq by zeromq.
the class bstar method voter.
// .split voter method
// This method registers a client voter socket. Messages received
// on this socket provide the CLIENT_REQUEST events for the Binary Star
// FSM and are passed to the provided application handler. We require
// exactly one voter per {{bstar}} instance:
public int voter(String endpoint, SocketType type, IZLoopHandler handler, Object arg) {
// Hold actual handler+arg so we can call this later
Socket socket = ctx.createSocket(type);
socket.bind(endpoint);
voterFn = handler;
voterArg = arg;
PollItem poller = new PollItem(socket, ZMQ.Poller.POLLIN);
return loop.addPoller(poller, VoterReady, this);
}
Aggregations