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


Java ZFrame.send方法代码示例

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


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

示例1: run

import org.zeromq.ZFrame; //导入方法依赖的package包/类
@Override
public void run (Object ... args)
{
    ZContext context = new ZContext();

    //  Prepare our context and sockets
    Socket worker  = context.createSocket (ZMQ.REQ);
    ZHelper.setId (worker);     //  Set a printable identity

    worker.connect("ipc://backend.ipc");

    //  Tell backend we're ready for work
    ZFrame frame = new ZFrame (WORKER_READY);
    frame.send (worker, 0);

    while(true)
    {
        ZMsg msg = ZMsg.recvMsg (worker);
        if (msg == null)
            break;

        msg.getLast ().reset ("OK");
        msg.send (worker);
    }
    context.destroy ();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:27,代码来源:lbbroker2.java

示例2: run

import org.zeromq.ZFrame; //导入方法依赖的package包/类
@Override
public void run()
{
    ZContext ctx = new ZContext();
    Socket worker = ctx.createSocket(ZMQ.REQ);
    worker.connect(String.format("ipc://%s-localbe.ipc", self));

    //  Tell broker we're ready for work
    ZFrame frame = new ZFrame(WORKER_READY);
    frame.send(worker, 0);

    while (true) {
        //  Send request, get reply
        ZMsg msg = ZMsg.recvMsg(worker, 0);
        if (msg == null)
            break;              //  Interrupted
        msg.getLast().print("Worker: ");
        msg.getLast().reset("OK");
        msg.send(worker);

    }
    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:24,代码来源:peering2.java

示例3: run

import org.zeromq.ZFrame; //导入方法依赖的package包/类
public void run()
{
    ZContext context = new ZContext();
    //  Prepare our context and sockets
    Socket worker = context.createSocket(ZMQ.REQ);

    worker.connect("ipc://backend.ipc");

    ZFrame frame = new ZFrame(lruqueue3.LRU_READY);
    //  Tell backend we're ready for work
    frame.send(worker, 0);

    while (true) {
        ZMsg msg = ZMsg.recvMsg(worker);
        if (msg == null)
            break;

        msg.getLast().reset("OK".getBytes(ZMQ.CHARSET));

        msg.send(worker);
        System.out.println(Thread.currentThread().getName() + " Worker Sent OK");
    }

    context.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:26,代码来源:lruqueue3.java

示例4: main

import org.zeromq.ZFrame; //导入方法依赖的package包/类
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(ZMQ.CHARSET));
    worker.connect("tcp://localhost:5556");

    //  Tell broker we're ready for work
    System.out.printf("I: (%s) worker ready\n", identity);
    ZFrame frame = new ZFrame(WORKER_READY);
    frame.send(worker, 0);

    int cycles = 0;
    while (true) {
        ZMsg msg = ZMsg.recvMsg(worker);
        if (msg == null)
            break;              //  Interrupted

        //  Simulate various problems, after a few cycles
        cycles++;
        if (cycles > 3 && rand.nextInt(5) == 0) {
            System.out.printf("I: (%s) simulating a crash\n", identity);
            msg.destroy();
            break;
        } else if (cycles > 3 && rand.nextInt(5) == 0) {
            System.out.printf("I: (%s) simulating CPU overload\n", identity);
            Thread.sleep(3000);
        }
        System.out.printf("I: (%s) normal reply\n", identity);
        Thread.sleep(1000); //  Do some heavy work
        msg.send(worker);
    }
    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:39,代码来源:spworker.java

示例5: 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

示例6: worker_socket

import org.zeromq.ZFrame; //导入方法依赖的package包/类
private static Socket worker_socket(ZContext ctx)
{
    Socket worker = ctx.createSocket(ZMQ.DEALER);
    worker.connect("tcp://localhost:5556");

    //  Tell queue we're ready for work
    System.out.println("I: worker ready\n");
    ZFrame frame = new ZFrame(PPP_READY);
    frame.send(worker, 0);

    return worker;
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:13,代码来源:ppworker.java

示例7: run

import org.zeromq.ZFrame; //导入方法依赖的package包/类
@Override
public void run()
{
    Random rand = new Random(System.nanoTime());
    ZContext ctx = new ZContext();
    Socket worker = ctx.createSocket(ZMQ.REQ);
    worker.connect(String.format("ipc://%s-localbe.ipc", self));

    //  Tell broker we're ready for work
    ZFrame frame = new ZFrame(WORKER_READY);
    frame.send(worker, 0);

    while (true) {
        //  Send request, get reply
        ZMsg msg = ZMsg.recvMsg(worker, 0);
        if (msg == null)
            break;              //  Interrupted

        //  Workers are busy for 0/1 seconds
        try {
            Thread.sleep(rand.nextInt(2) * 1000);
        } catch (InterruptedException e) {
        }

        msg.send(worker);

    }
    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:30,代码来源:peering3.java

示例8: 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

示例9: 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


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