Search in sources :

Example 11 with MessageAnnotations

use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.

the class MessageAnnotationsTypeDecoder method readArrayElements.

@Override
public MessageAnnotations[] readArrayElements(InputStream stream, StreamDecoderState state, int count) throws DecodeException {
    final StreamTypeDecoder<?> decoder = state.getDecoder().readNextTypeDecoder(stream, state);
    final MessageAnnotations[] result = new MessageAnnotations[count];
    if (decoder instanceof NullTypeDecoder) {
        for (int i = 0; i < count; ++i) {
            decoder.readValue(stream, state);
            result[i] = new MessageAnnotations(null);
        }
        return result;
    }
    final MapTypeDecoder mapDecoder = checkIsExpectedTypeAndCast(MapTypeDecoder.class, decoder);
    for (int i = 0; i < count; ++i) {
        result[i] = new MessageAnnotations(readMap(stream, state, mapDecoder));
    }
    return result;
}
Also used : NullTypeDecoder(org.apache.qpid.protonj2.codec.decoders.primitives.NullTypeDecoder) MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations) MapTypeDecoder(org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder)

Example 12 with MessageAnnotations

use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.

the class MessageAnnotationsTypeDecoder method readArrayElements.

@Override
public MessageAnnotations[] readArrayElements(ProtonBuffer buffer, DecoderState state, int count) throws DecodeException {
    final TypeDecoder<?> decoder = state.getDecoder().readNextTypeDecoder(buffer, state);
    final MessageAnnotations[] result = new MessageAnnotations[count];
    if (decoder instanceof NullTypeDecoder) {
        for (int i = 0; i < count; ++i) {
            decoder.readValue(buffer, state);
            result[i] = new MessageAnnotations(null);
        }
        return result;
    }
    final MapTypeDecoder mapDecoder = checkIsExpectedTypeAndCast(MapTypeDecoder.class, decoder);
    for (int i = 0; i < count; ++i) {
        result[i] = new MessageAnnotations(readMap(buffer, state, mapDecoder));
    }
    return result;
}
Also used : NullTypeDecoder(org.apache.qpid.protonj2.codec.decoders.primitives.NullTypeDecoder) MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations) MapTypeDecoder(org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder)

Example 13 with MessageAnnotations

use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.

the class Benchmark method benchmarkMessageAnnotations.

private void benchmarkMessageAnnotations() throws IOException {
    MessageAnnotations annotations = new MessageAnnotations(new HashMap<>());
    annotations.getValue().put(Symbol.valueOf("test1"), UnsignedByte.valueOf((byte) 128));
    annotations.getValue().put(Symbol.valueOf("test2"), UnsignedShort.valueOf((short) 128));
    annotations.getValue().put(Symbol.valueOf("test3"), UnsignedInteger.valueOf((byte) 128));
    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        buffer.clear();
        encoder.writeObject(buffer, encoderState, annotations);
    }
    resultSet.encodesComplete();
    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        buffer.setReadIndex(0);
        decoder.readObject(buffer, decoderState);
    }
    resultSet.decodesComplete();
    time("MessageAnnotations", resultSet);
}
Also used : MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations)

Example 14 with MessageAnnotations

use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.

the class MessageAnnotationsBenchmark method initMessageAnnotations.

private void initMessageAnnotations() {
    annotations = new MessageAnnotations(new HashMap<Symbol, Object>());
    annotations.getValue().put(Symbol.valueOf("test1"), UnsignedByte.valueOf((byte) 128));
    annotations.getValue().put(Symbol.valueOf("test2"), UnsignedShort.valueOf((short) 128));
    annotations.getValue().put(Symbol.valueOf("test3"), UnsignedInteger.valueOf((byte) 128));
}
Also used : HashMap(java.util.HashMap) MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations)

Example 15 with MessageAnnotations

use of org.apache.qpid.protonj2.types.messaging.MessageAnnotations in project qpid-protonj2 by apache.

the class MessageAnnotationsTypeCodecTest method doTestEncodeAndDecodeAnnotationsWithEmbeddedMaps.

private void doTestEncodeAndDecodeAnnotationsWithEmbeddedMaps(boolean fromStream) throws IOException {
    final Symbol SYMBOL_1 = Symbol.valueOf("x-opt-test1");
    final Symbol SYMBOL_2 = Symbol.valueOf("x-opt-test2");
    final String VALUE_1 = "string";
    final UnsignedInteger VALUE_2 = UnsignedInteger.valueOf(42);
    final UUID VALUE_3 = UUID.randomUUID();
    Map<String, Object> stringKeyedMap = new HashMap<>();
    stringKeyedMap.put("key1", VALUE_1);
    stringKeyedMap.put("key2", VALUE_2);
    stringKeyedMap.put("key3", VALUE_3);
    Map<Symbol, Object> symbolKeyedMap = new HashMap<>();
    symbolKeyedMap.put(Symbol.valueOf("key1"), VALUE_1);
    symbolKeyedMap.put(Symbol.valueOf("key2"), VALUE_2);
    symbolKeyedMap.put(Symbol.valueOf("key3"), VALUE_3);
    MessageAnnotations annotations = new MessageAnnotations(new HashMap<>());
    annotations.getValue().put(SYMBOL_1, stringKeyedMap);
    annotations.getValue().put(SYMBOL_2, symbolKeyedMap);
    ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
    InputStream stream = new ProtonBufferInputStream(buffer);
    encoder.writeObject(buffer, encoderState, annotations);
    final Object result;
    if (fromStream) {
        result = streamDecoder.readObject(stream, streamDecoderState);
    } else {
        result = decoder.readObject(buffer, decoderState);
    }
    assertNotNull(result);
    assertTrue(result instanceof MessageAnnotations);
    MessageAnnotations readAnnotations = (MessageAnnotations) result;
    Map<Symbol, Object> resultMap = readAnnotations.getValue();
    assertEquals(annotations.getValue().size(), resultMap.size());
    assertEquals(resultMap.get(SYMBOL_1), stringKeyedMap);
    assertEquals(resultMap.get(SYMBOL_2), symbolKeyedMap);
}
Also used : ProtonBuffer(org.apache.qpid.protonj2.buffer.ProtonBuffer) HashMap(java.util.HashMap) Symbol(org.apache.qpid.protonj2.types.Symbol) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) InputStream(java.io.InputStream) MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) UnsignedInteger(org.apache.qpid.protonj2.types.UnsignedInteger) UUID(java.util.UUID)

Aggregations

MessageAnnotations (org.apache.qpid.protonj2.types.messaging.MessageAnnotations)19 ProtonBuffer (org.apache.qpid.protonj2.buffer.ProtonBuffer)9 InputStream (java.io.InputStream)8 Symbol (org.apache.qpid.protonj2.types.Symbol)8 HashMap (java.util.HashMap)7 ProtonBufferInputStream (org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)7 Header (org.apache.qpid.protonj2.types.messaging.Header)6 Properties (org.apache.qpid.protonj2.types.messaging.Properties)6 Test (org.junit.jupiter.api.Test)6 ApplicationProperties (org.apache.qpid.protonj2.types.messaging.ApplicationProperties)5 Footer (org.apache.qpid.protonj2.types.messaging.Footer)4 URI (java.net.URI)3 Client (org.apache.qpid.protonj2.client.Client)3 Connection (org.apache.qpid.protonj2.client.Connection)3 StreamDelivery (org.apache.qpid.protonj2.client.StreamDelivery)3 StreamReceiver (org.apache.qpid.protonj2.client.StreamReceiver)3 StreamReceiverMessage (org.apache.qpid.protonj2.client.StreamReceiverMessage)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 MapTypeDecoder (org.apache.qpid.protonj2.codec.decoders.primitives.MapTypeDecoder)2