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

org.jetlinks.supports.server.DefaultClientMessageHandler Maven / Gradle / Ivy

The newest version!
package org.jetlinks.supports.server;

import lombok.AllArgsConstructor;
import org.jetlinks.core.device.DeviceOperator;
import org.jetlinks.core.message.Message;
import org.jetlinks.core.message.codec.MessageDecodeContext;
import org.jetlinks.core.message.codec.Transport;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@AllArgsConstructor
public class DefaultClientMessageHandler implements ClientMessageHandler {

    private DecodedClientMessageHandler messageHandler;

    @Override
    public Mono handleMessage(DeviceOperator operator, Transport transport, MessageDecodeContext message) {
        return operator
                .getProtocol()
                .flatMap(protocolSupport -> protocolSupport.getMessageCodec(transport))
                .flatMapMany(codec -> Flux.from(codec.decode(message)))
                .flatMap(msg -> messageHandler.handleMessage(operator, msg))
                .all(success -> success);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy