@Override protected NFAStateSerializer createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) { @SuppressWarnings("unchecked") TypeSerializer<DeweyNumber> versionSerializer = (TypeSerializer<DeweyNumber>) nestedSerializers[0]; @SuppressWarnings("unchecked") TypeSerializer<NodeId> nodeIdSerializer = (TypeSerializer<NodeId>) nestedSerializers[1]; @SuppressWarnings("unchecked") TypeSerializer<EventId> eventIdSerializer = (TypeSerializer<EventId>) nestedSerializers[2]; return new NFAStateSerializer(versionSerializer, nodeIdSerializer, eventIdSerializer); } }
@Override public NFAState copy(NFAState from) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); serialize(from, new DataOutputViewStreamWrapper(baos)); baos.close(); byte[] data = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(data); NFAState copy = deserialize(new DataInputViewStreamWrapper(bais)); bais.close(); return copy; } catch (IOException e) { throw new RuntimeException("Could not copy NFA.", e); } }
@Override public NFAState copy(NFAState from, NFAState reuse) { return copy(from); }
nfaTestHarness.consumeRecord(new StreamRecord<>(a, 8)); NFAStateSerializer serializer = new NFAStateSerializer(); serializer.serialize(nfaState, new DataOutputViewStreamWrapper(baos)); baos.close(); serializer.duplicate().copy(new DataInputViewStreamWrapper(in), new DataOutputViewStreamWrapper(out)); in.close(); out.close(); NFAState copy = serializer.duplicate().deserialize(new DataInputViewStreamWrapper(bais)); bais.close(); assertEquals(nfaState, copy);
@Override public NFAState deserialize(DataInputView source) throws IOException { PriorityQueue<ComputationState> partialMatches = deserializeComputationStates(source); PriorityQueue<ComputationState> completedMatches = deserializeComputationStates(source); return new NFAState(partialMatches, completedMatches); }
@Override public void copy(DataInputView source, DataOutputView target) throws IOException { copyStates(source, target); // copy partial matches copyStates(source, target); // copy completed matches }
@Override public void serialize(NFAState record, DataOutputView target) throws IOException { serializeComputationStates(record.getPartialMatches(), target); serializeComputationStates(record.getCompletedMatches(), target); }
@Override public NFAState deserialize(NFAState reuse, DataInputView source) throws IOException { return deserialize(source); }
private void copyStates(DataInputView source, DataOutputView target) throws IOException { int computationStateNo = source.readInt(); target.writeInt(computationStateNo); for (int i = 0; i < computationStateNo; i++) { copySingleComputationState(source, target); } }
private void copySingleComputationState(DataInputView source, DataOutputView target) throws IOException { StringValue.copyString(source, target); NodeId prevState = nodeIdSerializer.deserialize(source); nodeIdSerializer.serialize(prevState, target); DeweyNumber version = versionSerializer.deserialize(source); versionSerializer.serialize(version, target); long startTimestamp = source.readLong(); target.writeLong(startTimestamp); copyStartEvent(source, target); }
@Override public NFAState deserialize(DataInputView source) throws IOException { PriorityQueue<ComputationState> partialMatches = deserializeComputationStates(source); PriorityQueue<ComputationState> completedMatches = deserializeComputationStates(source); return new NFAState(partialMatches, completedMatches); }
@Override public void copy(DataInputView source, DataOutputView target) throws IOException { copyStates(source, target); // copy partial matches copyStates(source, target); // copy completed matches }
@Override public void serialize(NFAState record, DataOutputView target) throws IOException { serializeComputationStates(record.getPartialMatches(), target); serializeComputationStates(record.getCompletedMatches(), target); }
@Override public NFAState deserialize(NFAState reuse, DataInputView source) throws IOException { return deserialize(source); }
@Override public NFAState copy(NFAState from) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); serialize(from, new DataOutputViewStreamWrapper(baos)); baos.close(); byte[] data = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(data); NFAState copy = deserialize(new DataInputViewStreamWrapper(bais)); bais.close(); return copy; } catch (IOException e) { throw new RuntimeException("Could not copy NFA.", e); } }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); // initializeState through the provided context computationStates = context.getKeyedStateStore().getState( new ValueStateDescriptor<>( NFA_STATE_NAME, new NFAStateSerializer())); partialMatches = new SharedBuffer<>(context.getKeyedStateStore(), inputSerializer); elementQueueState = context.getKeyedStateStore().getMapState( new MapStateDescriptor<>( EVENT_QUEUE_STATE_NAME, LongSerializer.INSTANCE, new ListSerializer<>(inputSerializer))); migrateOldState(); }
@Override public NFAState deserialize(DataInputView source) throws IOException { PriorityQueue<ComputationState> partialMatches = deserializeComputationStates(source); PriorityQueue<ComputationState> completedMatches = deserializeComputationStates(source); return new NFAState(partialMatches, completedMatches); }
@Override public void copy(DataInputView source, DataOutputView target) throws IOException { copyStates(source, target); // copy partial matches copyStates(source, target); // copy completed matches }
@Override public NFAState copy(NFAState from, NFAState reuse) { return copy(from); }
@Override public void serialize(NFAState record, DataOutputView target) throws IOException { serializeComputationStates(record.getPartialMatches(), target); serializeComputationStates(record.getCompletedMatches(), target); }