- 浏览: 231370 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (101)
- Practice (17)
- Model (15)
- Prototype (2)
- Integration (6)
- GWT (3)
- Android (16)
- Lab (6)
- Ubuntu (4)
- Data Structure(D,S) (1)
- 社会观察员 (1)
- python (14)
- redis (0)
- mysql (9)
- php (0)
- Data Structure(D (1)
- haproxy (2)
- Shell (5)
- Zabbix (1)
- CentOS (1)
- sqlplus (1)
- rlwrap (1)
- Oracle (2)
- schema (2)
- user (1)
- accredit (1)
- Delphi (2)
- nagios (1)
- nginx (0)
最新评论
-
白云飞:
兄弟能不能发一份完整的源码到我邮箱?luochengwei20 ...
【Python真的很强大】程序Log实时监控 -
myreligion:
nice job!
解决一个棘手的bug: java.lang.NoClassDefFoundError: android.os.AsyncTask -
yw9002:
你这个貌似提交的时候整个页面都会刷新。
AjaxAnyWhere+Struts的一个应用(demo/feature crew) -
fkpwolf:
这总结偏向于细节了,流水账
Android app项目和开发总结 -
crazybull:
期待详细总结~~~
Android app项目和开发总结
开发到了一定时间,就会有很多的定式思维阻碍我们。 比如问到XML配置和Properties配置有什么区别,往往想都不想就回答: 更改Properties需要重新启动Server,而更改XML Schema则不需要重新启动Server就会生效。
虽然上面的说法是错误的 ,但是还是值得我们去思考为什么。
另一方面,我们要构建7*24小时运转的System,不能随意关闭 /启动 APP Server. 但是又要保证让我们更改系统配置,我们的Application又能立即感知。基于这方面的需求。 我们做了PropertyFileCache。 基本原理是模仿Properties,每次访问getProperty时,去检查文件修改的时间戳。如果时间为后来的,则代表文件已经修改,则需要作类似 Properties.load()的动作.
然后重新取得新的修改后的值。否则,采用Cache中的值。
下面是直接的代码.
使用的例子:
需要注意的是,它并不能取代java.util.Propertieshttp://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/java/util/Properties.html,很多的特殊字符转义暂时还没有考虑。
虽然上面的说法是错误的 ,但是还是值得我们去思考为什么。
另一方面,我们要构建7*24小时运转的System,不能随意关闭 /启动 APP Server. 但是又要保证让我们更改系统配置,我们的Application又能立即感知。基于这方面的需求。 我们做了PropertyFileCache。 基本原理是模仿Properties,每次访问getProperty时,去检查文件修改的时间戳。如果时间为后来的,则代表文件已经修改,则需要作类似 Properties.load()的动作.
然后重新取得新的修改后的值。否则,采用Cache中的值。
下面是直接的代码.
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.Enumeration; import java.util.HashSet; import java.util.Hashtable; import java.util.Set; //import org.apache.log4j.Logger; // // PropertyFileCache() : // This class reads a property file [full file name specified], then, put each line // with a key and value property to check. For example, if the file contains IP address... // // 127.0.0.1=ok // 202.3.8.4=blah // // The above example will put the above IP addresses as key, and "ok" and "blah" as its // associated values in a cached array. If the property file has changed, it will read it again. // If the property file has not changed, then, upon a request, it will simply // pull elements from cache/memory to check. // // This class also allows multiple instance of file to be cached. // public class PropertyFileCache { private static final String ENCODING = "UTF-8"; // encoding type... private static final String PARAMETER_DELIMITER = "="; // equate character for key and value private static final String COMMENT_DELIMITER = "#"; //comment delimiter inside the property file private static final int PRINT_ELEMENT_LIMIT = 50; // if more than X, do not print all read elements... // private static Logger sysLog = Logger.getLogger(PropertyFileCache.class); protected static PropertyFileCache instance; // singelton instance protected Hashtable<String, FileInfo> spfCache; // this stores different property file... protected PropertyFileCache() { spfCache = new Hashtable<String, FileInfo>(); } // // getInstance(): get this instance - a singleton // public static PropertyFileCache getInstance() { if ( instance == null ) { instance = new PropertyFileCache(); } return instance; } // // getAllKeys() : return an enumeration of all keys // public Enumeration <String> getAllKeys(String filename) { Enumeration<String> allkeys = null; FileInfo curFileInfo = getFileInfo(filename); if ( curFileInfo != null ) { checkConf(curFileInfo); allkeys = curFileInfo.cachedTokens.keys(); } return allkeys; } // // keySet() : return a set for all keys available // public Set<String> keySet(String filename) { Set<String> keyset = new HashSet<String>(); // JP, Aug 16, 2006, initialize it to an empty Set FileInfo curFileInfo = getFileInfo(filename); if ( curFileInfo != null ) { checkConf(curFileInfo); keyset = curFileInfo.cachedTokens.keySet(); } return keyset; } // // getProperty(): get the who hash table for internal processing // private Hashtable<String,String> getProperty(String filename) { Hashtable<String, String> retTable = null; FileInfo curFileInfo = getFileInfo(filename); if ( curFileInfo != null ) { checkConf(curFileInfo); retTable = curFileInfo.cachedTokens; } else { retTable = new Hashtable<String, String>(); // return empty vector } return retTable; } // // get(): get the value based on the key and filename // public String get(String filename, String key) { String retStr = null; FileInfo curFileInfo = getFileInfo(filename); if ( curFileInfo != null ) { checkConf(curFileInfo); retStr = curFileInfo.cachedTokens.get(key); } return retStr; } // // getTimestamp() : return the timestamp of this file. this is used by external routine to explicit triggers a re-read // public long getTimestamp(String filename) { long ts = 0; FileInfo curFileInfo = getFileInfo(filename); if ( curFileInfo != null) { checkConf(curFileInfo); ts = curFileInfo.timestamp; } return ts; } // // contains() : check if the item contains the token // public boolean contains(String filename, String token) { boolean status = false; FileInfo curFileInfo = getFileInfo(filename); if ( curFileInfo != null ) { checkConf(curFileInfo); status = contains(curFileInfo.cachedTokens, token); } return status; } // // containsKey() : check if key is there! // public boolean containsKey(String filename, String token) { boolean status = false; FileInfo curFileInfo = getFileInfo(filename); if ( curFileInfo != null ) { checkConf(curFileInfo); status = containsKey(curFileInfo.cachedTokens, token); } return status; } // // getSize() : return the number of items in the file // public int getSize(String filename) { int size = 0; FileInfo curFileInfo = getFileInfo(filename); if ( curFileInfo != null ) { checkConf(curFileInfo); size = curFileInfo.cachedTokens.size(); } return size; } // // isUpdated() : check to see if time stamp has been updated. This check DOES NOT trigger a re-read! // public boolean isUpdated(String filename) { boolean status = false; if ( filename != null && filename.length() > 0 ) { FileInfo curFileInfo = getFileInfo(filename); if ( curFileInfo != null ) { long newTimestamp = (new File(curFileInfo.filename)).lastModified(); // NOTE: if file does not exist, lastModified() will return '0', let // it proceed to create a zero element HashTable if ( newTimestamp > curFileInfo.timestamp || newTimestamp == 0) { status = true; // file has been updated! } // else - no need to do anything! } else { status = true; // signal update is required because file has not been read before! } } // else - if file name is invalid, there is nothing to be 'updated', return false... return status; } private FileInfo getFileInfo(String filename) { FileInfo curFileInfo = null; if ( filename != null && filename.length() > 0 ) { try { if ( spfCache.containsKey(filename)) { curFileInfo = spfCache.get(filename); } else { curFileInfo = new FileInfo(filename); spfCache.put(filename, curFileInfo); } curFileInfo = spfCache.get(filename); } catch (Exception e) { // sysLog.error("Cannot read simple property file [" + filename + "]"); } } return curFileInfo; } private String get(Hashtable<String, String> vs, String key) { return vs.get(key); } private boolean contains(Hashtable<String,String> vs, String token) { return vs.contains(token); } private boolean containsKey(Hashtable<String, String> vs, String key) { return vs.containsKey(key); } private void checkConf(FileInfo fi) { String curDir = null; try { curDir = (new File(".")).getAbsolutePath(); // if 'fp' is null, meaning cannot read a file, will throw exception long newTimestamp = (new File(fi.filename)).lastModified(); // NOTE: if file does not exist, lastModified() will return '0', let // it proceed to create a zero element HashTable if ( newTimestamp > fi.timestamp || newTimestamp == 0) { parseProperties(fi); // similar to Properties.load(), but have to deal with UTF-8! fi.timestamp = newTimestamp; // sysLog.info("Parsed from DIR[" + curDir + "] + FILE["+ fi.filename + "] with timestamp =[" + fi.timestamp +"]"); } } catch (Exception e) { // sysLog.fatal("Cannot read file [" + fi.filename + "] from directory [" + curDir + "]..." + e.getMessage()); } } private void parseProperties(FileInfo fi) { if (fi.filename != null && fi.filename.length() > 0 ) { Hashtable <String, String> tokensFromFile = new Hashtable<String, String>(); try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fi.filename), ENCODING)); String tmpValue; // extracted value String tmpKey; // extracted key String tmpLine; // the line while ( (tmpLine = br.readLine()) != null ) { // // strip off any comment and trim it down // tmpLine = tmpLine.replaceAll(COMMENT_DELIMITER + ".*$", "").trim(); int sindex = tmpLine.indexOf(PARAMETER_DELIMITER); if ( sindex != -1 ) { tmpKey = tmpLine.substring(0, sindex).trim(); tmpValue = tmpLine.substring(sindex + 1).trim(); if ( /* tmpValue.length() > 0 && */ tmpKey.length() > 0 ) { // allow empty string to be a variable... tokensFromFile.put(tmpKey, tmpValue); } // else ignore the parameters } // else ignore the parameters } br.close(); // sysLog.info("Property file [" + fi.filename + "] loaded with " + tokensFromFile.size() + " element(s)."); } catch (Exception e) { // sysLog.error("Property file [" + fi.filename + "] cannot be loaded " + e.getMessage()); } finally { if (tokensFromFile != null ) { if ( fi.cachedTokens != null ) { fi.cachedTokens.clear(); // remove old Vector } fi.cachedTokens = tokensFromFile; // use new table if ( fi.cachedTokens.size() < PRINT_ELEMENT_LIMIT ) { // if there are too many, do not print... // sysLog.debug("Property file containing elements...\n" + fi.cachedTokens.toString()); } // else - don't bother printing... } } } else { // sysLog.error("Property file [" + fi.filename + "] is not defined"); } } // // CAUTION: Do not try to combine this with SimplePropertyFileCache.java. THEY ARE DIFFERENT!!! // final class FileInfo { private FileInfo(String fn) { filename = fn; // no need to initialize timestamp and cachedTokens, it will be determined later } private String filename; private long timestamp; private Hashtable<String, String> cachedTokens; } }
使用的例子:
String value = PropertyFileCache.getInstance().get("./bin/servletmap/instr2url.properties", "key");
需要注意的是,它并不能取代java.util.Propertieshttp://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/java/util/Properties.html,很多的特殊字符转义暂时还没有考虑。
发表评论
-
MySQL的XML接口-数据解析
2016-01-21 21:46 1094MySQL从5.1.5开 ... -
xml + xslt => html => pdf
2014-03-05 18:02 1767继上一篇:使用java将xml格式化,本blog主 ... -
【Python真的很强大】md5sum in Python
2014-01-17 13:17 2261''' md5sum in Python ... -
使用java将xml格式化
2013-12-25 18:04 2079将生成的xml用ie浏览器打开,就可以见到漂亮的缩进的xm ... -
【Python真的很强大】程序Log实时监控
2013-12-10 16:45 7321需求构思: 在linux下常常需要查看程序的实时输出,我 ... -
【Python真的很强大】开发简易在线搜索
2013-11-25 23:54 1764需求如下:开发一个简易的搜索引擎(即提供查询关键字的服 ... -
haproxy使用总结
2012-10-17 17:19 1273DESCRIPTION HAProxy i ... -
集合数据比较
2012-07-31 12:17 1099数据比较的原型模型是两集合的操作(求交集,并集,补集),如下 ... -
利用事件冒泡(Event Bubbling )获取鼠标下的元素属性
2010-03-17 16:21 2028<html> <head> ... -
Generic Classes & Reflect
2010-02-26 10:05 1098abstract class TestGeneric1 < ... -
在数据库中用正则表达式查询数据
2009-12-30 21:20 1855Mysql5.0及以后直接支持. select * fro ... -
AjaxAnyWhere+Struts的一个应用(demo/feature crew)
2009-12-28 21:05 2773AjaxAnywhere介绍: Aja ... -
call webservice
2009-12-26 14:13 1488web services是用delphi写的,接口如下: i ... -
gwt Client-Server 交互原形模型
2007-10-16 13:17 2432gwt Client-Server 交互原形模型 ...
相关推荐
解决android studio构建太慢的问题,详细教程:https://blog.csdn.net/yang5726685/article/details/80786022
含NBOHC-E’缺陷的熔石英稳定结构和光学特性,杨阳,芦鹏飞,本文应用第一性原理方法模拟96原子的熔石英缺陷模型的稳定结构和光学特性。非桥氧缺陷的稳定结构位于硅氧键长2.4 Å处。应用准粒子G
在使用到redis连接池时,需要进行一些redis相关配置,redis.properties文件是由编程者自己在项目classpath路径(如eclipse的src)下建立的,并非从redis安装包中获取的。 1.redis.properties文件的建立 在eclipse中...
如果检查失败,则构建过程失败。 示例:在属性 vaule 末尾有一个空格并且 java 代码不修剪会发生什么? 特征: 检查属性值中的空格检查空值根据用户定义的正则表达式应用自定义检查有关此插件的更多信息和用法,请...
gradle-构建及配置 //gradle.properties 文件作为全局设置 GRADLE_HOME_USER/.gradle/目录下 //init.gradle gradle仓库全局设置 GRADLE_HOME_USER/.gradle/目录下
根项目目录中的gradle.yml文件(如果该项目是多项目构建的模块)。 Gradle用户主目录(通常为~/.gradle )中的${gradle.rootProject.name}.yml文件。 Gradle用户主目录中的gradle.yml文件。 最后但并非最不重要...
用于创建完整的注册页面链接数据库,前段以及JDBC三个阶段结合构建完整注册系统提供使用,其他用途仅作参考使用
自定义属性 自定义属性插件获取不同的信息并... hostInfo :它获取正在完成构建的主机名和 IP 用法 < groupId>com.github.Janendra</ groupId> < artifactId>custom-properties < version>1.0 < phase
属性-Maven-扩展 一个Maven扩展,用于在构建开始之前引入属性。 这允许使用动态项目版本,例如1.2.3.${sha1} 。例对于一个简单的示例,请考虑以下POM文件: <? xml version = " 1.0 " encoding = " UTF-8 " ?>...
idea数据库快速构建对象模版
根据文件输入为您的Optifine CIT创建.properties文件,以使纹理包更易于制作。 该脚本基于Python 3.8.2构建,并且使用的GUI模块为tkinter (通常安装在python中)。 2021年2月5日开始 如何使用? 选择您要制作的...
二甲醚的热物性和湍流燃烧模型的研究,周龙保,,在二甲醚发动机试验研究的基础上,建立了二甲醚湍流燃烧模型。包括两个部分:首先根据分子理论和对比态理论求得二甲醚的汽化潜热
gradle-build-properties-plugin:保守秘密。 对Gradle脚本的外部构建属性支持
Project Variables能在一个project下各个2D、3D、RMxprt下用,设置在Design Properties下建立; local Variables则只能在一个project下的某一个模型下用。设置在design properties下建立;在建参数变量时有两种变量...
SerenityOS 支持的 CSS 属性 这是一个简单的网页(在托管),显示最常用的 CSS 属性以及的...构建说明 它是纯 HTML、SCSS 和 JavaScript。 要从 SCSS 创建 CSS,请使用您最喜欢的转换器,例如 VS Code 扩展。 贡献者
运行composer install运行npm install运行npm run dev来构建资产。 转到“ ” 这会将属性数据导入数据库。 路线: / admin / properties / admin / properties / create / admin / properties / {id} / edit ...
answer-ontology-construction 是 Answer 系统中的本体半自动构建模块 从百度百科中爬取数据建立本体知识库,构建包括拟人(真实人物、虚拟人物、动物等)、电影、音乐、动画、漫画、地区、院校、公司 八大一级类,...
VUE项目构建打包生成Git信息(VERSION和COMMITHASH文件) Git版本Webpack插件(git-revision-webpack-plugin) 可在构建过程中生成VERSION和COMMITHASH文件的Webpack插件。 官网:...
建造使用build.sh文件构建应用程序和分发zip文件。 它只是运行mvn clean assembly:assembly 。 这将在目标文件夹中生成一个zip文件,该文件可以上传到Java SE CS。本地运行成功构建后,您可以使用sh target/bin/...
由一种简单Levy过程驱动且系数连续的倒向随机微分方程的若干性质,郑石秋,金殿川,本文研究了由一种简单Levy过程驱动且系数连续的倒向随机微分方程的若干性质,建立此方程的比较定理,给出了解的唯一性与解的连续�