Search in sources :

Example 21 with SofaRpcRuntimeException

use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.

the class RegistryFactoryTest method getRegistry.

@Test
public void getRegistry() {
    try {
        RegistryConfig registryConfig = new RegistryConfig().setProtocol("test111");
        Registry registry = RegistryFactory.getRegistry(registryConfig);
        Assert.fail();
    } catch (Exception e) {
        Assert.assertTrue(e instanceof SofaRpcRuntimeException);
    }
    {
        RegistryConfig registryConfig = new RegistryConfig().setProtocol("test");
        Registry registry = RegistryFactory.getRegistry(registryConfig);
        Assert.assertTrue(registry instanceof TestRegistry);
        registry.destroy(new Destroyable.DestroyHook() {

            @Override
            public void preDestroy() {
            }

            @Override
            public void postDestroy() {
            }
        });
    }
    for (int i = 0; i < 3; i++) {
        RegistryConfig registryConfig = new RegistryConfig().setProtocol("test").setTimeout(1000 + i);
        Registry registry = RegistryFactory.getRegistry(registryConfig);
        Assert.assertTrue(registry instanceof TestRegistry);
    }
    Assert.assertTrue(RegistryFactory.getRegistries().size() == 4);
    RegistryFactory.destroyAll();
}
Also used : RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) Test(org.junit.Test)

Example 22 with SofaRpcRuntimeException

use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.

the class ReflectUtils method getPropertyGetterMethod.

/**
 * 得到get/is方法
 *
 * @param clazz    类
 * @param property 属性
 * @return Method 方法对象
 */
public static Method getPropertyGetterMethod(Class clazz, String property) {
    String methodName = "get" + property.substring(0, 1).toUpperCase() + property.substring(1);
    Method method;
    try {
        method = clazz.getMethod(methodName);
    } catch (NoSuchMethodException e) {
        try {
            methodName = "is" + property.substring(0, 1).toUpperCase() + property.substring(1);
            method = clazz.getMethod(methodName);
        } catch (NoSuchMethodException e1) {
            throw new SofaRpcRuntimeException("No getter method for " + clazz.getName() + "#" + property, e);
        }
    }
    return method;
}
Also used : SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) Method(java.lang.reflect.Method)

Example 23 with SofaRpcRuntimeException

use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.

the class LocalRegistryTest method setUp.

@BeforeClass
public static void setUp() {
    FileUtils.cleanDirectory(new File(filePath));
    registryConfig = new RegistryConfig().setProtocol("local").setSubscribe(true).setRegister(true);
    // registryConfig.setAddress()
    // .setConnectTimeout(5000)
    // .setHeartbeatPeriod(60000)
    // .setReconnectPeriod(15000)
    // .setBatch(true)
    // .setBatchSize(10);
    registry = (LocalRegistry) RegistryFactory.getRegistry(registryConfig);
    try {
        registry.init();
    } catch (Exception e) {
        Assert.assertTrue(e instanceof SofaRpcRuntimeException);
    }
    registryConfig.setFile(file);
    registry.init();
    registry.start();
}
Also used : RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) File(java.io.File) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) BeforeClass(org.junit.BeforeClass)

Example 24 with SofaRpcRuntimeException

use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.

the class PolarisRegistry method register.

@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) {
        return;
    }
    try {
        List<InstanceRegisterRequest> services = buildPolarisRegister(config);
        if (CommonUtils.isNotEmpty(services)) {
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, config.getInterfaceId()));
            }
            for (InstanceRegisterRequest service : services) {
                registerPolarisService(config, service);
                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB, config.getInterfaceId()));
                }
            }
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, config.getInterfaceId()));
            }
        }
    } catch (SofaRpcRuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REG_PROVIDER, "polarisRegistry", config.buildKey()), e);
    }
    if (EventBus.isEnable(ProviderPubEvent.class)) {
        ProviderPubEvent event = new ProviderPubEvent(config);
        EventBus.post(event);
    }
}
Also used : SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) InstanceRegisterRequest(com.tencent.polaris.api.rpc.InstanceRegisterRequest) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)

Example 25 with SofaRpcRuntimeException

use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.

the class ConsulRegistry method register.

@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        // 只订阅不注册
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) {
        return;
    }
    // 注册服务端节点
    try {
        List<NewService> services = buildNewServices(config);
        if (CommonUtils.isNotEmpty(services)) {
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, config.getInterfaceId()));
            }
            for (NewService service : services) {
                registerConsulService(service);
                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB, config.getInterfaceId()));
                }
            }
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, config.getInterfaceId()));
            }
        }
    } catch (SofaRpcRuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REG_PROVIDER, "consulRegistry", config.buildKey()), e);
    }
    if (EventBus.isEnable(ProviderPubEvent.class)) {
        ProviderPubEvent event = new ProviderPubEvent(config);
        EventBus.post(event);
    }
}
Also used : SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent) NewService(com.ecwid.consul.v1.agent.model.NewService) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)

Aggregations

SofaRpcRuntimeException (com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)64 Method (java.lang.reflect.Method)10 KeeperException (org.apache.zookeeper.KeeperException)7 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)6 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)6 NacosException (com.alibaba.nacos.api.exception.NacosException)5 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)4 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)4 Instance (com.alibaba.nacos.api.naming.pojo.Instance)3 ConsumerSubEvent (com.alipay.sofa.rpc.event.ConsumerSubEvent)3 ProviderPubEvent (com.alipay.sofa.rpc.event.ProviderPubEvent)3 ProviderInfoListener (com.alipay.sofa.rpc.listener.ProviderInfoListener)3 SslContext (io.netty.handler.ssl.SslContext)3 File (java.io.File)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 Test (org.junit.Test)3 EventListener (com.alibaba.nacos.api.naming.listener.EventListener)2 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)2 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)2