Examples of ZFrame


Examples of org.zeromq.ZFrame

        ZMsg msg = msgp == null ? new ZMsg() : msgp.duplicate();

        // Stack protocol envelope to start of message
        if (option != null)
            msg.addFirst(new ZFrame(option));
        msg.addFirst(command.newFrame());
        msg.addFirst(MDP.W_WORKER.newFrame());

        // Stack routing envelope to start of message
        msg.wrap(worker.address.duplicate());
View Full Code Here

Examples of org.zeromq.ZFrame

     * @param request
     * @return
     */
    public ZMsg send(String service, ZMsg request) {

        request.push(new ZFrame(service));
        request.push(MDP.C_CLIENT.newFrame());
        if (verbose) {
            log.format("I: send request to '%s' service: \n", service);
            request.dump(log.out());
        }
        ZMsg reply = null;

        int retriesLeft = retries;
        while (retriesLeft > 0 && !Thread.currentThread().isInterrupted()) {

            request.duplicate().send(client);

            // Poll socket for a reply, with timeout
            ZMQ.Poller items = ctx.getContext().poller();
            items.register(client, ZMQ.Poller.POLLIN);
            if (items.poll(timeout * 1000) == -1)
                break; // Interrupted

            if (items.pollin(0)) {
                ZMsg msg = ZMsg.recvMsg(client);
                if (verbose){
                    log.format("I: received reply: \n");
                    msg.dump(log.out());
                }
                // Don't try to handle errors, just assert noisily
                assert (msg.size() >= 3);

                ZFrame header = msg.pop();
                assert (MDP.C_CLIENT.equals(header.toString()));
                header.destroy();

                ZFrame replyService = msg.pop();
                assert (service.equals(replyService.toString()));
                replyService.destroy();

                reply = msg;
                break;
            } else {
                items.unregister(client);
View Full Code Here

Examples of org.zeromq.ZFrame

    void sendToBroker(MDP command, String option, ZMsg msg) {
        msg = msg != null ? msg.duplicate() : new ZMsg();

        // Stack protocol envelope to start of message
        if (option != null)
            msg.addFirst(new ZFrame(option));

        msg.addFirst(command.newFrame());
        msg.addFirst(MDP.W_WORKER.newFrame());
        msg.addFirst(new ZFrame(new byte[0]));

        if (verbose) {
            log.format("I: sending %s to broker\n", command);
            msg.dump(log.out());
        }
View Full Code Here

Examples of org.zeromq.ZFrame

                }
                liveness = HEARTBEAT_LIVENESS;
                // Don't try to handle errors, just assert noisily
                assert (msg != null && msg.size() >= 3);

                ZFrame empty = msg.pop();
                assert (empty.getData().length == 0);
                empty.destroy();

                ZFrame header = msg.pop();
                assert (MDP.W_WORKER.frameEquals(header));
                header.destroy();

                ZFrame command = msg.pop();
                if (MDP.W_REQUEST.frameEquals(command)) {
                    // We should pop and save as many addresses as there are
                    // up to a null part, but for now, just save one...
                    replyTo = msg.unwrap();
                    command.destroy();
                    return msg; // We have a request to process
                } else if (MDP.W_HEARTBEAT.frameEquals(command)) {
                    // Do nothing for heartbeats
                } else if (MDP.W_DISCONNECT.frameEquals(command)) {
                    reconnectToBroker();
                } else {
                    log.format("E: invalid input message: \n");
                    msg.dump(log.out());
                }
                command.destroy();
                msg.destroy();
            } else if (--liveness == 0) {
                if (verbose)
                    log.format("W: disconnected from broker - retrying...\n");
                try {
View Full Code Here

Examples of org.zeromq.ZFrame

                msg.dump(log.out());
            }
            // Don't try to handle errors, just assert noisily
            assert (msg.size() >= 4);

            ZFrame empty = msg.pop();
            assert (empty.getData().length == 0);
            empty.destroy();

            ZFrame header = msg.pop();
            assert (MDP.C_CLIENT.equals(header.toString()));
            header.destroy();

            ZFrame replyService = msg.pop();
            replyService.destroy();

            reply = msg;
        }
        return reply;
    }
View Full Code Here

Examples of org.zeromq.ZFrame

    @Test
    public void testFmqSasl ()
    {
        System.out.printf (" * fmq_sasl: ");

        ZFrame frame = FmqSasl.plainEncode ("Happy", "Harry");
        String [] result = new String [2];
        String login, password;
        boolean rc = FmqSasl.plainDecode (frame, result);
        login = result [0];
        password = result [1];
       
        assertTrue (rc);
        assertEquals (login, "Happy");
        assertEquals (password, "Harry");
        frame.destroy ();

        System.out.printf ("OK\n");
    }
View Full Code Here

Examples of org.zeromq.ZFrame

        self.destroy ();

        self = new FmqMsg (FmqMsg.ORLY);
        self.appendMechanisms ("Name: %s", "Brutus");
        self.appendMechanisms ("Age: %d", 43);
        self.setChallenge (new ZFrame ("Captcha Diem"));
        self.send (output);
   
        self = FmqMsg.recv (input);
        assert (self != null);
        assertEquals (self.mechanisms ().size (), 2);
        assertEquals (self.mechanisms ().get (0), "Name: Brutus");
        assertEquals (self.mechanisms ().get (1), "Age: 43");
        assertTrue (self.challenge ().streq ("Captcha Diem"));
        self.destroy ();

        self = new FmqMsg (FmqMsg.YARLY);
        self.setMechanism ("Life is short but Now lasts for ever");
        self.setResponse (new ZFrame ("Captcha Diem"));
        self.send (output);
   
        self = FmqMsg.recv (input);
        assert (self != null);
        assertEquals (self.mechanism (), "Life is short but Now lasts for ever");
        assertTrue (self.response ().streq ("Captcha Diem"));
        self.destroy ();

        self = new FmqMsg (FmqMsg.OHAI_OK);
        self.send (output);
   
        self = FmqMsg.recv (input);
        assert (self != null);
        self.destroy ();

        self = new FmqMsg (FmqMsg.ICANHAZ);
        self.setPath ("Life is short but Now lasts for ever");
        self.insertOptions ("Name", "Brutus");
        self.insertOptions ("Age", "%d", 43);
        self.insertCache ("Name", "Brutus");
        self.insertCache ("Age", "%d", 43);
        self.send (output);
   
        self = FmqMsg.recv (input);
        assert (self != null);
        assertEquals (self.path (), "Life is short but Now lasts for ever");
        assertEquals (self.options ().size (), 2);
        assertEquals (self.optionsString ("Name", "?"), "Brutus");
        assertEquals (self.optionsNumber ("Age", 0), 43);
        assertEquals (self.cache ().size (), 2);
        assertEquals (self.cacheString ("Name", "?"), "Brutus");
        assertEquals (self.cacheNumber ("Age", 0), 43);
        self.destroy ();

        self = new FmqMsg (FmqMsg.ICANHAZ_OK);
        self.send (output);
   
        self = FmqMsg.recv (input);
        assert (self != null);
        self.destroy ();

        self = new FmqMsg (FmqMsg.NOM);
        self.setCredit ((byte) 123);
        self.setSequence ((byte) 123);
        self.send (output);
   
        self = FmqMsg.recv (input);
        assert (self != null);
        assertEquals (self.credit (), 123);
        assertEquals (self.sequence (), 123);
        self.destroy ();

        self = new FmqMsg (FmqMsg.CHEEZBURGER);
        self.setSequence ((byte) 123);
        self.setOperation ((byte) 123);
        self.setFilename ("Life is short but Now lasts for ever");
        self.setOffset ((byte) 123);
        self.setEof ((byte) 123);
        self.insertHeaders ("Name", "Brutus");
        self.insertHeaders ("Age", "%d", 43);
        self.setChunk (new ZFrame ("Captcha Diem"));
        self.send (output);
   
        self = FmqMsg.recv (input);
        assert (self != null);
        assertEquals (self.sequence (), 123);
View Full Code Here

Examples of org.zeromq.ZFrame

        private void trySecurityMechanism (Server server)
        {
            String login = config.resolve ("security/plain/login", "guest");
            String password = config.resolve ("security/plain/password", "");
            ZFrame frame = FmqSasl.plainEncode (login, password);           
            server.request.setMechanism ("PLAIN");                          
            server.request.setResponse (frame);                             
        }
View Full Code Here

Examples of org.zeromq.ZFrame

                        server.file = null;                                        
                        return;                                                    
                    }                                                              
                }                                                                  
                //  Try to write, ignore errors in this version                    
                ZFrame frame = server.reply.chunk ();                              
                FmqChunk chunk = new FmqChunk (frame.getData (), frame.size ());   
                if (chunk.size () > 0) {                                           
                    server.file.write (chunk, server.reply.offset ());             
                    server.credit -= chunk.size ();                                
                }                                                                  
                else {                                                             
View Full Code Here

Examples of org.zeromq.ZFrame

    //  any degree of confidentiality. The SASL PLAIN mechanism is defined here:
    //  http://www.ietf.org/internet-drafts/draft-ietf-sasl-plain-08.txt.
    public static ZFrame plainEncode (String login, String password)
    {
        //  PLAIN format is [null]login[null]password
        ZFrame frame = new ZFrame (new byte [login.length () + password.length () + 2]);
        byte [] data = frame.getData ();
        int pos = 0;
        data [pos++] = 0;
        System.arraycopy (login.getBytes (), 0, data, pos, login.length ());
        pos += login.length ();
        data [pos++] = 0;
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.