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


Java Socket.hasReceiveMore方法代码示例

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


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

示例1: receive

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
private Message receive(final Socket zmqSocket, final boolean failOnNull) throws IOException
{
    byte[] frame = zmqSocket.recv();

    if (frame == null)
    {
        if (failOnNull)
        {
            throw new IOException("Received null first frame after waiting " + receiveTimeoutMillis
                                  + "ms");
        }
        else
        {
            return null;
        }
    }

    final List<byte[]> frames = new ArrayList<>();

    do
    {
        frames.add(frame);
    }
    while (zmqSocket.hasReceiveMore() && ((frame = zmqSocket.recv()) != null));

    return protocol.fromFrames(frames);
}
 
开发者ID:openanalytics,项目名称:japyter,代码行数:28,代码来源:Session.java

示例2: recv

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
 * Internal method to call recv on the socket.
 * Does not trap any ZMQExceptions but expects caling routine to handle them.
 * @param socket
 *          0MQ socket to read from
 * @return
 *          byte[] data
 */
private byte[] recv(Socket socket, int flags) {
    if (socket == null)
        throw new IllegalArgumentException("socket parameter must not be null");
    
    data = socket.recv(flags);
    more = socket.hasReceiveMore();
    return data;
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:17,代码来源:ZFrame.java

示例3: dump

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
 * Receives all message parts from socket, prints neatly
 */
public static void dump (Socket sock)
{
    System.out.println("----------------------------------------");
    while(true) {
        byte [] msg = sock.recv (0);
        boolean isText = true;
        String data = "";
        for (int i = 0; i< msg.length; i++) {
            if (msg[i] < 32 || msg[i] > 127)
                isText = false;
            data += String.format ("%02X", msg[i]);
        }
        if (isText)
            data = new String (msg, ZMQ.CHARSET);

        System.out.println (String.format ("[%03d] %s", msg.length, data));
        if (!sock.hasReceiveMore ())
            break;
    }
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:24,代码来源:ZHelper.java

示例4: recv

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
 * Internal method to call recv on the socket. Does not trap any ZMQExceptions but expects caling routine to handle
 * them.
 * 
 * @param socket 0MQ socket to read from
 * @return Byte array
 */
private byte[] recv(Socket socket, int flags) {
    if (socket == null)
        throw new IllegalArgumentException("socket parameter must not be null");

    data = socket.recv(flags);
    more = socket.hasReceiveMore();
    return data;
}
 
开发者ID:zeromq,项目名称:jzmq3-x,代码行数:16,代码来源:ZFrame.java

示例5: recv

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static kvmsg recv(Socket socket)
{
    //  This method is almost unchanged from kvsimple
    //  .skip
    assert (socket != null);
    kvmsg self = new kvmsg(0);

    //  Read all frames off the wire, reject if bogus
    int frameNbr;
    for (frameNbr = 0; frameNbr < KVMSG_FRAMES; frameNbr++) {
        //zmq_msg_init (&self->frame [frameNbr]);
        self.present[frameNbr] = true;
        if ((self.frame[frameNbr] = socket.recv(0)) == null) {
            self.destroy();
            break;
        }
        //  Verify multipart framing
        boolean rcvmore = (frameNbr < KVMSG_FRAMES - 1)? true: false;
        if (socket.hasReceiveMore() != rcvmore) {
            self.destroy();
            break;
        }
    }
    //  .until
    self.decodeProps();
    return self;
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:28,代码来源:kvmsg.java

示例6: recv

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static kvsimple recv(Socket updates) {
       byte [] data = updates.recv(0);
       if (data == null || !updates.hasReceiveMore())
           return null;
	String key = new String(data, ZMQ.CHARSET);
       data = updates.recv(0);
       if (data == null || !updates.hasReceiveMore())
           return null;
	Long sequence = ByteBuffer.wrap(data).getLong();
	byte[] body = updates.recv(0);
       if (body == null || updates.hasReceiveMore())
           return null;

	return new kvsimple(key, sequence, body);
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:16,代码来源:kvsimple.java

示例7: hasRecvMore

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static boolean hasRecvMore(Socket socket) {
	return socket.hasReceiveMore();
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:4,代码来源:ZeroMq.java

示例8: recv

import org.zeromq.ZMQ.Socket; //导入方法依赖的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

示例9: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void main (String[] args) {
    //  Prepare our context and sockets
    Context context = ZMQ.context(1);

    Socket frontend = context.socket(ZMQ.ROUTER);
    Socket backend  = context.socket(ZMQ.DEALER);
    frontend.bind("tcp://*:5559");
    backend.bind("tcp://*:5560");

    System.out.println("launch and connect broker.");

    //  Initialize poll set
    Poller items = new Poller (2);
    items.register(frontend, Poller.POLLIN);
    items.register(backend, Poller.POLLIN);

    boolean more = false;
    byte[] message;

    //  Switch messages between sockets
    while (!Thread.currentThread().isInterrupted()) {            
        //  poll and memorize multipart detection
        items.poll();

        if (items.pollin(0)) {
            while (true) {
                // receive message
                message = frontend.recv(0);
                more = frontend.hasReceiveMore();

                // Broker it
                backend.send(message, more ? ZMQ.SNDMORE : 0);
                if(!more){
                    break;
                }
            }
        }
        if (items.pollin(1)) {
            while (true) {
                // receive message
                message = backend.recv(0);
                more = backend.hasReceiveMore();
                // Broker it
                frontend.send(message,  more ? ZMQ.SNDMORE : 0);
                if(!more){
                    break;
                }
            }
        }
    }
    //  We never get here but clean up anyhow
    frontend.close();
    backend.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:56,代码来源:rrbroker.java


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