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

org.jetlinks.rule.engine.api.rpc.RpcDefinition Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package org.jetlinks.rule.engine.api.rpc;

import org.jetlinks.rule.engine.api.codec.Codec;
import org.jetlinks.rule.engine.api.codec.Codecs;
import org.jetlinks.rule.engine.defaults.codec.ErrorCodec;

/**
 * Rpc定义信息
 *
 * @param  请求类型
 * @param  响应类型
 */
public interface RpcDefinition {

    /**
     * 服务地址
     *
     * @return 地址
     */
    String getAddress();

    /**
     * @return 请求编解码器
     */
    Codec requestCodec();

    /**
     * @return 响应编解码器
     */
    Codec responseCodec();

    /**
     * @return 错误相应编解码器
     */
    default Codec errorCodec() {
        return ErrorCodec.DEFAULT;
    }

    static  RpcDefinition of(String address,
                                                 Codec requestCodec,
                                                 Codec responseCodec) {
        return new DefaultRpcDefinition<>(address, requestCodec, responseCodec);
    }

    static RpcDefinition of(String address) {
        return new DefaultRpcDefinition<>(address, Codecs.lookup(Void.class), Codecs.lookup(Void.class));
    }

    static  RpcDefinition of(String address,
                                                 Class requestType,
                                                 Class responseType) {
        return new DefaultRpcDefinition<>(address, Codecs.lookup(requestType), Codecs.lookup(responseType));
    }

    static  RpcDefinition ofNoParameter(String address, Class responseType) {
        return new DefaultRpcDefinition<>(address, Codecs.lookup(Void.class), Codecs.lookup(responseType));
    }

    static  RpcDefinition ofNoResponse(String address, Class requestType) {
        return new DefaultRpcDefinition<>(address, Codecs.lookup(requestType), Codecs.lookup(Void.class));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy