Package org.zeromq

Examples of org.zeromq.ZContext.createSocket()


    //  The main task is an LRU queue with heartbeating on workers so we can
    //  detect crashed or blocked worker tasks:
    public static void main(String[] args) {
        ZContext ctx = new ZContext ();
        Socket frontend = ctx.createSocket(ZMQ.ROUTER);
        Socket backend = ctx.createSocket(ZMQ.ROUTER);
        frontend.bind( "tcp://*:5555");    //  For clients
        backend.bind( "tcp://*:5556");    //  For workers

        //  List of available workers
        ArrayList<Worker> workers = new ArrayList<Worker> ();
View Full Code Here


        ZContext ctx = new ZContext();
        //  Prepare server socket with predictable identity
        String bindEndpoint = "tcp://*:5555";
        String connectEndpoint = "tcp://localhost:5555";
        Socket server = ctx.createSocket(ZMQ.ROUTER);
        server.setIdentity(connectEndpoint.getBytes());
        server.bind(bindEndpoint);
        System.out.printf ("I: service is ready at %s\n", bindEndpoint);

        while (!Thread.currentThread().isInterrupted()) {
View Full Code Here

public class pathopub
{
    public static void main(String[] args) throws Exception
    {
        ZContext context = new ZContext();
        Socket publisher = context.createSocket(ZMQ.PUB);
        if (args.length == 1)
            publisher.connect(args[0]);
        else
            publisher.bind("tcp://*:5556");

 
View Full Code Here

    private final static String WORKER_READY = "\001";      //  Signals worker is ready

    public static void main(String[] args) throws Exception
    {
        ZContext ctx = new ZContext();
        Socket worker = ctx.createSocket(ZMQ.REQ);

        //  Set random identity to make tracing easier
        Random rand = new Random(System.nanoTime());
        String identity = String.format("%04X-%04X", rand.nextInt(0x10000), rand.nextInt(0x10000));
        worker.setIdentity(identity.getBytes());
View Full Code Here

    private static class client_task implements Runnable {

        public void run() {
            ZContext ctx = new ZContext();
            Socket client = ctx.createSocket(ZMQ.DEALER);

            //  Set random identity to make tracing easier
            String identity = String.format("%04X-%04X", rand.nextInt(), rand.nextInt());
            client.setIdentity(identity.getBytes());
            client.connect("tcp://localhost:5570");
View Full Code Here

    private static class server_task implements Runnable {
        public void run() {
            ZContext ctx = new ZContext();

            //  Frontend socket talks to clients over TCP
            Socket frontend = ctx.createSocket(ZMQ.ROUTER);
            frontend.bind("tcp://*:5570");

            //  Backend socket talks to workers over inproc
            Socket backend = ctx.createSocket(ZMQ.DEALER);
            backend.bind("inproc://backend");
View Full Code Here

            //  Frontend socket talks to clients over TCP
            Socket frontend = ctx.createSocket(ZMQ.ROUTER);
            frontend.bind("tcp://*:5570");

            //  Backend socket talks to workers over inproc
            Socket backend = ctx.createSocket(ZMQ.DEALER);
            backend.bind("inproc://backend");

            //  Launch pool of worker threads, precise number is not critical
            for (int threadNbr = 0; threadNbr < 5; threadNbr++)
                new Thread(new server_worker(ctx)).start();
View Full Code Here

    public static void main(String[] argv) {
        //  Arguments can be either of:
        //      -p  primary server, at tcp://localhost:5001
        //      -b  backup server, at tcp://localhost:5002
        ZContext ctx = new ZContext();
        Socket statepub = ctx.createSocket(ZMQ.PUB);
        Socket statesub = ctx.createSocket(ZMQ.SUB);
        statesub.subscribe("".getBytes());
        Socket frontend = ctx.createSocket(ZMQ.ROUTER);
        bstarsrv fsm = new bstarsrv();
View Full Code Here

        //  Arguments can be either of:
        //      -p  primary server, at tcp://localhost:5001
        //      -b  backup server, at tcp://localhost:5002
        ZContext ctx = new ZContext();
        Socket statepub = ctx.createSocket(ZMQ.PUB);
        Socket statesub = ctx.createSocket(ZMQ.SUB);
        statesub.subscribe("".getBytes());
        Socket frontend = ctx.createSocket(ZMQ.ROUTER);
        bstarsrv fsm = new bstarsrv();

        if (argv.length == 1 && argv[0].equals("-p")) {
View Full Code Here

        //      -b  backup server, at tcp://localhost:5002
        ZContext ctx = new ZContext();
        Socket statepub = ctx.createSocket(ZMQ.PUB);
        Socket statesub = ctx.createSocket(ZMQ.SUB);
        statesub.subscribe("".getBytes());
        Socket frontend = ctx.createSocket(ZMQ.ROUTER);
        bstarsrv fsm = new bstarsrv();

        if (argv.length == 1 && argv[0].equals("-p")) {
            System.out.printf("I: Primary active, waiting for backup (passive)\n");
            frontend.bind("tcp://*:5001");
 
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.