use of rpc.turbo.annotation.TurboService in project turbo-rpc by hank-whu.
the class TurboClientStarter method extractTurboServiceClassList.
private Collection<Class<?>> extractTurboServiceClassList(ConfigurableListableBeanFactory beanFactory) {
LocalDateTime startTime = LocalDateTime.now();
Set<Class<?>> turboServiceSet = new HashSet<>();
String[] beanNames = beanFactory.getBeanDefinitionNames();
for (int i = 0; i < beanNames.length; i++) {
String beanName = beanNames[i];
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
String beanClassName = beanDefinition.getBeanClassName();
extractTurboServiceClass(turboServiceSet, beanClassName);
}
if (logger.isInfoEnabled()) {
LocalDateTime finishTime = LocalDateTime.now();
Duration duration = Duration.between(startTime, finishTime);
String turboServiceString = //
turboServiceSet.stream().map(//
clazz -> clazz.getName()).collect(Collectors.joining(",", "[", "]"));
logger.info("扫描到TurboService: " + turboServiceString);
logger.info("扫描TurboService耗时: " + duration);
}
return turboServiceSet;
}
use of rpc.turbo.annotation.TurboService in project turbo-rpc by hank-whu.
the class TurboClientStarter method extractTurboServiceClass.
private void extractTurboServiceClass(Set<Class<?>> turboServiceSet, String beanClassName) {
if (beanClassName == null || beanClassName.startsWith("org.springframework.")) {
return;
}
Class<?> beanClass;
try {
beanClass = Class.forName(beanClassName, false, beanFactory.getBeanClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
Collection<Class<?>> allDependClass = ReflectUtils.getAllDependClass(beanClass, clazz -> {
if (!clazz.isInterface()) {
// 只支持接口
return false;
}
TurboService turboService = clazz.getAnnotation(TurboService.class);
if (turboService == null) {
return false;
}
return true;
});
turboServiceSet.addAll(allDependClass);
}
use of rpc.turbo.annotation.TurboService in project turbo-rpc by hank-whu.
the class TurboServerStarter method getTurboService.
@SuppressWarnings("rawtypes")
private Tuple2<TurboService, Class> getTurboService(Object bean) {
if (bean == null) {
return null;
}
Class<?> beanClass = bean.getClass();
if (beanClass.getAnnotation(TurboFailover.class) != null) {
return null;
}
Class<?>[] interfaces = beanClass.getInterfaces();
if (interfaces == null || interfaces.length == 0) {
return null;
}
for (int i = 0; i < interfaces.length; i++) {
Class<?> interfaceClass = interfaces[i];
TurboService turboService = interfaceClass.getAnnotation(TurboService.class);
if (turboService != null) {
return tuple(turboService, interfaceClass);
}
}
return null;
}
use of rpc.turbo.annotation.TurboService in project turbo-rpc by hank-whu.
the class RemoteServiceFactory method register.
/**
* 注册一个远程代理
*
* @param app
* 连接组
*
* @param clazz
* 服务接口
*
* @param configs
* 远程方法配置
*
* @throws Exception
*/
public synchronized void register(App app, Class<?> clazz, Collection<MethodConfig> configs) throws Exception {
if (app == null) {
throw new RuntimeException("app must not be null");
}
if (clazz == null) {
throw new RuntimeException("clazz must not be null");
}
if (!app.isSupport(clazz)) {
throw new RuntimeException("the remote service not support the service " + clazz.getName());
}
if (configs == null || configs.isEmpty()) {
throw new RuntimeException("configs must not be empty");
}
if (getService(clazz) != null) {
return;
}
TurboService classConfig = clazz.getAnnotation(TurboService.class);
if (classConfig != null && classConfig.ignore()) {
if (logger.isInfoEnabled()) {
logger.info(clazz + " service ignore");
}
return;
}
if (logger.isInfoEnabled()) {
logger.info("service " + clazz.getName() + " register");
}
Object service = generateRemoteObject(app, clazz, configs);
remoteServiceMap.put(clazz, service);
if (failoverInvokerFactory == null) {
return;
}
}
Aggregations