Search in sources :

Example 1 with InstanceNotFountException

use of io.moyada.sharingan.infrastructure.exception.InstanceNotFountException in project dubbo-faker by moyada.

the class SofaInvoke method doInitialize.

@Override
protected void doInitialize(ClassInvocation metaDate) throws InstanceNotFountException {
    ConsumerConfig consumerConfig = new ConsumerConfig<>().setApplication(this.applicationConfig).setInterfaceId(// 指定接口
    metaDate.getClassType().getName()).setGeneric(ClassUtil.isGeneric(metaDate.getClassType())).setProtocol(// 指定协议
    sofaConfig.getProtocol()).setConcurrents(200).setRetries(0).setDirectUrl(// 指定直连地址
    sofaConfig.getDirectUrl()).setRegistry(this.registryConfigs).setRegister(false).setSubscribe(false).setConnectTimeout(sofaConfig.getTimeout()).setTimeout(sofaConfig.getTimeout());
    Object ref;
    try {
        ref = consumerConfig.refer();
    } catch (Exception e) {
        throw new InstanceNotFountException(e);
    }
    setInstance(ref);
    setMethodHandle(metaDate.getMethodHandle());
    this.consumerConfig = consumerConfig;
}
Also used : InstanceNotFountException(io.moyada.sharingan.infrastructure.exception.InstanceNotFountException) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) InstanceNotFountException(io.moyada.sharingan.infrastructure.exception.InstanceNotFountException)

Example 2 with InstanceNotFountException

use of io.moyada.sharingan.infrastructure.exception.InstanceNotFountException in project dubbo-faker by moyada.

the class SpringCloudInvoke method beforeInvoke.

/**
 * 预处理请求
 */
@Override
protected void beforeInvoke(HttpInvocation metaDate) {
    int size = hasBody ? paramSize + 1 : paramSize;
    Object[] args = new Object[size];
    for (int index = 0; index < size; index++) {
        args[index] = "";
    }
    Invocation invocation = new Invocation(args);
    Result result = execute(invocation);
    if (!result.isSuccess()) {
        String exception = result.getException();
        if (exception.contains("does not have available server")) {
            throw new InstanceNotFountException(exception);
        }
    }
}
Also used : Invocation(io.moyada.sharingan.infrastructure.invoke.Invocation) HttpInvocation(io.moyada.sharingan.infrastructure.invoke.data.HttpInvocation) InstanceNotFountException(io.moyada.sharingan.infrastructure.exception.InstanceNotFountException) Result(io.moyada.sharingan.infrastructure.invoke.data.Result)

Example 3 with InstanceNotFountException

use of io.moyada.sharingan.infrastructure.exception.InstanceNotFountException in project dubbo-faker by moyada.

the class DubboInvoke method doInitialize.

@Override
protected void doInitialize(ClassInvocation metaDate) throws InstanceNotFountException {
    // 此实例很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏
    ReferenceConfig<?> reference = new ReferenceConfig<>();
    reference.setApplication(config);
    reference.setConsumer(consumer);
    reference.setRegistries(registries);
    reference.setRetries(0);
    reference.setInterface(metaDate.getClassType());
    Object ref;
    try {
        ref = reference.get();
    } catch (Exception e) {
        throw new InstanceNotFountException(e);
    }
    setInstance(ref);
    setMethodHandle(metaDate.getMethodHandle());
    this.reference = reference;
}
Also used : ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) InstanceNotFountException(io.moyada.sharingan.infrastructure.exception.InstanceNotFountException) InstanceNotFountException(io.moyada.sharingan.infrastructure.exception.InstanceNotFountException)

Aggregations

InstanceNotFountException (io.moyada.sharingan.infrastructure.exception.InstanceNotFountException)3 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 Invocation (io.moyada.sharingan.infrastructure.invoke.Invocation)1 HttpInvocation (io.moyada.sharingan.infrastructure.invoke.data.HttpInvocation)1 Result (io.moyada.sharingan.infrastructure.invoke.data.Result)1