Java Code Examples for org.apache.pulsar.common.api.proto.PulsarApi#KeyValue

The following examples show how to use org.apache.pulsar.common.api.proto.PulsarApi#KeyValue . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaInfoUtil.java    From pulsar with Apache License 2.0 6 votes vote down vote up
public static SchemaInfo newSchemaInfo(Schema schema) {
    SchemaInfo si = new SchemaInfo();
    si.setName(schema.getName());
    si.setSchema(schema.getSchemaData().toByteArray());
    si.setType(Commands.getSchemaType(schema.getType()));
    if (schema.getPropertiesCount() == 0) {
        si.setProperties(Collections.emptyMap());
    } else {
        si.setProperties(new TreeMap<>());
        for (int i = 0; i < schema.getPropertiesCount(); i++) {
            PulsarApi.KeyValue kv = schema.getProperties(i);
            si.getProperties().put(kv.getKey(), kv.getValue());
        }
    }
    return si;
}
 
Example 2
Source File: CommandUtilsTests.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testToKeyValueList() {
    List<PulsarApi.KeyValue> keyValues = CommandUtils.toKeyValueList(null);
    Assert.assertNotNull(keyValues);
    Assert.assertTrue(keyValues.isEmpty());

    final Map<String, String> metadata = new HashMap<>();
    metadata.put("key1", "value1");

    keyValues = CommandUtils.toKeyValueList(metadata);
    Assert.assertEquals(keyValues.size(), keyValues.size());
    PulsarApi.KeyValue kv = keyValues.get(0);
    final Map.Entry<String, String> entry = metadata.entrySet().iterator().next();
    Assert.assertEquals(kv.getKey(), entry.getKey());
    Assert.assertEquals(kv.getValue(), entry.getValue());
}
 
Example 3
Source File: CommandUtils.java    From pulsar with Apache License 2.0 5 votes vote down vote up
static List<PulsarApi.KeyValue> toKeyValueList(Map<String, String> metadata) {
    if (metadata == null || metadata.isEmpty()) {
        return Collections.emptyList();
    }

    return metadata.entrySet().stream().map(e ->
            PulsarApi.KeyValue.newBuilder().setKey(e.getKey()).setValue(e.getValue()).build())
            .collect(Collectors.toList());
}
 
Example 4
Source File: CommandUtils.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private static Map<String, String> toMap(List<PulsarApi.KeyValue> keyValues) {
    if (keyValues == null || keyValues.isEmpty()) {
        return Collections.emptyMap();
    }

    return keyValues.stream()
            .collect(Collectors.toMap(PulsarApi.KeyValue::getKey, PulsarApi.KeyValue::getValue));
}
 
Example 5
Source File: MockMessage.java    From skywalking with Apache License 2.0 5 votes vote down vote up
public synchronized Map<String, String> getProperties() {
    if (this.properties == null) {
        if (this.msgMetadataBuilder.getPropertiesCount() > 0) {
            Map<String, String> internalProperties = new HashMap<String, String>();
            for (int i = 0; i < this.msgMetadataBuilder.getPropertiesCount(); i++) {
                PulsarApi.KeyValue kv = this.msgMetadataBuilder.getProperties(i);
                internalProperties.put(kv.getKey(), kv.getValue());
            }
            this.properties = Collections.unmodifiableMap(internalProperties);
        } else {
            this.properties = Collections.emptyMap();
        }
    }
    return this.properties;
}