private void handleStdIn() { byte[] buffer = stdinSocket.recv(); logger.info("Stdin: {}", new String(buffer)); }
/** * Receive a message as a String. * * @param flags the flags to apply to the receive operation. * @param charset the charset of the resulting string. * @return the message received, as a String; null on error. */ public String recvStr(int flags, Charset charset) { byte[] data = recv(flags); if (data == null) { return null; } else { return new String(data, charset); } } /**
@Override public boolean writeStreamElement(StreamElement se) { try { ByteArrayOutputStream bais = new ByteArrayOutputStream(); Output o = new Output(bais); kryo.writeObjectOrNull(o,se,StreamElement.class); o.close(); byte[] b = bais.toByteArray(); if(sender.send(b)){ byte[] rec = sender.recv(); return rec != null && rec.length == 1 && rec[0] == 0; } } catch (Exception e) { logger.error(e.getMessage(), e); } return false; }
/** * 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; }
@Override public DataField[] getOutputFormat() { if (structure == null){ if (requester.send(vsensor)){ byte[] rec = requester.recv(); if (rec != null){ structure = kryo.readObjectOrNull(new Input(new ByteArrayInputStream(rec)),DataField[].class); if (structure != null) requester.close(); return structure; } } } return structure; }
public static void runKernelDebug(Session session) throws FileNotFoundException, InvalidKeyException, UnsupportedEncodingException, IOException { Session._DEBUG_ = true; ZContext ctx = new ZContext(); Socket channel = ctx.createSocket(ZMQ.REP); channel.bind("tcp://127.0.0.1:2222"); byte[] msg = channel.recv(); String sArgs = new String(msg, StandardCharsets.UTF_8); String[] newArgs = sArgs.split(" "); channel.send("ok"); runKernel(session, newArgs); }
public void generateMessages(int msgCount) throws InterruptedException { for (int subscribers = 0; subscribers < SUBSCRIBERS_EXPECTED; subscribers++) { byte[] value = syncservice.recv(0); syncservice.send("".getBytes(), 0); } for (int i = 0; i < msgCount; i++) { ArrayList<HashMap<String, Integer>> dataMaps = MessageQueueTestHelper.getMessages(); for (int j = 0; j < dataMaps.size(); j++) { send(dataMaps.get(j)); } } } }
public <T> void run(final Action<T> handler, final Factory<T> factory, final Class<T> typeClass) { final Schema<T> schema = RuntimeSchema.getSchema(typeClass); while (true) { final byte[] message = subscriber.recv(0); T event = factory.build(); ProtobufIOUtil.mergeFrom(message, event, schema); handler.invoke(event); } } }
/** * * @param flags the flags to apply to the receive operation. * @return the message received, as a String object; null on no message. */ public String recvStr(int flags) { byte[] msg = recv(flags); if (msg != null) { return new String(msg, CHARSET); } return null; }
public <T> T receive(Class<T> clazz) { final byte[] bytes = requester.recv(); try { return mapper.readValue(bytes, clazz); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void run() { while (true) { byte[] buf = sock.recv(0); if (buf == null) { continue; } outputPort.emit(convertFromBytesToTuple(buf)); } }
/** * Receive a message. * * @return the message received, as an array of bytes; null on error. */ public byte[] recv() { return recv(0); }
/** * necessary for publisher side to synchronize publisher and subscriber, must run after setup() * make sure subscribers all connected to the publisher, then the publisher send data after that */ public void startSyncJob() { for (int subscribers = 0; subscribers < SUBSCRIBERS_EXPECTED; subscribers++) { syncservice.recv(0); syncservice.send("".getBytes(), 0); } syncStarted = true; }
/** * Get the next message from queue * @return received messages in type byte[] */ public byte[] recv(){ return this.sub.recv(); } }
/** * necessary for publisher side to synchronize publisher and subscriber, must run after setup() * make sure subscribers all connected to the publisher, then the publisher send data after that */ public void startSyncJob() { for (int subscribers = 0; subscribers < SUBSCRIBERS_EXPECTED; subscribers++) { syncservice.recv(0); syncservice.send("".getBytes(), 0); } syncStarted = true; }
@Override public void run() { while (true) { byte[] buf = sock.recv(0); if (buf == null) { continue; } outputPort.emit(convertFromBytesToTuple(buf)); } }
/** * Receive a message. * * @return the message received, as an array of bytes; null on error. */ public byte[] recv() { return recv(0); }
public static byte[] recv(Socket socket, int flags) { return socket.recv(flags); }
private void handleHeartbeat() { byte[] buffer = hearbeatSocket.recv(0); hearbeatSocket.send(buffer); }