Search in sources :

Example 6 with Msg

use of com.dexels.navajo.document.stream.api.Msg in project navajo by Dexels.

the class StreamDocument method replicationToMessage.

public static Message replicationToMessage(ImmutableMessage msg, String name, boolean isArrayElement) {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(n, name, isArrayElement ? Message.MSG_TYPE_ARRAY_ELEMENT : Message.MSG_TYPE_SIMPLE);
    List<Property> pp = msg.columnNames().stream().map(e -> {
        String type = msg.columnType(e);
        Optional<Object> value = msg.value(e);
        Property p = NavajoFactory.getInstance().createProperty(n, e, type, "", 0, "", Property.DIR_OUT);
        if (value.isPresent()) {
            p.setAnyValue(value.get());
        }
        return p;
    }).collect(Collectors.toList());
    pp.stream().forEach(p -> m.addProperty(p));
    msg.subMessageListMap().forEach((msgName, submessages) -> {
        Message subArray = NavajoFactory.getInstance().createMessage(n, msgName, Message.MSG_TYPE_ARRAY_ELEMENT);
        submessages.forEach(repl -> {
            subArray.addElement(replicationToMessage(repl, msgName, true));
        });
        m.addMessage(subArray);
    });
    msg.subMessageMap().forEach((msgName, subMessage) -> m.addMessage(replicationToMessage(subMessage, msgName, false)));
    return m;
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ByteBuffer(java.nio.ByteBuffer) FlowableTransformer(io.reactivex.FlowableTransformer) Map(java.util.Map) Events(com.dexels.navajo.document.stream.events.Events) Navajo(com.dexels.navajo.document.Navajo) FlowableOperator(io.reactivex.FlowableOperator) CharBuffer(java.nio.CharBuffer) Message(com.dexels.navajo.document.Message) CharsetDecoder(java.nio.charset.CharsetDecoder) Collectors(java.util.stream.Collectors) NavajoFactory(com.dexels.navajo.document.NavajoFactory) List(java.util.List) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) FlowableSubscriber(io.reactivex.FlowableSubscriber) Disposable(io.reactivex.disposables.Disposable) ObservableTransformer(io.reactivex.ObservableTransformer) SingleTransformer(io.reactivex.SingleTransformer) BaseFlowableOperator(com.dexels.navajo.document.stream.io.BaseFlowableOperator) Optional(java.util.Optional) BackpressureAdministrator(com.dexels.navajo.document.stream.base.BackpressureAdministrator) Property(com.dexels.navajo.document.Property) Binary(com.dexels.navajo.document.types.Binary) CharacterCodingException(java.nio.charset.CharacterCodingException) Method(com.dexels.navajo.document.stream.api.Method) HashMap(java.util.HashMap) Function(java.util.function.Function) Stack(java.util.Stack) CoderResult(java.nio.charset.CoderResult) Charset(java.nio.charset.Charset) Flowable(io.reactivex.Flowable) NavajoEventTypes(com.dexels.navajo.document.stream.events.NavajoStreamEvent.NavajoEventTypes) Msg(com.dexels.navajo.document.stream.api.Msg) ObservableNavajoParser(com.dexels.navajo.document.stream.xml.ObservableNavajoParser) Observable(io.reactivex.Observable) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Prop(com.dexels.navajo.document.stream.api.Prop) Subscriber(org.reactivestreams.Subscriber) XMLEvent(com.dexels.navajo.document.stream.xml.XMLEvent) Logger(org.slf4j.Logger) ObservableOperator(io.reactivex.ObservableOperator) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Consumer(io.reactivex.functions.Consumer) File(java.io.File) ImmutableFactory(com.dexels.immutable.factory.ImmutableFactory) AbstractMap(java.util.AbstractMap) Subscription(org.reactivestreams.Subscription) Observer(io.reactivex.Observer) NavajoHead(com.dexels.navajo.document.stream.api.NavajoHead) Bytes(com.github.davidmoten.rx2.Bytes) Collections(java.util.Collections) InputStream(java.io.InputStream) Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Optional(java.util.Optional) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 7 with Msg

use of com.dexels.navajo.document.stream.api.Msg in project navajo by Dexels.

the class NavajoEventToImmutableProcessor method event.

public void event(NavajoStreamEvent event) {
    switch(event.type()) {
        case ARRAY_STARTED:
            arrayCounter.set(0);
            currentArray.clear();
        case MESSAGE_STARTED:
        case MESSAGE_DEFINITION_STARTED:
            // TODO ignore definition messages?
            pathStack.push(event.path());
        case ARRAY_ELEMENT_STARTED:
            break;
        case MESSAGE:
        case ARRAY_ELEMENT:
            Msg m = (Msg) event.body();
            arrayCounter.incrementAndGet();
            m.toImmutableMessage();
            break;
        case NAVAJO_DONE:
        case NAVAJO_STARTED:
        case BINARY_STARTED:
        case BINARY_CONTENT:
        case BINARY_DONE:
        case ARRAY_DONE:
        case MESSAGE_DEFINITION:
            return;
        default:
            throw new UnsupportedOperationException("Unknown event found in NAVADOC: " + event.type());
    }
// }
}
Also used : Msg(com.dexels.navajo.document.stream.api.Msg)

Example 8 with Msg

use of com.dexels.navajo.document.stream.api.Msg in project navajo by Dexels.

the class NavajoStreamEvent method toString.

@SuppressWarnings("unchecked")
public String toString() {
    if (type == NavajoEventTypes.NAVAJO_STARTED) {
        NavajoHead h = (NavajoHead) body;
        return "Type: " + type + " path: " + path + " attributes: {" + attributes + "} - RPCNAME: " + h.name() + " user: " + h.username();
    }
    if (type == NavajoEventTypes.MESSAGE) {
        Msg msgBody = (Msg) body;
        List<Prop> contents = msgBody.properties();
        StringBuilder sb = new StringBuilder("Message detected. Name: " + path + " with mode: " + this.attributes.get("mode") + "\n");
        for (Prop prop : contents) {
            sb.append("Prop: " + prop.name() + " = " + prop.value() + " value type: " + prop.type() + "with direction: " + prop.direction() + "\n");
            if (prop.value() != null) {
                sb.append("   -> value class: " + prop.value().getClass() + "\n");
            }
        }
        return sb.toString();
    }
    if (type == NavajoEventTypes.NAVAJO_DONE) {
        List<String> methods = (List<String>) body;
        return "Navajo Done. Methods: " + methods;
    }
    return "Type: " + type + " path: " + path + " attributes: {" + attributes + "} " + body;
}
Also used : Msg(com.dexels.navajo.document.stream.api.Msg) Prop(com.dexels.navajo.document.stream.api.Prop) NavajoHead(com.dexels.navajo.document.stream.api.NavajoHead) List(java.util.List)

Aggregations

Msg (com.dexels.navajo.document.stream.api.Msg)8 Prop (com.dexels.navajo.document.stream.api.Prop)5 List (java.util.List)5 Message (com.dexels.navajo.document.Message)4 NavajoHead (com.dexels.navajo.document.stream.api.NavajoHead)4 IOException (java.io.IOException)4 Method (com.dexels.navajo.document.stream.api.Method)3 NavajoStreamEvent (com.dexels.navajo.document.stream.events.NavajoStreamEvent)3 Optional (java.util.Optional)3 Stack (java.util.Stack)3 ImmutableFactory (com.dexels.immutable.factory.ImmutableFactory)2 Navajo (com.dexels.navajo.document.Navajo)2 NavajoFactory (com.dexels.navajo.document.NavajoFactory)2 Property (com.dexels.navajo.document.Property)2 NavajoEventTypes (com.dexels.navajo.document.stream.events.NavajoStreamEvent.NavajoEventTypes)2 BaseFlowableOperator (com.dexels.navajo.document.stream.io.BaseFlowableOperator)2 Binary (com.dexels.navajo.document.types.Binary)2 Bytes (com.github.davidmoten.rx2.Bytes)2 FlowableSubscriber (io.reactivex.FlowableSubscriber)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2