Search in sources :

Example 1 with ZLoop

use of org.zeromq.ZLoop in project jeromq by zeromq.

the class lruqueue3 method main.

public static void main(String[] args) {
    ZContext context = new ZContext();
    LRUQueueArg arg = new LRUQueueArg();
    //  Prepare our context and sockets
    Socket frontend = context.createSocket(ZMQ.ROUTER);
    Socket backend = context.createSocket(ZMQ.ROUTER);
    arg.frontend = frontend;
    arg.backend = backend;
    frontend.bind("ipc://frontend.ipc");
    backend.bind("ipc://backend.ipc");
    int client_nbr;
    for (client_nbr = 0; client_nbr < 10; client_nbr++) new ClientThread3().start();
    int worker_nbr;
    for (worker_nbr = 0; worker_nbr < 3; worker_nbr++) new WorkerThread3().start();
    //  Queue of available workers
    arg.workers = new LinkedList<ZFrame>();
    //  Prepare reactor and fire it up
    ZLoop reactor = new ZLoop(context);
    reactor.verbose(true);
    PollItem poller = new PollItem(arg.backend, ZMQ.Poller.POLLIN);
    reactor.addPoller(poller, handle_backend, arg);
    reactor.start();
    reactor.destroy();
    for (ZFrame frame : arg.workers) {
        frame.destroy();
    }
    context.destroy();
    System.exit(0);
}
Also used : ZFrame(org.zeromq.ZFrame) PollItem(org.zeromq.ZMQ.PollItem) ZLoop(org.zeromq.ZLoop) ZContext(org.zeromq.ZContext) Socket(org.zeromq.ZMQ.Socket)

Example 2 with ZLoop

use of org.zeromq.ZLoop 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) {
    ZContext context = new ZContext();
    LBBroker arg = new LBBroker();
    //  Prepare our context and sockets
    arg.frontend = context.createSocket(ZMQ.ROUTER);
    arg.backend = context.createSocket(ZMQ.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();
    context.destroy();
}
Also used : ZFrame(org.zeromq.ZFrame) PollItem(org.zeromq.ZMQ.PollItem) ZLoop(org.zeromq.ZLoop) ZContext(org.zeromq.ZContext)

Aggregations

ZContext (org.zeromq.ZContext)2 ZFrame (org.zeromq.ZFrame)2 ZLoop (org.zeromq.ZLoop)2 PollItem (org.zeromq.ZMQ.PollItem)2 Socket (org.zeromq.ZMQ.Socket)1