Examples of ZMsg


Examples of org.zeromq.ZMsg

            if (items [0].isReadable()) {
                //  Ensure message directory exists
                new File(TITANIC_DIR).mkdirs();

                //  Append UUID to queue, prefixed with '-' for pending
                ZMsg msg = ZMsg.recvMsg(requestPipe);
                if (msg == null)
                    break;          //  Interrupted
                String uuid = msg.popString();
                BufferedWriter wfile = null;
                try {
                    wfile = new BufferedWriter(new FileWriter(TITANIC_DIR + "/queue", true));
                    wfile.write("-" + uuid + "\n");
                } catch (IOException e) {
                    e.printStackTrace();
                    break;
                } finally {
                    try {
                        if (wfile != null)
                        wfile.close();
                    } catch (IOException e) {
                    }
                }
                msg.destroy();
            }
            //  Brute force dispatcher
            byte[] entry = new byte[37]; //"?........:....:....:....:............:";
            RandomAccessFile file = null;
            try {
View Full Code Here

Examples of org.zeromq.ZMsg

        //  If the client already closed request, treat as successful
        if (!new File(filename).exists())
            return true;

        DataInputStream file = null;
        ZMsg request;
        try {
            file = new DataInputStream(new FileInputStream(filename));
            request = ZMsg.load(file);
        } catch (IOException e) {
            e.printStackTrace();
            return true;
        } finally {
            try {
                if (file != null)
                    file.close();
            } catch (IOException e) {
            }
        }
        ZFrame service = request.pop();
        String serviceName = service.toString();

        //  Create MDP client session with short timeout
        mdcliapi client = new mdcliapi("tcp://localhost:5555", false);
        client.setTimeout(1000)//  1 sec
        client.setRetries(1);     //  only 1 retry

        //  Use MMI protocol to check if service is available
        ZMsg mmiRequest = new ZMsg();
        mmiRequest.add(service);
        ZMsg mmiReply = client.send("mmi.service", mmiRequest);
        boolean serviceOK = (mmiReply != null
                && mmiReply.getFirst().toString().equals("200"));
       
        if(mmiReply != null)
            mmiReply.destroy();

        boolean result = false;
        if (serviceOK) {
            ZMsg reply = client.send(serviceName, request);
            if (reply != null) {
                filename = replyFilename(uuid);
                DataOutputStream ofile = null;
                try {
                    ofile = new DataOutputStream(new FileOutputStream(filename));
                    ZMsg.save(reply, ofile);
                } catch (IOException e) {
                    e.printStackTrace();
                    return true;
                } finally {
                    try {
                        if (file != null)
                            file.close();
                    } catch (IOException e) {
                    }
                }
                result = true;
                reply.destroy();
            }
           
        }
        else
            request.destroy();
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.