gpt4 book ai didi

org.zeromq.ZMsg.()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 22:50:49 58 4
gpt4 key购买 nike

本文整理了Java中org.zeromq.ZMsg.<init>()方法的一些代码示例,展示了ZMsg.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZMsg.<init>()方法的具体详情如下:
包路径:org.zeromq.ZMsg
类名称:ZMsg
方法名:<init>

ZMsg.<init>介绍

[英]Class Constructor
[中]类构造函数

代码示例

代码示例来源:origin: twosigma/beakerx

private synchronized void sendMsg(ZMQ.Socket socket, List<Message> messages) {
 if (!isShutdown()) {
  messages.forEach(message -> {
   String header = toJson(message.getHeader());
   String parent = toJson(message.getParentHeader());
   String meta = toJson(message.getMetadata());
   String content = toJson(message.getContent());
   String digest = hmac.sign(Arrays.asList(header, parent, meta, content));
   ZMsg newZmsg = new ZMsg();
   message.getIdentities().forEach(newZmsg::add);
   newZmsg.add(DELIM);
   newZmsg.add(digest.getBytes(StandardCharsets.UTF_8));
   newZmsg.add(header.getBytes(StandardCharsets.UTF_8));
   newZmsg.add(parent.getBytes(StandardCharsets.UTF_8));
   newZmsg.add(meta.getBytes(StandardCharsets.UTF_8));
   newZmsg.add(content.getBytes(StandardCharsets.UTF_8));
   message.getBuffers().forEach(x -> newZmsg.add(x));
   newZmsg.send(socket);
  });
 }
}

代码示例来源:origin: org.zeromq/jeromq

/**
 * Create a new ZMsg from one or more Strings
 *
 * @param strings
 *      Strings to add as frames.
 * @return
 *      ZMsg object
 */
public static ZMsg newStringMsg(String... strings)
{
  ZMsg msg = new ZMsg();
  for (String data : strings) {
    msg.addString(data);
  }
  return msg;
}

代码示例来源:origin: org.zeromq/jeromq

@Override
public String premiere(Socket pipe)
{
  ZMsg reply = new ZMsg();
  reply.add(ALIVE);
  reply.send(pipe);
  return name;
}

代码示例来源:origin: org.zeromq/jeromq

/**
 * Creates copy of this ZMsg.
 * Also duplicates all frame content.
 * @return
 *          The duplicated ZMsg object, else null if this ZMsg contains an empty frame set
 */
public ZMsg duplicate()
{
  if (frames.isEmpty()) {
    return null;
  }
  else {
    ZMsg msg = new ZMsg();
    for (ZFrame f : frames) {
      msg.add(f.duplicate());
    }
    return msg;
  }
}

代码示例来源:origin: org.zeromq/jeromq

return null;
ZMsg rcvMsg = new ZMsg();

代码示例来源:origin: net.unit8.enkan/enkan-repl-pseudo

@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);
  }
}

代码示例来源:origin: kawasima/enkan

@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);
  }
}

代码示例来源:origin: kawasima/enkan

@Override
  public int complete(String buffer, int cursor, List<CharSequence> candidates) {
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
    ZMsg msg = new ZMsg();
    msg.add(buffer);
    msg.add(Integer.toString(cursor));
    msg.send(socket);

    ZMsg response = ZMsg.recvMsg(socket);
    while (response != null && !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;
    }
  }
}

代码示例来源:origin: fiber-space/jupyter-kernel-jsr223

public void send() {  
  msg.header.msg_id = UUID.newID();
  JSONObject jsonMsg = msg.toJSON();        
  ZMsg newZmsg = new ZMsg();
  newZmsg.add(uuid);
  newZmsg.add(bDelimiter);
  byte[] header  = jsonMsg.getJSONObject("header").toString().getBytes();
  byte[] parent  = jsonMsg.getJSONObject("parent_header").toString().getBytes();        
  byte[] meta    = jsonMsg.getJSONObject("metadata").toString().getBytes();
  byte[] content = jsonMsg.getJSONObject("content").toString().getBytes();
  byte[] digest  = computeSignature(header, parent, meta, content);
  digest = HexBinaryConverter.toHexBinary(digest).toLowerCase().getBytes();
  newZmsg.add(digest);
  newZmsg.add(header);
  newZmsg.add(parent);
  newZmsg.add(meta);
  newZmsg.add(content);        
  newZmsg.send(socket);                
}

代码示例来源:origin: org.zeromq/jeromq

/**
 * Sends a command message to the proxy actor.
 * Can be useful for programmatic interfaces.
 * Works only with commands {@link Command#CONFIG CONFIG} and {@link Command#RESTART RESTART}.
 *
 * @param command  the command to execute.
 * @param msg      the custom message to transmit.
 * @param sync     true to read the status in synchronous way, false for asynchronous mode
 * @return the response message
 */
public ZMsg command(Command command, ZMsg msg, boolean sync)
{
  if (command == Command.CONFIG) {
    return configure(msg);
  }
  if (command == Command.RESTART) {
    String status = restart(msg);
    msg = new ZMsg();
    msg.add(status);
    return msg;
  }
  return null;
}

代码示例来源:origin: org.opendaylight.netide/shim

public boolean SendData(byte[] data) {
  ZMsg msg = new ZMsg();
  msg.add(data);
  ZMQ.Socket sendSocket = context.socket(ZMQ.PUSH);
  sendSocket.setIdentity("shim".getBytes());
  sendSocket.connect(CONTROL_ADDRESS);
  send(msg, sendSocket);
  sendSocket.close();
  return true;
}

代码示例来源:origin: org.projectreactor/reactor-net

@Override
protected void write(ByteBuffer data, final Deferred<Void, Promise<Void>> onComplete, boolean flush) {
  byte[] bytes = new byte[data.remaining()];
  data.get(bytes);
  boolean isNewMsg = MSG_UPD.compareAndSet(this, null, new ZMsg());
  ZMsg msg = MSG_UPD.get(this);
  if (isNewMsg) {
    switch (socket.getType()) {
      case ZMQ.ROUTER:
        msg.add(new ZFrame(connectionId));
        break;
      default:
    }
  }
  msg.add(new ZFrame(bytes));
  if (flush) {
    doFlush(onComplete);
  }
}

代码示例来源:origin: org.zeromq/jeromq

/**
 * Adds event types to monitor.
 * @param events the types of events to monitor.
 * @return this instance.
 */
public final ZMonitor add(Event... events)
{
  if (started) {
    System.out.println("ZMonitor: Unable to add events while already started.");
    return this;
  }
  ZMsg msg = new ZMsg();
  msg.add(ADD_EVENTS);
  for (Event evt : events) {
    msg.add(evt.name());
  }
  agent.send(msg);
  agent.recv();
  return this;
}

代码示例来源:origin: org.zeromq/jeromq

private ZMsg status()
{
  ZMsg reply = new ZMsg();
  if (!state.alive) {
    reply.add(EXITED);
  }
  else if (state.paused) {
    reply.add(PAUSED);
  }
  else if (state.started) {
    reply.add(STARTED);
  }
  else {
    reply.add(STOPPED);
  }
  return reply;
}

代码示例来源:origin: org.zeromq/jeromq

/**
 * Removes event types from monitor.
 * @param events the types of events to stop monitoring.
 * @return this instance.
 */
public final ZMonitor remove(Event... events)
{
  if (started) {
    System.out.println("ZMonitor: Unable to remove events while already started.");
    return this;
  }
  ZMsg msg = new ZMsg();
  msg.add(REMOVE_EVENTS);
  for (Event evt : events) {
    msg.add(evt.name());
  }
  agent.send(msg);
  agent.recv();
  return this;
}

代码示例来源:origin: org.zeromq/jeromq

protected ZAuth send(String command, String... datas)
{
  ZMsg msg = new ZMsg();
  msg.add(command);
  for (String data : datas) {
    msg.add(data);
  }
  agent.send(msg);
  msg.destroy();
  agent.recv();
  return this;
}

代码示例来源:origin: org.zeromq/jeromq

private ZMsg msg()
{
  ZMsg msg = new ZMsg();
  msg.add(version);
  msg.add(sequence);
  msg.add(Integer.toString(statusCode));
  msg.add(statusText);
  msg.add(userId == null ? "" : userId);
  msg.add(metadata == null ? new byte[0] : metadata.bytes());
  return msg;
}

代码示例来源:origin: org.zeromq/jeromq

/**
 * Restarts the proxy. Stays alive.
 *
 * @param hot     null to make a cold restart (closing then re-creation of the sockets)
 *  or a configuration message to perform a configurable hot restart,
 */
public String restart(ZMsg hot)
{
  ZMsg msg = new ZMsg();
  msg.add(RESTART);
  final boolean cold = hot == null;
  if (cold) {
    msg.add(Boolean.toString(false));
  }
  else {
    msg.add(Boolean.toString(true));
    msg.append(hot);
  }
  String status = EXITED;
  if (agent.send(msg)) {
    status = status(false);
  }
  return status;
}

代码示例来源:origin: kawasima/enkan

@Override
public void send(ReplResponse response) {
  @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
  ZMsg msg = new ZMsg();
  msg.add(clientAddress.duplicate());
  msg.add(fressian.write(response));
  msg.send(socket, true);
}

代码示例来源:origin: org.zeromq/jeromq

@Override
public boolean stage(Socket socket, Socket pipe, ZPoller poller, int evts)
{
  final ZMQ.Event event = ZMQ.Event.recv(socket);
  assert (event != null);
  final int code = event.getEvent();
  final String address = event.getAddress();
  assert (address != null);
  final Event type = Event.find(code);
  assert (type != null);
  final ZMsg msg = new ZMsg();
  msg.add(type.name());
  msg.add(Integer.toString(code));
  msg.add(address);
  final Object value = event.getValue();
  if (value != null) {
    msg.add(value.toString());
  }
  return msg.send(pipe, true);
}

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com