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();
}
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;
}
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();
}
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);
}
}
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);
}
}
Aggregations