Example #1
0
    /** Writes the {@code Context} to the given state checkpoint output. */
    protected void writeToState(StateBackend.CheckpointStateOutputView out) throws IOException {
      keySerializer.serialize(key, out);
      windowSerializer.serialize(window, out);
      out.writeLong(watermarkTimer);
      out.writeLong(processingTimeTimer);

      byte[] serializedState = InstantiationUtil.serializeObject(state);
      out.writeInt(serializedState.length);
      out.write(serializedState, 0, serializedState.length);

      MultiplexingStreamRecordSerializer<IN> recordSerializer =
          new MultiplexingStreamRecordSerializer<>(inputSerializer);
      out.writeInt(windowBuffer.size());
      for (StreamRecord<IN> element : windowBuffer.getElements()) {
        recordSerializer.serialize(element, out);
      }
    }
Example #2
0
    /**
     * Constructs a new {@code Context} by reading from a {@link DataInputView} that contains a
     * serialized context that we wrote in {@link
     * #writeToState(StateBackend.CheckpointStateOutputView)}
     */
    @SuppressWarnings("unchecked")
    protected Context(DataInputView in, ClassLoader userClassloader) throws Exception {
      this.key = keySerializer.deserialize(in);
      this.window = windowSerializer.deserialize(in);
      this.watermarkTimer = in.readLong();
      this.processingTimeTimer = in.readLong();

      int stateSize = in.readInt();
      byte[] stateData = new byte[stateSize];
      in.read(stateData);
      state = InstantiationUtil.deserializeObject(stateData, userClassloader);

      this.windowBuffer = windowBufferFactory.create();
      int numElements = in.readInt();
      MultiplexingStreamRecordSerializer<IN> recordSerializer =
          new MultiplexingStreamRecordSerializer<>(inputSerializer);
      for (int i = 0; i < numElements; i++) {
        windowBuffer.storeElement(recordSerializer.deserialize(in).<IN>asRecord());
      }
    }