@Override public TimestampedValue<V> fromBytes(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); byte[] vBytes = new byte[bytes.length - TIMESTAMP_BYTES]; bb.get(vBytes, 0, vBytes.length); V v = vSerde.fromBytes(vBytes); long ts = bb.getLong(); return new TimestampedValue<>(v, ts); }
/** * Add a value to the list. * (Timestamp assigned to this value is the current timestamp.) * @param value The Gauge value to be added */ public void add(T value) { this.elements.add(new TimestampedValue<T>(value, Instant.now().toEpochMilli())); // perform any evictions that may be needed. this.evict(); }
@Override public TimestampedValue<V> fromBytes(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); byte[] vBytes = new byte[bytes.length - TIMESTAMP_BYTES]; bb.get(vBytes, 0, vBytes.length); V v = vSerde.fromBytes(vBytes); long ts = bb.getLong(); return new TimestampedValue<>(v, ts); }
@Override public TimestampedValue<V> fromBytes(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); byte[] vBytes = new byte[bytes.length - TIMESTAMP_BYTES]; bb.get(vBytes, 0, vBytes.length); V v = vSerde.fromBytes(vBytes); long ts = bb.getLong(); return new TimestampedValue<>(v, ts); }
/** * Add a value to the list. * (Timestamp assigned to this value is the current timestamp.) * @param value The Gauge value to be added */ public void add(T value) { this.elements.add(new TimestampedValue<T>(value, Instant.now().toEpochMilli())); // perform any evictions that may be needed. this.evict(); }
@Override public TimestampedValue<V> fromBytes(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); byte[] vBytes = new byte[bytes.length - TIMESTAMP_BYTES]; bb.get(vBytes, 0, vBytes.length); V v = vSerde.fromBytes(vBytes); long ts = bb.getLong(); return new TimestampedValue<>(v, ts); }
@Override public TimestampedValue<V> fromBytes(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); byte[] vBytes = new byte[bytes.length - TIMESTAMP_BYTES]; bb.get(vBytes, 0, vBytes.length); V v = vSerde.fromBytes(vBytes); long ts = bb.getLong(); return new TimestampedValue<>(v, ts); }
@Override public TimestampedValue<V> next() { Entry<TimeSeriesKey<K>, V> next = wrappedIterator.next(); return new TimestampedValue<>(next.getValue(), next.getKey().getTimestamp()); }
@Override public TimestampedValue<V> next() { Entry<TimeSeriesKey<K>, V> next = wrappedIterator.next(); return new TimestampedValue<>(next.getValue(), next.getKey().getTimestamp()); }
@Override public TimestampedValue<V> next() { Entry<TimeSeriesKey<K>, V> next = wrappedIterator.next(); return new TimestampedValue<>(next.getValue(), next.getKey().getTimestamp()); }
@Override public TimestampedValue<V> next() { Entry<TimeSeriesKey<K>, V> next = wrappedIterator.next(); return new TimestampedValue<>(next.getValue(), next.getKey().getTimestamp()); }
@Override public TimestampedValue<V> next() { Entry<TimeSeriesKey<K>, V> next = wrappedIterator.next(); return new TimestampedValue<>(next.getValue(), next.getKey().getTimestamp()); }
@Test public void testEmptyValueSerialization() { byte[] expectedBytes = new byte[8]; ByteBuffer.wrap(expectedBytes).putLong(1234L); TimestampedValueSerde<Integer> timestampedValueSerde = new TimestampedValueSerde<>(new IntegerSerde()); TimestampedValue<Integer> timestampedValue = new TimestampedValue<>(null, 1234L); assertTrue(Arrays.equals(expectedBytes, timestampedValueSerde.toBytes(timestampedValue))); } }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
when(mockLeftStore.get(eq(joinKey))).thenReturn(new TimestampedValue<>(mockLeftMessage, currentTimeMillis)); IncomingMessageEnvelope leftMessage = new IncomingMessageEnvelope(mock(SystemStreamPartition.class), "", "", mockLeftMessage); inputOpImpl1.onMessage(leftMessage, mock(MessageCollector.class), mock(TaskCoordinator.class)); when(mockRightStore.get(eq(joinKey))).thenReturn(new TimestampedValue<>(mockRightMessage, currentTimeMillis)); IncomingMessageEnvelope rightMessage = new IncomingMessageEnvelope(mock(SystemStreamPartition.class), "", "", mockRightMessage); inputOpImpl2.onMessage(rightMessage, mock(MessageCollector.class), mock(TaskCoordinator.class));