Exemple #1
0
		/// 
		public virtual void scanData2Store(ScanStaticModel scanModel)
		{

			// 转换配置文件
			IList<DisconfCenterBaseModel> disconfCenterFiles = getDisconfFiles(scanModel);
			DisconfStoreProcessorFactory.DisconfStoreFileProcessor.transformScanData(disconfCenterFiles);
		}
Exemple #2
0
		public virtual void scanData2Store(ScanStaticModel scanModel)
		{

			// 转换配置项
			IList<DisconfCenterBaseModel> disconfCenterItems = getDisconfItems(scanModel);
			DisconfStoreProcessorFactory.DisconfStoreItemProcessor.transformScanData(disconfCenterItems);

		}
Exemple #3
0
		/// <summary>
		/// 第二次扫描, 获取更新 回调的实例<br/>
		/// <p/>
		/// 分析出更新操作的相关配置文件内容
		/// </summary>
		private static ScanDynamicModel analysis4DisconfUpdate(ScanStaticModel scanModel, Registry registry)
		{

			// 配置项或文件
			IDictionary<DisconfKey, IList<IDisconfUpdate>> inverseMap = new Dictionary<DisconfKey, IList<IDisconfUpdate>>();

			ISet<Type> disconfUpdateServiceSet = scanModel.DisconfUpdateService;
			foreach (Type disconfUpdateServiceClass in disconfUpdateServiceSet)
			{

				// 回调对应的参数
				DisconfUpdateService disconfUpdateService = disconfUpdateServiceClass.getAnnotation(typeof(DisconfUpdateService));

				//
				// 校验是否有继承正确,是否继承IDisconfUpdate
				if (!ScanVerify.hasIDisconfUpdate(disconfUpdateServiceClass))
				{
					continue;
				}

				//
				// 获取回调接口实例
				IDisconfUpdate iDisconfUpdate = getIDisconfUpdateInstance(disconfUpdateServiceClass, registry);
				if (iDisconfUpdate == null)
				{
					continue;
				}

				//
				// 配置项
				processItems(inverseMap, disconfUpdateService, iDisconfUpdate);

				//
				// 配置文件
				processFiles(inverseMap, disconfUpdateService, iDisconfUpdate);

			}

			// set data
			ScanDynamicModel scanDynamicModel = new ScanDynamicModel();
			scanDynamicModel.DisconfUpdateServiceInverseIndexMap = inverseMap;

			//
			// set update pipeline
			//
			if (scanModel.getiDisconfUpdatePipeline() != null)
			{
				IDisconfUpdatePipeline iDisconfUpdatePipeline = getIDisconfUpdatePipelineInstance(scanModel.getiDisconfUpdatePipeline(), registry);
				if (iDisconfUpdatePipeline != null)
				{
					scanDynamicModel.DisconfUpdatePipeline = iDisconfUpdatePipeline;
				}
			}

			return scanDynamicModel;
		}
Exemple #4
0
		/// <summary>
		/// 扫描更新回调函数
		/// </summary>
		public static void scanUpdateCallbacks(ScanStaticModel scanModel, Registry registry)
		{

			// 扫描出来
			ScanDynamicModel scanDynamicModel = analysis4DisconfUpdate(scanModel, registry);

			// 写到仓库中
			transformUpdateService(scanDynamicModel.DisconfUpdateServiceInverseIndexMap);
			transformPipelineService(scanDynamicModel.DisconfUpdatePipeline);
		}
Exemple #5
0
		/// <summary>
		/// 转换配置项
		/// </summary>
		private static IList<DisconfCenterBaseModel> getDisconfItems(ScanStaticModel scanModel)
		{

			IList<DisconfCenterBaseModel> disconfCenterItems = new List<DisconfCenterBaseModel>();

			ISet<Method> methods = scanModel.DisconfItemMethodSet;
			foreach (Method method in methods)
			{

				DisconfCenterItem disconfCenterItem = transformScanItem(method);

				if (disconfCenterItem != null)
				{
					disconfCenterItems.Add(disconfCenterItem);
				}
			}

			return disconfCenterItems;
		}
Exemple #6
0
		/// <summary>
		/// 扫描并存储(静态)
		/// </summary>
		/// <exception cref="Exception"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void firstScan(java.util.List<String> packageNameList) throws Exception
		public virtual void firstScan(IList<string> packageNameList)
		{

			LOGGER.debug("start to scan package: " + packageNameList.ToString());

			// 获取扫描对象并分析整合
			scanModel = scanStaticStrategy.scan(packageNameList);

			// 增加非注解的配置
			scanModel.JustHostFiles = DisconfCenterHostFilesStore.Instance.JustHostFiles;

			// 放进仓库
			foreach (StaticScannerMgr scannerMgr in staticScannerMgrList)
			{

				// 扫描进入仓库
				scannerMgr.scanData2Store(scanModel);

				// 忽略哪些KEY
				scannerMgr.exclude(DisClientConfig.Instance.IgnoreDisconfKeySet);
			}
		}
Exemple #7
0
		/// <summary>
		/// 获取配置文件数据
		/// </summary>
		private static IList<DisconfCenterBaseModel> getDisconfFiles(ScanStaticModel scanModel)
		{

			IList<DisconfCenterBaseModel> disconfCenterFiles = new List<DisconfCenterBaseModel>();

			ISet<Type> classSet = scanModel.DisconfFileClassSet;
			foreach (Type disconfFile in classSet)
			{

				ISet<Method> methods = scanModel.DisconfFileItemMap[disconfFile];
				if (methods == null)
				{
					continue;
				}

				DisconfCenterFile disconfCenterFile = transformScanFile(disconfFile, methods);

				disconfCenterFiles.Add(disconfCenterFile);
			}

			return disconfCenterFiles;
		}
Exemple #8
0
		/// <summary>
		/// 分析出一些关系 出来
		/// </summary>
		private void analysis(ScanStaticModel scanModel)
		{

			// 分析出配置文件MAP
			analysis4DisconfFile(scanModel);
		}
Exemple #9
0
		/// <summary>
		/// 扫描基本信息
		/// </summary>
		private ScanStaticModel scanBasicInfo(IList<string> packNameList)
		{

			ScanStaticModel scanModel = new ScanStaticModel();

			//
			// 扫描对象
			//
			Reflections reflections = getReflection(packNameList);
			scanModel.Reflections = reflections;

			//
			// 获取DisconfFile class
			//
			ISet<Type> classdata = reflections.getTypesAnnotatedWith(typeof(DisconfFile));
			scanModel.DisconfFileClassSet = classdata;

			//
			// 获取DisconfFileItem method
			//
			ISet<Method> af1 = reflections.getMethodsAnnotatedWith(typeof(DisconfFileItem));
			scanModel.DisconfFileItemMethodSet = af1;

			//
			// 获取DisconfItem method
			//
			af1 = reflections.getMethodsAnnotatedWith(typeof(DisconfItem));
			scanModel.DisconfItemMethodSet = af1;

			//
			// 获取DisconfActiveBackupService
			//
			classdata = reflections.getTypesAnnotatedWith(typeof(DisconfActiveBackupService));
			scanModel.DisconfActiveBackupServiceClassSet = classdata;

			//
			// 获取DisconfUpdateService
			//
			classdata = reflections.getTypesAnnotatedWith(typeof(DisconfUpdateService));
			scanModel.DisconfUpdateService = classdata;

			// update pipeline
			ISet<Type> iDisconfUpdatePipeline = reflections.getSubTypesOf(typeof(IDisconfUpdatePipeline));
			if (iDisconfUpdatePipeline != null && iDisconfUpdatePipeline.Count != 0)
			{
				scanModel.setiDisconfUpdatePipeline((Type<IDisconfUpdatePipeline>) iDisconfUpdatePipeline.ToArray()[0]);
			}

			return scanModel;
		}
Exemple #10
0
		/// <summary>
		/// 分析出配置文件与配置文件中的Field的Method的MAP
		/// </summary>
		private void analysis4DisconfFile(ScanStaticModel scanModel)
		{

			IDictionary<Type, ISet<Method>> disconfFileItemMap = new Dictionary<Type, ISet<Method>>();

			//
			// 配置文件MAP
			//
			ISet<Type> classdata = scanModel.DisconfFileClassSet;
			foreach (Type classFile in classdata)
			{
				disconfFileItemMap[classFile] = new HashSet<Method>();
			}

			//
			// 将配置文件与配置文件中的配置项进行关联
			//
			ISet<Method> af1 = scanModel.DisconfFileItemMethodSet;
			foreach (Method method in af1)
			{

				Type thisClass = method.DeclaringClass;

				if (disconfFileItemMap.ContainsKey(thisClass))
				{
					ISet<Method> fieldSet = disconfFileItemMap[thisClass];
					fieldSet.Add(method);
					disconfFileItemMap[thisClass] = fieldSet;

				}
				else
				{

//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
					LOGGER.error("cannot find CLASS ANNOTATION " + typeof(DisconfFile).FullName + " for disconf file item: " + method.ToString());
				}
			}

			//
			// 最后的校验
			//
			IEnumerator<Type> iterator = disconfFileItemMap.Keys.GetEnumerator();
			while (iterator.MoveNext())
			{

				Type classFile = iterator.Current;

				// 校验是否所有配置文件都含有配置
				if (disconfFileItemMap[classFile].Count == 0)
				{
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
					LOGGER.info("disconf file hasn't any items: " + classFile.FullName);
					continue;
				}

				// 校验配置文件类型是否合适(目前只支持.properties类型)
				DisconfFile disconfFile = classFile.getAnnotation(typeof(DisconfFile));
				bool fileTypeRight = ScanVerify.isDisconfFileTypeRight(disconfFile);
				if (!fileTypeRight)
				{
					LOGGER.warn("now do not support this file type" + disconfFile.ToString());
					continue;
				}
			}

			// 设置
			scanModel.DisconfFileItemMap = disconfFileItemMap;
		}