All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yamcs.artemis.EventTupleTranslator Maven / Gradle / Ivy

There is a newer version: 4.10.9
Show newest version
package org.yamcs.artemis;

import org.apache.activemq.artemis.api.core.client.ClientMessage;
import org.yamcs.StandardTupleDefinitions;
import org.yamcs.api.artemis.ArtemisApiException;
import org.yamcs.api.artemis.Protocol;
import org.yamcs.protobuf.Yamcs.Event;
import org.yamcs.yarch.Tuple;
import org.yamcs.yarch.TupleDefinition;

public class EventTupleTranslator implements TupleTranslator {

    @Override
    public ClientMessage buildMessage(ClientMessage msg, Tuple tuple) {
        Event event = (Event) tuple.getColumn("body");
        Protocol.encode(msg, event);
        return msg;
    }

    @Override
    public Tuple buildTuple(ClientMessage msg) {
        TupleDefinition tdef = StandardTupleDefinitions.EVENT;
        try {
            Event event = (Event) Protocol.decode(msg, Event.newBuilder());
            return new Tuple(tdef, new Object[] { event.getGenerationTime(),
                    event.getSource(), event.getSeqNumber(), event });
        } catch (ArtemisApiException e) {
            throw new IllegalArgumentException(e.toString(), e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy