当前位置: 首页>>代码示例>>Java>>正文


Java ZFrame.destroy方法代码示例

本文整理汇总了Java中org.zeromq.ZFrame.destroy方法的典型用法代码示例。如果您正苦于以下问题:Java ZFrame.destroy方法的具体用法?Java ZFrame.destroy怎么用?Java ZFrame.destroy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.zeromq.ZFrame的用法示例。


在下文中一共展示了ZFrame.destroy方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serviceCall

import org.zeromq.ZFrame; //导入方法依赖的package包/类
static ZMsg
serviceCall (mdcliapi session, String service, ZMsg request)
{
    ZMsg reply = session.send(service, request);
    if (reply != null) {
        ZFrame status = reply.pop();
        if (status.streq("200")) {
            status.destroy();
            return reply;
        }
        else if (status.streq("400")) {
            System.out.println("E: client fatal error, aborting");
        }
        else
        if (status.streq("500")) {
            System.out.println("E: server fatal error, aborting");
        }
        reply.destroy();
    }
    return null;        //  Didn't succeed; don't care why not
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:22,代码来源:ticlient.java

示例2: run

import org.zeromq.ZFrame; //导入方法依赖的package包/类
@Override
public void run(Object[] args, ZContext ctx, Socket pipe)
{
    //  Print everything that arrives on pipe
    while (true) {
        ZFrame frame = ZFrame.recvFrame(pipe);
        if (frame == null)
            break;              //  Interrupted
        frame.print(null);
        frame.destroy();
    }
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:13,代码来源:espresso.java

示例3: recv

import org.zeromq.ZFrame; //导入方法依赖的package包/类
/**
 * Returns the reply message or NULL if there was no reply. Does not attempt
 * to recover from a broker failure, this is not possible without storing
 * all unanswered requests and resending them all…
 */
public ZMsg recv() {
    ZMsg reply = null;

    // Poll socket for a reply, with timeout
    ZMQ.Poller items = new ZMQ.Poller(1);
    items.register(client, ZMQ.Poller.POLLIN);
    if (items.poll(timeout * 1000) == -1)
        return null; // 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() >= 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;
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:39,代码来源:mdcliapi2.java

示例4: run

import org.zeromq.ZFrame; //导入方法依赖的package包/类
public void run() {
    Socket worker = ctx.createSocket(ZMQ.DEALER);
    worker.connect("inproc://backend");

    while (!Thread.currentThread().isInterrupted()) {
        //  The DEALER socket gives us the address envelope and message
        ZMsg msg = ZMsg.recvMsg(worker);
        ZFrame address = msg.pop();
        ZFrame content = msg.pop();
        assert (content != null);
        msg.destroy();

        //  Send 0..4 replies back
        int replies = rand.nextInt(5);
        for (int reply = 0; reply < replies; reply++) {
            //  Sleep for some fraction of a second
            try {
                Thread.sleep(rand.nextInt(1000) + 1);
            } catch (InterruptedException e) {
            }
            address.send(worker, ZFrame.REUSE + ZFrame.MORE);
            content.send(worker, ZFrame.REUSE);
        }
        address.destroy();
        content.destroy();
    }
    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:29,代码来源:asyncsrv.java

示例5: processClient

import org.zeromq.ZFrame; //导入方法依赖的package包/类
/**
 * Process a request coming from a client.
 */
private void processClient(ZFrame sender, ZMsg msg) {
    assert (msg.size() >= 2); // Service name + body
    ZFrame serviceFrame = msg.pop();
    // Set reply return address to client sender
    msg.wrap(sender.duplicate());
    if (serviceFrame.toString().startsWith(INTERNAL_SERVICE_PREFIX))
        serviceInternal(serviceFrame, msg);
    else
        dispatch(requireService(serviceFrame), msg);
    serviceFrame.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:15,代码来源:mdbroker.java

示例6: run

import org.zeromq.ZFrame; //导入方法依赖的package包/类
public void run() {
	Socket worker = ctx.createSocket(ZMQ.DEALER);
	worker.connect("inproc://backend");

	Sensors sensorsService = new Sensors();

	while (!Thread.currentThread().isInterrupted()) {
		// The DEALER socket gives us the address envelope and message
		ZMsg msg = ZMsg.recvMsg(worker);
		ZFrame address = msg.pop();
		ZFrame header = msg.pop();
		ZFrame content = msg.pop();
		assert (content != null);
		msg.destroy();

		String messageContent = content.toString();
		LogManager.getLogger(this.getClass()).info("Got message: "+messageContent);

		ObjectMapper mapper = new ObjectMapper();

		try {

			messageContent=messageContent.replace("@class", "@c");
			
			messageContent=messageContent.replace("cm.homeautomation.sensors", "");
			
			messageContent=messageContent.replace("cm.homeautomation.transmission.TransmissionStatusData", ".TransmissionStatusData");
			
			LogManager.getLogger(this.getClass()).info("message for deserialization: "+messageContent);
			
			JSONSensorDataBase sensorData = mapper.readValue(messageContent, JSONSensorDataBase.class);

			if (sensorData instanceof SensorDataSaveRequest) {
				sensorsService.saveSensorData((SensorDataSaveRequest) sensorData);
			} else if (sensorData instanceof SensorDataRoomSaveRequest) {
				sensorsService.save((SensorDataRoomSaveRequest)sensorData);					
			}

			address.send(worker, ZFrame.REUSE + ZFrame.MORE);
			content.send(worker, ZFrame.REUSE);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		address.destroy();
		content.destroy();
	}
	ctx.destroy();
}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:51,代码来源:JeroMQServerWorker.java

示例7: recv

import org.zeromq.ZFrame; //导入方法依赖的package包/类
public static ZreLogMsg recv (Socket input)
{
    assert (input != null);
    ZreLogMsg self = new ZreLogMsg (0);
    ZFrame frame = null;

    try {
        //  Read valid message frame from socket; we loop over any
        //  garbage data we might receive from badly-connected peers
        while (true) {
            //  If we're reading from a ROUTER socket, get address
            if (input.getType () == ZMQ.ROUTER) {
                self.address = ZFrame.recvFrame (input);
                if (self.address == null)
                    return null;         //  Interrupted
                if (!input.hasReceiveMore ())
                    throw new IllegalArgumentException ();
            }
            //  Read and parse command in frame
            frame = ZFrame.recvFrame (input);
            if (frame == null)
                return null;             //  Interrupted

            //  Get and check protocol signature
            self.needle = ByteBuffer.wrap (frame.getData ()); 
            int signature = self.getNumber2 ();
            if (signature == (0xAAA0 | 2))
                break;                  //  Valid signature

            //  Protocol assertion, drop message
            while (input.hasReceiveMore ()) {
                frame.destroy ();
                frame = ZFrame.recvFrame (input);
            }
            frame.destroy ();
        }

        //  Get message id, which is first byte in frame
        self.id = self.getNumber1 ();
        int listSize;
        int hashSize;

        switch (self.id) {
        case LOG:
            self.level = self.getNumber1 ();
            self.event = self.getNumber1 ();
            self.node = self.getNumber2 ();
            self.peer = self.getNumber2 ();
            self.time = self.getNumber8 ();
            self.data = self.getString ();
            break;

        default:
            throw new IllegalArgumentException ();
        }

        return self;

    } catch (Exception e) {
        //  Error returns
        System.out.printf ("E: malformed message '%d'\n", self.id);
        self.destroy ();
        return null;
    } finally {
        if (frame != null)
            frame.destroy ();
    }
}
 
开发者ID:zeromq,项目名称:jyre,代码行数:69,代码来源:ZreLogMsg.java

示例8: send

import org.zeromq.ZFrame; //导入方法依赖的package包/类
public boolean send (Socket socket)
{
    assert (socket != null);

    //  Calculate size of serialized data
    int frameSize = 2 + 1;          //  Signature and message ID
    switch (id) {
    case LOG:
        //  level is a 1-byte integer
        frameSize += 1;
        //  event is a 1-byte integer
        frameSize += 1;
        //  node is a 2-byte integer
        frameSize += 2;
        //  peer is a 2-byte integer
        frameSize += 2;
        //  time is a 8-byte integer
        frameSize += 8;
        //  data is a string with 1-byte length
        frameSize++;       //  Size is one octet
        if (data != null)
            frameSize += data.length ();
        break;
        
    default:
        System.out.printf ("E: bad message type '%d', not sent\n", id);
        assert (false);
    }
    //  Now serialize message into the frame
    ZFrame frame = new ZFrame (new byte [frameSize]);
    needle = ByteBuffer.wrap (frame.getData ()); 
    int frameFlags = 0;
    putNumber2 (0xAAA0 | 2);
    putNumber1 ((byte) id);

    switch (id) {
    case LOG:
        putNumber1 (level);
        putNumber1 (event);
        putNumber2 (node);
        putNumber2 (peer);
        putNumber8 (time);
        if (data != null)
            putString (data);
        else
            putNumber1 ((byte) 0);      //  Empty string
        break;
        
    }
    //  If we're sending to a ROUTER, we send the address first
    if (socket.getType () == ZMQ.ROUTER) {
        assert (address != null);
        if (!address.send (socket, ZMQ.SNDMORE)) {
            destroy ();
            return false;
        }
    }
    //  Now send the data frame
    if (!frame.send (socket, frameFlags)) {
        frame.destroy ();
        destroy ();
        return false;
    }
    
    //  Now send any frame fields, in order
    switch (id) {
    }
    //  Destroy ZreLogMsg object
    destroy ();
    return true;
}
 
开发者ID:zeromq,项目名称:jyre,代码行数:72,代码来源:ZreLogMsg.java

示例9: send

import org.zeromq.ZFrame; //导入方法依赖的package包/类
/**
 * Send request to broker and get reply by hook or crook Takes ownership of
 * request message and destroys it when sent. Returns the reply message or
 * NULL if there was no reply.
 *
 * @param service
 * @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 = new ZMQ.Poller(1);
        items.register(client, ZMQ.Poller.POLLIN);
        if (items.poll(timeout) == -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);
            if (--retriesLeft == 0) {
                log.format("W: permanent error, abandoning\n");
                break;
            }
            log.format("W: no reply, reconnecting\n");
            reconnectToBroker();
        }
    }
    request.destroy();
    return reply;
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:63,代码来源:mdcliapi.java

示例10: main

import org.zeromq.ZFrame; //导入方法依赖的package包/类
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();
    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);

}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:44,代码来源:lruqueue3.java

示例11: mediate

import org.zeromq.ZFrame; //导入方法依赖的package包/类
/**
 * Main broker work happens here
 */
public void mediate() {
    while (!Thread.currentThread().isInterrupted()) {
        ZMQ.Poller items = new ZMQ.Poller(1);
        items.register(socket, ZMQ.Poller.POLLIN);
        if (items.poll(HEARTBEAT_INTERVAL) == -1)
            break; // Interrupted
        if (items.pollin(0)) {
            ZMsg msg = ZMsg.recvMsg(socket);
            if (msg == null)
                break; // Interrupted

            if (verbose) {
                log.format("I: received message:\n");
                msg.dump(log.out());
            }

            ZFrame sender = msg.pop();
            ZFrame empty = msg.pop();
            ZFrame header = msg.pop();

            if (MDP.C_CLIENT.frameEquals(header)) {
                processClient(sender, msg);
            } else if (MDP.W_WORKER.frameEquals(header))
                processWorker(sender, msg);
            else {
                log.format("E: invalid message:\n");
                msg.dump(log.out());
                msg.destroy();
            }

            sender.destroy();
            empty.destroy();
            header.destroy();

        }
        purgeWorkers();
        sendHeartbeats();
    }
    destroy(); // interrupted
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:44,代码来源:mdbroker.java

示例12: processWorker

import org.zeromq.ZFrame; //导入方法依赖的package包/类
/**
 * Process message sent to us by a worker.
 */
private void processWorker(ZFrame sender, ZMsg msg) {
    assert (msg.size() >= 1); // At least, command

    ZFrame command = msg.pop();

    boolean workerReady = workers.containsKey(sender.strhex());

    Worker worker = requireWorker(sender);

    if (MDP.W_READY.frameEquals(command)) {
        // Not first command in session || Reserved service name
        if (workerReady
                || sender.toString().startsWith(INTERNAL_SERVICE_PREFIX))
            deleteWorker(worker, true);
        else {
            // Attach worker to service and mark as idle
            ZFrame serviceFrame = msg.pop();
            worker.service = requireService(serviceFrame);
            workerWaiting(worker);
            serviceFrame.destroy();
        }
    } else if (MDP.W_REPLY.frameEquals(command)) {
        if (workerReady) {
            // Remove & save client return envelope and insert the
            // protocol header and service name, then rewrap envelope.
            ZFrame client = msg.unwrap();
            msg.addFirst(worker.service.name);
            msg.addFirst(MDP.C_CLIENT.newFrame());
            msg.wrap(client);
            msg.send(socket);
            workerWaiting(worker);
        } else {
            deleteWorker(worker, true);
        }
    } else if (MDP.W_HEARTBEAT.frameEquals(command)) {
        if (workerReady) {
            worker.expiry = System.currentTimeMillis() + HEARTBEAT_EXPIRY;
        } else {
            deleteWorker(worker, true);
        }
    } else if (MDP.W_DISCONNECT.frameEquals(command))
        deleteWorker(worker, false);
    else {
        log.format("E: invalid message:\n");
        msg.dump(log.out());
    }
    msg.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:52,代码来源:mdbroker.java


注:本文中的org.zeromq.ZFrame.destroy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。