@Override public void open(int taskNumber, int numTasks) throws IOException { this.taskNumber = taskNumber; this.numTasks = numTasks; //open a socket to push data handler = new OutputPublisher(instance, ringBuffer); }
@Override public void close() throws IOException { //signal close to output receiver handler.sendClose(taskNumber); } }
public void send(byte[] bytes) { queueMessage(bytes); }
@Override public void writeRecord(IN next) throws IOException { byte[] msg; if (serializer == null) { //startWith serializer TypeInformation<IN> typeInfo = TypeExtractor.getForObject(next); serializer = typeInfo.createSerializer(getRuntimeContext().getExecutionConfig()); //push serializer to output receiver try { handler.sendOpen(taskNumber, numTasks, SerializeUtil.serialize(serializer)); } catch (IOException e) { LOG.error("Could not serialize TypeSerializer", e); return; } } //serialize input and push to output byte[] bytes; try { bytes = SerializeUtil.serialize(next, serializer); } catch (IOException e) { LOG.error("Could not serialize input", e); return; } handler.sendRecord(bytes); }
handler.sendOpen(indexofThisSubTask, numberOfSubTasks, SerializeUtil.serialize(serializer)); return; handler.sendRecord(bytes);
@Override public void close() { //signal close to output receiver handler.sendClose( getRuntimeContext().getIndexOfThisSubtask()); }
@Override public void open(Configuration configuration) throws UnknownHostException { String jobManagerAddress = configuration .getString("jobmanager.rpc.address", "localhost"); //open a socket to push data handler = new OutputPublisher(instance, buffer); }
public void send(String string) { queueMessage(string.getBytes(StandardCharsets.UTF_8)); }
/** * Signal the closing of the output producer. * * @param taskNumber index of the subtask. */ public void sendClose(int taskNumber) { // System.out.println("close taskNumber = " + taskNumber); if (!closed.contains(taskNumber)) { String close = String.format("CLOSE %d %d", taskNumber, msgCount.get()); queueMessage(close.getBytes()); closed.add(taskNumber); } }
/** * Send a record message to the subscriber. * * @param bytes serialized record. */ public void sendRecord(byte[] bytes) { byte[] msg = Bytes.concat("REC".getBytes(), bytes); msgCount.incrementAndGet(); queueMessage(msg); }
/** * Send a opening message to the subscriber. * Signaling the start of output. * * @param taskNumber index of the subtask. * @param numTasks number of parallelism. * @param serializer serialized serializer. */ public void sendOpen(int taskNumber, int numTasks, byte[] serializer) { String open = String.format("OPEN %d %d", taskNumber, numTasks); byte[] msg = Bytes.concat((open + " ;").getBytes(), serializer); queueMessage(msg); }