@Override protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException { // write key / namespace serializers, and their configuration snapshots TypeSerializerSerializationUtil.writeSerializersAndConfigsWithResilience( out, Arrays.asList( Tuple2.of(timersSnapshot.getKeySerializer(), timersSnapshot.getKeySerializerConfigSnapshot()), Tuple2.of(timersSnapshot.getNamespaceSerializer(), timersSnapshot.getNamespaceSerializerConfigSnapshot()))); } }
private boolean areSnapshotSerializersIncompatible(InternalTimersSnapshot<?, ?> restoredSnapshot) { return (this.keyDeserializer != null && !this.keyDeserializer.equals(restoredSnapshot.getKeySerializer())) || (this.namespaceDeserializer != null && !this.namespaceDeserializer.equals(restoredSnapshot.getNamespaceSerializer())); } }
@SuppressWarnings("unchecked") private <N> InternalTimerServiceImpl<K, N> registerOrGetTimerService( String serviceName, InternalTimersSnapshot<?, ?> restoredTimersSnapshot) { final TypeSerializer<K> keySerializer = (TypeSerializer<K>) restoredTimersSnapshot.getKeySerializer(); final TypeSerializer<N> namespaceSerializer = (TypeSerializer<N>) restoredTimersSnapshot.getNamespaceSerializer(); TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer); return timerServicesManager.registerOrGetTimerService(serviceName, timerSerializer); } }
@Override protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException { // write key / namespace serializers, and their configuration snapshots TypeSerializerSerializationUtil.writeSerializersAndConfigsWithResilience( out, Arrays.asList( Tuple2.of(timersSnapshot.getKeySerializer(), timersSnapshot.getKeySerializerConfigSnapshot()), Tuple2.of(timersSnapshot.getNamespaceSerializer(), timersSnapshot.getNamespaceSerializerConfigSnapshot()))); } }
new LegacyTimerSerializer<>( restoredTimersSnapshot.getKeySerializer(), restoredTimersSnapshot.getNamespaceSerializer());
@Override protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException { // write key / namespace serializers, and their configuration snapshots TypeSerializerSerializationUtil.writeSerializersAndConfigsWithResilience( out, Arrays.asList( Tuple2.of(timersSnapshot.getKeySerializer(), timersSnapshot.getKeySerializerConfigSnapshot()), Tuple2.of(timersSnapshot.getNamespaceSerializer(), timersSnapshot.getNamespaceSerializerConfigSnapshot()))); } }
@Override protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException { // the pre-versioned format only serializes the serializers, without their configuration snapshots try (ByteArrayOutputStreamWithPos stream = new ByteArrayOutputStreamWithPos()) { InstantiationUtil.serializeObject(stream, timersSnapshot.getKeySerializer()); InstantiationUtil.serializeObject(stream, timersSnapshot.getNamespaceSerializer()); out.write(stream.getBuf(), 0, stream.getPosition()); } } }
/** * Restore the timers (both processing and event time ones) for a given {@code keyGroupIdx}. * * @param restoredSnapshot the restored snapshot containing the key-group's timers, * and the serializers that were used to write them * @param keyGroupIdx the id of the key-group to be put in the snapshot. */ @SuppressWarnings("unchecked") public void restoreTimersForKeyGroup(InternalTimersSnapshot<?, ?> restoredSnapshot, int keyGroupIdx) { this.restoredTimersSnapshot = (InternalTimersSnapshot<K, N>) restoredSnapshot; if (areSnapshotSerializersIncompatible(restoredSnapshot)) { throw new IllegalArgumentException("Tried to restore timers " + "for the same service with different serializers."); } this.keyDeserializer = restoredTimersSnapshot.getKeySerializer(); this.namespaceDeserializer = restoredTimersSnapshot.getNamespaceSerializer(); checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range."); // restore the event time timers eventTimeTimersQueue.addAll(restoredTimersSnapshot.getEventTimeTimers()); // restore the processing time timers processingTimeTimersQueue.addAll(restoredTimersSnapshot.getProcessingTimeTimers()); }
@Override public final void writeTimersSnapshot(DataOutputView out) throws IOException { writeKeyAndNamespaceSerializers(out); LegacyTimerSerializer<K, N> timerSerializer = new LegacyTimerSerializer<>( timersSnapshot.getKeySerializer(), timersSnapshot.getNamespaceSerializer()); // write the event time timers Set<TimerHeapInternalTimer<K, N>> eventTimers = timersSnapshot.getEventTimeTimers(); if (eventTimers != null) { out.writeInt(eventTimers.size()); for (TimerHeapInternalTimer<K, N> eventTimer : eventTimers) { timerSerializer.serialize(eventTimer, out); } } else { out.writeInt(0); } // write the processing time timers Set<TimerHeapInternalTimer<K, N>> processingTimers = timersSnapshot.getProcessingTimeTimers(); if (processingTimers != null) { out.writeInt(processingTimers.size()); for (TimerHeapInternalTimer<K, N> processingTimer : processingTimers) { timerSerializer.serialize(processingTimer, out); } } else { out.writeInt(0); } } }
private boolean areSnapshotSerializersIncompatible(InternalTimersSnapshot<?, ?> restoredSnapshot) { return (this.keyDeserializer != null && !this.keyDeserializer.equals(restoredSnapshot.getKeySerializer())) || (this.namespaceDeserializer != null && !this.namespaceDeserializer.equals(restoredSnapshot.getNamespaceSerializer())); } }
@SuppressWarnings("unchecked") private <N> InternalTimerServiceImpl<K, N> registerOrGetTimerService( String serviceName, InternalTimersSnapshot<?, ?> restoredTimersSnapshot) { final TypeSerializer<K> keySerializer = (TypeSerializer<K>) restoredTimersSnapshot.getKeySerializer(); final TypeSerializer<N> namespaceSerializer = (TypeSerializer<N>) restoredTimersSnapshot.getNamespaceSerializer(); TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer); return timerServicesManager.registerOrGetTimerService(serviceName, timerSerializer); } }
private boolean areSnapshotSerializersIncompatible(InternalTimersSnapshot<?, ?> restoredSnapshot) { return (this.keyDeserializer != null && !this.keyDeserializer.equals(restoredSnapshot.getKeySerializer())) || (this.namespaceDeserializer != null && !this.namespaceDeserializer.equals(restoredSnapshot.getNamespaceSerializer())); } }
@SuppressWarnings("unchecked") private <N> InternalTimerServiceImpl<K, N> registerOrGetTimerService( String serviceName, InternalTimersSnapshot<?, ?> restoredTimersSnapshot) { final TypeSerializer<K> keySerializer = (TypeSerializer<K>) restoredTimersSnapshot.getKeySerializer(); final TypeSerializer<N> namespaceSerializer = (TypeSerializer<N>) restoredTimersSnapshot.getNamespaceSerializer(); TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer); return timerServicesManager.registerOrGetTimerService(serviceName, timerSerializer); } }
new LegacyTimerSerializer<>( restoredTimersSnapshot.getKeySerializer(), restoredTimersSnapshot.getNamespaceSerializer());
@Override protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException { // the pre-versioned format only serializes the serializers, without their configuration snapshots try (ByteArrayOutputStreamWithPos stream = new ByteArrayOutputStreamWithPos()) { InstantiationUtil.serializeObject(stream, timersSnapshot.getKeySerializer()); InstantiationUtil.serializeObject(stream, timersSnapshot.getNamespaceSerializer()); out.write(stream.getBuf(), 0, stream.getPosition()); } } }
@Override protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException { // the pre-versioned format only serializes the serializers, without their configuration snapshots try (ByteArrayOutputStreamWithPos stream = new ByteArrayOutputStreamWithPos()) { InstantiationUtil.serializeObject(stream, timersSnapshot.getKeySerializer()); InstantiationUtil.serializeObject(stream, timersSnapshot.getNamespaceSerializer()); out.write(stream.getBuf(), 0, stream.getPosition()); } } }
/** * Restore the timers (both processing and event time ones) for a given {@code keyGroupIdx}. * * @param restoredSnapshot the restored snapshot containing the key-group's timers, * and the serializers that were used to write them * @param keyGroupIdx the id of the key-group to be put in the snapshot. */ @SuppressWarnings("unchecked") public void restoreTimersForKeyGroup(InternalTimersSnapshot<?, ?> restoredSnapshot, int keyGroupIdx) { this.restoredTimersSnapshot = (InternalTimersSnapshot<K, N>) restoredSnapshot; if (areSnapshotSerializersIncompatible(restoredSnapshot)) { throw new IllegalArgumentException("Tried to restore timers " + "for the same service with different serializers."); } this.keyDeserializer = restoredTimersSnapshot.getKeySerializer(); this.namespaceDeserializer = restoredTimersSnapshot.getNamespaceSerializer(); checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range."); // restore the event time timers eventTimeTimersQueue.addAll(restoredTimersSnapshot.getEventTimeTimers()); // restore the processing time timers processingTimeTimersQueue.addAll(restoredTimersSnapshot.getProcessingTimeTimers()); }
/** * Restore the timers (both processing and event time ones) for a given {@code keyGroupIdx}. * * @param restoredSnapshot the restored snapshot containing the key-group's timers, * and the serializers that were used to write them * @param keyGroupIdx the id of the key-group to be put in the snapshot. */ @SuppressWarnings("unchecked") public void restoreTimersForKeyGroup(InternalTimersSnapshot<?, ?> restoredSnapshot, int keyGroupIdx) { this.restoredTimersSnapshot = (InternalTimersSnapshot<K, N>) restoredSnapshot; if (areSnapshotSerializersIncompatible(restoredSnapshot)) { throw new IllegalArgumentException("Tried to restore timers " + "for the same service with different serializers."); } this.keyDeserializer = restoredTimersSnapshot.getKeySerializer(); this.namespaceDeserializer = restoredTimersSnapshot.getNamespaceSerializer(); checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range."); // restore the event time timers eventTimeTimersQueue.addAll(restoredTimersSnapshot.getEventTimeTimers()); // restore the processing time timers processingTimeTimersQueue.addAll(restoredTimersSnapshot.getProcessingTimeTimers()); }
@Override public final void writeTimersSnapshot(DataOutputView out) throws IOException { writeKeyAndNamespaceSerializers(out); LegacyTimerSerializer<K, N> timerSerializer = new LegacyTimerSerializer<>( timersSnapshot.getKeySerializer(), timersSnapshot.getNamespaceSerializer()); // write the event time timers Set<TimerHeapInternalTimer<K, N>> eventTimers = timersSnapshot.getEventTimeTimers(); if (eventTimers != null) { out.writeInt(eventTimers.size()); for (TimerHeapInternalTimer<K, N> eventTimer : eventTimers) { timerSerializer.serialize(eventTimer, out); } } else { out.writeInt(0); } // write the processing time timers Set<TimerHeapInternalTimer<K, N>> processingTimers = timersSnapshot.getProcessingTimeTimers(); if (processingTimers != null) { out.writeInt(processingTimers.size()); for (TimerHeapInternalTimer<K, N> processingTimer : processingTimers) { timerSerializer.serialize(processingTimer, out); } } else { out.writeInt(0); } } }
@Override public final void writeTimersSnapshot(DataOutputView out) throws IOException { writeKeyAndNamespaceSerializers(out); LegacyTimerSerializer<K, N> timerSerializer = new LegacyTimerSerializer<>( timersSnapshot.getKeySerializer(), timersSnapshot.getNamespaceSerializer()); // write the event time timers Set<TimerHeapInternalTimer<K, N>> eventTimers = timersSnapshot.getEventTimeTimers(); if (eventTimers != null) { out.writeInt(eventTimers.size()); for (TimerHeapInternalTimer<K, N> eventTimer : eventTimers) { timerSerializer.serialize(eventTimer, out); } } else { out.writeInt(0); } // write the processing time timers Set<TimerHeapInternalTimer<K, N>> processingTimers = timersSnapshot.getProcessingTimeTimers(); if (processingTimers != null) { out.writeInt(processingTimers.size()); for (TimerHeapInternalTimer<K, N> processingTimer : processingTimers) { timerSerializer.serialize(processingTimer, out); } } else { out.writeInt(0); } } }