@Override public byte[] toBytes(String key) { Object[] keyArray = new Object[]{CoordinatorStreamMessage.VERSION, type, key}; return keySerde.toBytes(Arrays.asList(keyArray)); } }
public KV<K, V> fromBytes(byte[] bytes) { if (bytes != null) { ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); int keyLength = byteBuffer.getInt(); byte[] keyBytes = new byte[keyLength]; byteBuffer.get(keyBytes); int valueLength = byteBuffer.getInt(); byte[] valueBytes = new byte[valueLength]; byteBuffer.get(valueBytes); K key = keySerde.fromBytes(keyBytes); V value = valueSerde.fromBytes(valueBytes); return KV.of(key, value); } else { return null; } }
@Override public byte[] toBytes(String key) { Object[] keyArray = new Object[]{CoordinatorStreamMessage.VERSION, type, key}; return keySerde.toBytes(Arrays.asList(keyArray)); } }
@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 byte[] toBytes(String key) { Object[] keyArray = new Object[]{CoordinatorStreamMessage.VERSION, type, key}; return keySerde.toBytes(Arrays.asList(keyArray)); } }
@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 byte[] toBytes(String key) { Object[] keyArray = new Object[]{CoordinatorStreamMessage.VERSION, type, key}; return keySerde.toBytes(Arrays.asList(keyArray)); } }
@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 byte[] toBytes(String key) { Object[] keyArray = new Object[]{CoordinatorStreamMessage.VERSION, type, key}; return keySerde.toBytes(Arrays.asList(keyArray)); } }
@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); }
public byte[] toBytes(KV<K, V> obj) { if (obj != null) { byte[] keyBytes = keySerde.toBytes(obj.key); byte[] valueBytes = valueSerde.toBytes(obj.value); byte[] bytes = new byte[8 + keyBytes.length + 8 + valueBytes.length]; ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.putInt(keyBytes.length); byteBuffer.put(keyBytes); byteBuffer.putInt(valueBytes.length); byteBuffer.put(valueBytes); return byteBuffer.array(); } else { return null; } }
@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); }
public byte[] toBytes(KV<K, V> obj) { if (obj != null) { byte[] keyBytes = keySerde.toBytes(obj.key); byte[] valueBytes = valueSerde.toBytes(obj.value); byte[] bytes = new byte[8 + keyBytes.length + 8 + valueBytes.length]; ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.putInt(keyBytes.length); byteBuffer.put(keyBytes); byteBuffer.putInt(valueBytes.length); byteBuffer.put(valueBytes); return byteBuffer.array(); } else { return null; } }
public KV<K, V> fromBytes(byte[] bytes) { if (bytes != null) { ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); int keyLength = byteBuffer.getInt(); byte[] keyBytes = new byte[keyLength]; byteBuffer.get(keyBytes); int valueLength = byteBuffer.getInt(); byte[] valueBytes = new byte[valueLength]; byteBuffer.get(valueBytes); K key = keySerde.fromBytes(keyBytes); V value = valueSerde.fromBytes(valueBytes); return KV.of(key, value); } else { return null; } }
/** * Deletes the task container info from the {@link MetadataStore} for the task names. * * @param taskNames the task names for which the mapping will be deleted. */ public void deleteTaskContainerMappings(Iterable<String> taskNames) { for (String taskName : taskNames) { metadataStore.delete(keySerde.toBytes(taskName)); taskNameToContainerId.remove(taskName); } }
/** * Method to allow read container task information from {@link MetadataStore}. This method is used in {@link org.apache.samza.coordinator.JobModelManager}. * * @return the map of taskName: containerId */ public Map<String, String> readTaskAssignment() { taskNameToContainerId.clear(); metadataStore.all().forEach((keyBytes, valueBytes) -> { String taskName = keySerde.fromBytes(keyBytes); String containerId = valueSerde.fromBytes(valueBytes); if (containerId != null) { taskNameToContainerId.put(taskName, containerId); } LOG.debug("Assignment for task {}: {}", taskName, containerId); }); return Collections.unmodifiableMap(new HashMap<>(taskNameToContainerId)); }
/** * Deletes the task container info from the {@link MetadataStore} for the task names. * * @param taskNames the task names for which the mapping will be deleted. */ public void deleteTaskContainerMappings(Iterable<String> taskNames) { for (String taskName : taskNames) { metadataStore.delete(keySerde.toBytes(taskName)); taskNameToContainerId.remove(taskName); } }
/** * Method to allow read container task information from {@link MetadataStore}. This method is used in {@link org.apache.samza.coordinator.JobModelManager}. * * @return the map of taskName: containerId */ public Map<String, String> readTaskAssignment() { taskNameToContainerId.clear(); metadataStore.all().forEach((keyBytes, valueBytes) -> { String taskName = keySerde.fromBytes(keyBytes); String containerId = valueSerde.fromBytes(valueBytes); if (containerId != null) { taskNameToContainerId.put(taskName, containerId); } LOG.debug("Assignment for task {}: {}", taskName, containerId); }); return Collections.unmodifiableMap(new HashMap<>(taskNameToContainerId)); }