Search in sources :

Example 1 with SegmentInfo

use of io.pravega.segmentstore.server.containers.MetadataStore.SegmentInfo in project pravega by pravega.

the class ContainerMetadataSerializer method deserialize.

@Override
public String deserialize(ByteBuffer serializedValue) {
    StringBuilder stringValueBuilder;
    try {
        SegmentInfo data = SERIALIZER.deserialize(new ByteArraySegment(serializedValue).getReader());
        stringValueBuilder = new StringBuilder();
        appendField(stringValueBuilder, SEGMENT_ID, String.valueOf(data.getSegmentId()));
        SegmentProperties sp = data.getProperties();
        SEGMENT_PROPERTIES_FIELD_MAP.forEach((name, f) -> appendField(stringValueBuilder, name, String.valueOf(f.apply(sp))));
        sp.getAttributes().forEach((attributeId, attributeValue) -> appendField(stringValueBuilder, attributeId.toString(), attributeValue.toString()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return stringValueBuilder.toString();
}
Also used : ByteArraySegment(io.pravega.common.util.ByteArraySegment) SegmentInfo(io.pravega.segmentstore.server.containers.MetadataStore.SegmentInfo) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) IOException(java.io.IOException)

Example 2 with SegmentInfo

use of io.pravega.segmentstore.server.containers.MetadataStore.SegmentInfo in project pravega by pravega.

the class ContainerMetadataSerializer method serialize.

@Override
public ByteBuffer serialize(String value) {
    ByteBuffer buf;
    try {
        // Convert string to map with fields and values.
        Map<String, String> data = parseStringData(value);
        long segmentId = Long.parseLong(getAndRemoveIfExists(data, SEGMENT_ID));
        // Use the map to build SegmentProperties. The fields/keys are removed after being queried to ensure attributes
        // can be handled without interference. If the field/key queried does not exist we throw an IllegalArgumentException.
        StreamSegmentInformation properties = StreamSegmentInformation.builder().name(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_NAME)).sealed(Boolean.parseBoolean(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_SEALED))).startOffset(Long.parseLong(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_START_OFFSET))).length(Long.parseLong(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_LENGTH))).attributes(getAttributes(data)).build();
        SegmentInfo segment = SegmentInfo.builder().segmentId(segmentId).properties(properties).build();
        buf = SERIALIZER.serialize(segment).asByteBuffer();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return buf;
}
Also used : StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) SegmentInfo(io.pravega.segmentstore.server.containers.MetadataStore.SegmentInfo) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

SegmentInfo (io.pravega.segmentstore.server.containers.MetadataStore.SegmentInfo)2 IOException (java.io.IOException)2 ByteArraySegment (io.pravega.common.util.ByteArraySegment)1 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)1 StreamSegmentInformation (io.pravega.segmentstore.contracts.StreamSegmentInformation)1 ByteBuffer (java.nio.ByteBuffer)1