@Override public void registerAllServices() { Set<ProcessorKey> keys = ProcessorCache.getProcessorMap().keySet(); for (ProcessorKey key : keys) { TProcessor<?> processor = ProcessorCache.getProcessorMap().get(key); if (null != processor.getInterfaceClass().getClass()) { Service service = processor.getInterfaceClass().getAnnotation(Service.class); this.registerService(service.name(), service.version()); } } }
TProcessor<?> processor = processorMap.get(key); long count = new ArrayList<>(Arrays.asList(processor.getIface().getClass().getInterfaces())) .stream() .filter(m -> m.getName().equals("org.springframework.aop.framework.Advised")) .count(); Class<?> ifaceClass = (Class) (count > 0 ? processor.getIface().getClass().getMethod("getTargetClass").invoke(processor.getIface()) : processor.getIface().getClass()); SoaProcessFunction<Object, Object, Object, ? extends TCommonBeanSerializer<Object>, ? extends TCommonBeanSerializer<Object>> soaProcessFunction = (SoaProcessFunction<Object, Object, Object, ? extends TCommonBeanSerializer<Object>, ? extends TCommonBeanSerializer<Object>>) processor.getProcessMapView().get(methodName); Service service = processor.getInterfaceClass().getAnnotation(Service.class); String serviceName = service.name(); String versionName = service.version(); jobDataMap.put("iface", processor.getIface()); jobDataMap.put("serviceName", serviceName); jobDataMap.put("versionName", versionName);
@Override @SuppressWarnings("unchecked") public TProcessor<?> getObject() throws Exception { final Class<?> aClass = serviceRef.getClass(); final List<Class<?>> interfaces = Arrays.asList(aClass.getInterfaces()); List<Class<?>> filterInterfaces = interfaces.stream() .filter(anInterface -> anInterface.isAnnotationPresent(Service.class) && anInterface.isAnnotationPresent(Processor.class)) .map(anInterface -> anInterface) .collect(toList()); if (filterInterfaces.isEmpty()) throw new RuntimeException("not config @Service & @Processor in " + refId); Class<?> interfaceClass = filterInterfaces.get(filterInterfaces.size() - 1); Processor processor = interfaceClass.getAnnotation(Processor.class); Class<?> processorClass = Class.forName(processor.className(), true, interfaceClass.getClassLoader()); Constructor<?> constructor = processorClass.getConstructor(interfaceClass); TProcessor tProcessor = (TProcessor) constructor.newInstance(serviceRef); tProcessor.setInterfaceClass(interfaceClass); return tProcessor; }
soaProcessor.process(inputProtocol, outputProtocol);
throw new SoaException(SoaBaseCode.NotFoundServer); CompletableFuture<Context> future = soaProcessor.processAsync(inputProtocol, outputProtocol); future.whenComplete((resultContext, ex) -> {
soaProcessor.process(protocol, protocol);
@Override public void registerAllServices() { if (processorMap == null) return; Set<ProcessorKey> keys = processorMap.keySet(); for (ProcessorKey key : keys) { TProcessor<?> processor = processorMap.get(key); if (processor.getInterfaceClass().getClass() != null) { Service service = processor.getInterfaceClass().getAnnotation(Service.class); this.registerService(service.name(), service.version()); } } //如果开启了全局事务,将事务服务也注册到zookeeper,为了主从竞选,只有主全局事务管理器会执行 if (SoaSystemEnvProperties.SOA_TRANSACTIONAL_ENABLE) { this.registerService("com.isuwang.dapeng.transaction.api.service.GlobalTransactionService", "1.0.0"); } }
@Override public void start() { Map<Object, Class<?>> contexts = SpringContainer.getContexts(); Set<Object> ctxs = contexts.keySet(); for (Object ctx : ctxs) { Class<?> contextClass = contexts.get(ctx); try { Method method = contextClass.getMethod("getBeansOfType", Class.class); @SuppressWarnings("unchecked") Map<String, TProcessor<?>> processorMap = (Map<String, TProcessor<?>>) method.invoke(ctx, contextClass.getClassLoader().loadClass(TProcessor.class.getName())); Set<String> keys = processorMap.keySet(); for (String key : keys) { TProcessor<?> processor = processorMap.get(key); if (processor.getInterfaceClass().getClass() != null) { Service service = processor.getInterfaceClass().getAnnotation(Service.class); ProcessorKey processorKey = new ProcessorKey(service.name(), service.version()); getProcessorMap().put(processorKey, processor); this.registerService(service.name(), service.version()); } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } RegistryAgentProxy.setCurrentInstance(RegistryAgentProxy.Type.Server, this); }
public void reloadServices() { final Map<String, com.isuwang.dapeng.core.metadata.Service> services = new TreeMap<>(); urlMappings.clear(); Map<ProcessorKey, TProcessor<?>> processorMap = RegistryAgentProxy.getCurrentInstance(RegistryAgentProxy.Type.Server).getProcessorMap(); Set<ProcessorKey> keys = processorMap.keySet(); for (ProcessorKey key : keys) { TProcessor<?> processor = processorMap.get(key); if (processor.getInterfaceClass().getClass() != null) { Service service = processor.getInterfaceClass().getAnnotation(Service.class); String serviceName = service.name(); String version = service.version(); String metadata = ""; try { metadata = new MetadataClient(serviceName, version).getServiceMetadata(); } catch (TException e) { LOGGER.error(e.getMessage(), e); } if (metadata != null) { try (StringReader reader = new StringReader(metadata)) { com.isuwang.dapeng.core.metadata.Service serviceData = JAXB.unmarshal(reader, com.isuwang.dapeng.core.metadata.Service.class); loadResource(serviceData, services); } catch (Exception e) { LOGGER.error("生成SERVICE出错", e); } } } } this.services = services; LOGGER.info("size of urlMapping: " + urlMappings.size()); }
@Override @SuppressWarnings("unchecked") public void start() { RegistryAgentProxy.setCurrentInstance(RegistryAgentProxy.Type.Server, registryAgent); registryAgent.setProcessorMap(ProcessorCache.getProcessorMap()); registryAgent.start(); Map<Object, Class<?>> contexts = SpringContainer.getContexts(); Map<Object,ClassLoader>appClassLoaderMap = SpringContainer.getClassLoaderMap(); Set<Object> ctxs = contexts.keySet(); for (Object ctx : ctxs) { Class<?> contextClass = contexts.get(ctx); try { Method method = contextClass.getMethod("getBeansOfType", Class.class); Map<String, TProcessor<?>> processorMap = (Map<String, TProcessor<?>>) method.invoke(ctx, contextClass.getClassLoader().loadClass(TProcessor.class.getName())); Set<String> keys = processorMap.keySet(); for (String key : keys) { TProcessor<?> processor = processorMap.get(key); if (processor.getInterfaceClass().getClass() != null) { Service service = processor.getInterfaceClass().getAnnotation(Service.class); ProcessorKey processorKey = new ProcessorKey(service.name(), service.version()); ProcessorCache.getProcessorMap().put(processorKey, processor); registryAgent.registerService(service.name(), service.version()); SoaAppClassLoaderCache.getAppClassLoaderMap().put(processorKey,appClassLoaderMap.get(ctx)); } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } }