Package org.zeromq.ZMQ

Examples of org.zeromq.ZMQ.Socket


            @Override
            public void run(Object[] args) {
                ZContext ctx = new ZContext();
                assert (ctx != null);

                Socket push = ctx.createSocket(ZMQ.PUSH);
                assert (push != null);
                ctx.destroy();
            }
        };
View Full Code Here


                pipe.recvStr();
                pipe.send("pong");
            }
        };

        Socket pipe = ZThread.fork(ctx, attached);
        assert (pipe != null);

        pipe.send("ping");
        String pong = pipe.recvStr();

        Assert.assertEquals(pong, "pong");

        // Everything should be cleanly closed now
        ctx.destroy();
View Full Code Here

    @Test
    public void testSingleFrameMessage() {
        ZContext ctx = new ZContext();

        Socket output = ctx.createSocket(ZMQ.PAIR);
        output.bind("inproc://zmsg.test");
        Socket input = ctx.createSocket(ZMQ.PAIR);
        input.connect("inproc://zmsg.test");

        // Test send and receive of a single ZMsg
        ZMsg msg = new ZMsg();
        ZFrame frame = new ZFrame("Hello");
        msg.addFirst(frame);
View Full Code Here

    @Test
    public void testMultiPart() {
        ZContext ctx = new ZContext();

        Socket output = ctx.createSocket(ZMQ.PAIR);
        output.bind("inproc://zmsg.test2");
        Socket input = ctx.createSocket(ZMQ.PAIR);
        input.connect("inproc://zmsg.test2");

        ZMsg msg = new ZMsg();
        for (int i = 0; i < 10; i++)
            msg.addString("Frame" + i);
        ZMsg copy = msg.duplicate();
View Full Code Here

    @Test
    public void testClosedContext() {
        ZContext ctx = new ZContext();

        Socket output = ctx.createSocket(ZMQ.PAIR);
        output.bind("inproc://zmsg.test");
        Socket input = ctx.createSocket(ZMQ.PAIR);
        input.connect("inproc://zmsg.test");
       
        ZMsg msg = ZMsg.newStringMsg("Foo", "Bar");
        msg.send(output);
       
        ZMsg msg2 = ZMsg.recvMsg(input);
View Full Code Here

    }

    @Test
    public void testSending() {
        ZContext ctx = new ZContext();
        Socket output = ctx.createSocket(ZMQ.PAIR);
        output.bind("inproc://zframe.test");
        Socket input = ctx.createSocket(ZMQ.PAIR);
        input.connect("inproc://zframe.test");

        // Send five different frames, test ZFRAME_MORE
        for (int i = 0; i < 5; i++) {
            ZFrame f = new ZFrame("Hello".getBytes());
            boolean rt = f.send(output, ZMQ.SNDMORE);
View Full Code Here

    }

    @Test
    public void testCopyingAndDuplicating() {
        ZContext ctx = new ZContext();
        Socket output = ctx.createSocket(ZMQ.PAIR);
        output.bind("inproc://zframe.test");
        Socket input = ctx.createSocket(ZMQ.PAIR);
        input.connect("inproc://zframe.test");

        ZFrame f = new ZFrame("Hello");
        ZFrame copy = f.duplicate();
        assertTrue(copy.equals(f));
        f.destroy();
View Full Code Here

    }

    @Test
    public void testReceiving() {
        ZContext ctx = new ZContext();
        Socket output = ctx.createSocket(ZMQ.PAIR);
        output.bind("inproc://zframe.test");
        Socket input = ctx.createSocket(ZMQ.PAIR);
        input.connect("inproc://zframe.test");

        // Send same frame five times
        ZFrame f = new ZFrame("Hello".getBytes());
        for (int i = 0; i < 5; i++) {
            f.send(output, ZMQ.SNDMORE);
View Full Code Here

    }

    @Test
    public void testStringFrames() {
        ZContext ctx = new ZContext();
        Socket output = ctx.createSocket(ZMQ.PAIR);
        output.bind("inproc://zframe.test");
        Socket input = ctx.createSocket(ZMQ.PAIR);
        input.connect("inproc://zframe.test");

        ZFrame f1 = new ZFrame("Hello");
        assertEquals(5, f1.getData().length);
        f1.send(output, 0);
View Full Code Here

    // Create an attached thread. An attached thread gets a ctx and a PAIR
    // pipe back to its parent. It must monitor its pipe, and exit if the
    // pipe becomes unreadable. Returns pipe, or null if there was an error.

    public static Socket fork(ZContext ctx, IAttachedRunnable runnable, Object... args) {
        Socket pipe = ctx.createSocket(ZMQ.PAIR);

        if (pipe != null) {
            pipe.bind(String.format("inproc://zctx-pipe-%d", pipe.hashCode()));
        } else {
            return null;
        }

        // Connect child pipe to our pipe
        ZContext ccontext = ZContext.shadow(ctx);
        Socket cpipe = ccontext.createSocket(ZMQ.PAIR);
        if (cpipe == null)
            return null;
        cpipe.connect(String.format("inproc://zctx-pipe-%d", pipe.hashCode()));

        // Prepare child thread
        Thread shim = new ShimThread(ccontext, runnable, args, cpipe);
        shim.start();
View Full Code Here

TOP

Related Classes of org.zeromq.ZMQ.Socket

Copyright © 2018 www.massapicom. 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.