@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); }
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 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> 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 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; } }
/** * 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)); }
/** * 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(); taskContainerMappingMetadataStore.all().forEach((taskName, valueBytes) -> { String containerId = containerIdSerde.fromBytes(valueBytes); if (containerId != null) { taskNameToContainerId.put(taskName, containerId); } LOG.debug("Assignment for task {}: {}", taskName, containerId); }); return Collections.unmodifiableMap(new HashMap<>(taskNameToContainerId)); }
@Override public String fromBytes(byte[] bytes) { CoordinatorStreamMessage message = new CoordinatorStreamMessage(keySerde.fromBytes(bytes).toArray(), new HashMap<>()); return message.getKey(); }
@Override public String fromBytes(byte[] bytes) { CoordinatorStreamMessage message = new CoordinatorStreamMessage(keySerde.fromBytes(bytes).toArray(), new HashMap<>()); return message.getKey(); }
@Override public String fromBytes(byte[] bytes) { CoordinatorStreamMessage message = new CoordinatorStreamMessage(keySerde.fromBytes(bytes).toArray(), new HashMap<>()); return message.getKey(); }
@Override public String fromBytes(byte[] bytes) { CoordinatorStreamMessage message = new CoordinatorStreamMessage(keySerde.fromBytes(bytes).toArray(), new HashMap<>()); return message.getKey(); }
public Map<TaskName, TaskMode> readTaskModes() { Map<TaskName, TaskMode> taskModeMap = new HashMap<>(); taskModeMappingMetadataStore.all().forEach((taskName, valueBytes) -> { String taskMode = taskModeSerde.fromBytes(valueBytes); if (taskMode != null) { taskModeMap.put(new TaskName(taskName), TaskMode.valueOf(taskMode)); } LOG.debug("Task mode assignment for task {}: {}", taskName, taskMode); }); return Collections.unmodifiableMap(new HashMap<>(taskModeMap)); }
@Override public String fromBytes(byte[] bytes) { CoordinatorStreamMessage message = new CoordinatorStreamMessage(keySerde.fromBytes(bytes).toArray(), new HashMap<>()); return message.getKey(); }
@Override public String fromBytes(byte[] bytes) { Map<String, Object> values = messageSerde.fromBytes(bytes); CoordinatorStreamMessage message = new CoordinatorStreamMessage(new Object[]{}, values); if (type.equalsIgnoreCase(SetContainerHostMapping.TYPE)) { SetContainerHostMapping hostMapping = new SetContainerHostMapping(message); return hostMapping.getHostLocality(); } else if (type.equalsIgnoreCase(SetTaskContainerMapping.TYPE)) { SetTaskContainerMapping setTaskContainerMapping = new SetTaskContainerMapping(message); return setTaskContainerMapping.getTaskAssignment(); } else if (type.equalsIgnoreCase(SetChangelogMapping.TYPE)) { SetChangelogMapping changelogMapping = new SetChangelogMapping(message); return String.valueOf(changelogMapping.getPartition()); } else { throw new SamzaException(String.format("Unknown coordinator stream message type: %s", type)); } }
@Override public String fromBytes(byte[] bytes) { Map<String, Object> values = messageSerde.fromBytes(bytes); CoordinatorStreamMessage message = new CoordinatorStreamMessage(new Object[]{}, values); if (type.equalsIgnoreCase(SetContainerHostMapping.TYPE)) { SetContainerHostMapping hostMapping = new SetContainerHostMapping(message); return hostMapping.getHostLocality(); } else if (type.equalsIgnoreCase(SetTaskContainerMapping.TYPE)) { SetTaskContainerMapping setTaskContainerMapping = new SetTaskContainerMapping(message); return setTaskContainerMapping.getTaskAssignment(); } else if (type.equalsIgnoreCase(SetChangelogMapping.TYPE)) { SetChangelogMapping changelogMapping = new SetChangelogMapping(message); return String.valueOf(changelogMapping.getPartition()); } else { throw new SamzaException(String.format("Unknown coordinator stream message type: %s", type)); } }
@Override public Map<K, V> getAll(List<K> keys) { Map<K, V> results = new HashMap<>(); for (K key : keys) { byte[] value = map.get(keySerde.toBytes(key)); if (value != null) { results.put(key, valSerde.fromBytes(value)); } } return results; }
@Override public V get(K key) { byte[] keyBytes = keySerde.toBytes(key); byte[] valBytes = map.get(keyBytes); if (valBytes == null) return null; return valSerde.fromBytes(valBytes); }