public void init() { registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true)); registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true)); registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true)); registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true)); registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true)); registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true)); registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true)); registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true)); registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false)); registerBeanDefinitionParser("annotation", new DubboBeanDefinitionParser(AnnotationBean.class, true)); }
functionform2Json(params){ var selector=params.form; var values= $(selector).serializeArray(); var obj={}; for (var index = 0; index < values.length; ++index) { var temp=obj; //上一级 var n=values[index].name; if(n.indexOf(".")>-1){ var arr=n.split("."); for(var i=0;i<arr.length-1;i++){ if(arr[i].indexOf("[")>-1){ var a=arr[i].substring(0,arr[i].indexOf("[")); temp[a]=temp[a]||[]; var y=arr[i].substring(arr[i].indexOf("[")+1,arr[i].indexOf("]")); temp[a][y]=temp[a][y]||{}; temp=temp[a][y]; }else{ temp[arr[i]]=temp[arr[i]] || {}; temp=temp[arr[i]]; } } temp[arr[arr.length-1]]=values[index].value; }else{ if(obj[n] !==undefined && obj[n]!=null){ if( !$.isArray(obj[n])){ var v=obj[n]; obj[n]=[]; obj[n].push(v); }
publicvoiddoSaveProperties(long version) { if(version < lastCacheChanged.get()){ return; } if (file == null) { return; } PropertiesnewProperties=newProperties(); // 保存之前先读取一遍,防止多个注册中心之间冲突 InputStreamin=null; try { if (file.exists()) { in = newFileInputStream(file); newProperties.load(in); } } catch (Throwable e) { logger.warn("Failed to load registry store file, cause: " + e.getMessage(), e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } // 保存 try { newProperties.putAll(properties); Filelockfile=newFile(file.getAbsolutePath() + ".lock"); if (!lockfile.exists()) { lockfile.createNewFile(); } RandomAccessFileraf=newRandomAccessFile(lockfile, "rw"); try { FileChannelchannel= raf.getChannel(); try { FileLocklock= channel.tryLock(); if (lock == null) { thrownewIOException("Can not lock the registry cache file " + file.getAbsolutePath() + ", ignore and retry later, maybe multi java process use the file, please config: dubbo.registry.file=xxx.properties"); } // 保存 try { if (! file.exists()) { file.createNewFile(); } FileOutputStreamoutputFile=newFileOutputStream(file); try { newProperties.store(outputFile, "Dubbo Registry Cache"); } finally { outputFile.close(); } } finally { lock.release(); } } finally { channel.close(); } } finally { raf.close(); } } catch (Throwable e) { if (version < lastCacheChanged.get()) { return; } else { registryCacheExecutor.execute(newSaveProperties(lastCacheChanged.incrementAndGet())); } logger.warn("Failed to save registry store file, cause: " + e.getMessage(), e); } }
如果是两个不同的注册中心,不能使用一个缓存文件。 值得注意一点的是,多个dubbo服务公用一个cache文件的时候,如果一起启动,可能会出现Failed to load registry store File 这类异常信息, 这是因为当时该文件其他服务占用了。这种情况开发环境比较多,可以无视掉。因为会重复去注册的,下面会说明, 但是尽量还是手动指定注册缓存文件比较好。尽量不使用同一个缓存文件。
@SuppressWarnings("unchecked") publicstatic <T> ExtensionLoader<T> getExtensionLoader(Class<T> type) { if (type == null) thrownewIllegalArgumentException("Extension type == null"); if(!type.isInterface()) { thrownewIllegalArgumentException("Extension type(" + type + ") is not interface!"); } if(!withExtensionAnnotation(type)) { thrownewIllegalArgumentException("Extension type(" + type + ") is not extension, because WITHOUT @" + SPI.class.getSimpleName() + " Annotation!"); }