Java Code Examples for org.zeromq.ZMsg#pop()

The following examples show how to use org.zeromq.ZMsg#pop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoteCompleter.java    From enkan with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
    ZMsg msg = new ZMsg();
    msg.add(""); // delimiter
    msg.add(buffer);
    msg.add(Integer.toString(cursor));
    msg.send(socket);

    ZMsg response = ZMsg.recvMsg(socket);
    response.pop(); // delimiter
    while (!response.isEmpty()) {
        candidates.add(response.popString());
    }
    if (candidates.isEmpty()) return cursor;

    int delimiterPos = Math.max(buffer.lastIndexOf(' '), buffer.lastIndexOf('.'));
    if (delimiterPos > 0) {
        return delimiterPos + 1;
    } else {
        return 0;
    }
}
 
Example 2
Source File: CompletionServer.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
    while(!Thread.currentThread().isInterrupted()) {
        ZMsg msg = ZMsg.recvMsg(socket);
        ZFrame clientAddress = msg.pop();
        String input = msg.popString();
        int cursor = Integer.parseInt(msg.popString());
        int[] anchor = {-1};

        ZMsg reply = new ZMsg();
        reply.add(clientAddress.duplicate());

        String trimmedCommand = input.trim();
        if (trimmedCommand.startsWith("/")) {
            if (!trimmedCommand.contains(" ")) {
                Predicate<String> filter = trimmedCommand.equals("/") ?
                        n -> true : n -> n.startsWith(trimmedCommand.substring(1));

                commandNames.stream()
                        .filter(filter)
                        .forEach(s -> reply.add("/" + s));
                anchor[0] = 0;
            }
        }
        reply.send(socket, true);
    }
}
 
Example 3
Source File: CompletionServer.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
    while(!Thread.currentThread().isInterrupted()) {
        ZMsg msg = ZMsg.recvMsg(socket);
        ZFrame clientAddress = msg.pop();
        msg.pop(); // delimiter
        String input = msg.popString();
        int cursor = Integer.parseInt(msg.popString());
        int[] anchor = {-1};

        ZMsg reply = new ZMsg();
        reply.add(clientAddress.duplicate());
        reply.add("");

        String trimmedCommand = input.trim();
        if (trimmedCommand.startsWith("/")) {
            if (!trimmedCommand.contains(" ")) {
                Predicate<String> filter = trimmedCommand.equals("/") ?
                        n -> true : n -> n.startsWith(trimmedCommand.substring(1));

                commandNames.stream()
                        .filter(filter)
                        .forEach(s -> reply.add("/" + s));
                anchor[0] = 0;
            }
        } else {
            try {
                analysis.completionSuggestions(input, cursor, anchor).stream()
                        .map(SourceCodeAnalysis.Suggestion::continuation)
                        .forEach(reply::add);
                anchor[0] += cursor + 1;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        reply.send(socket, true);
    }
}
 
Example 4
Source File: ZmqServerTransport.java    From enkan with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String recv(long timeout) {
    ZMsg msg = ZMsg.recvMsg(socket);
    clientAddress = msg.pop();
    return msg.popString();
}