- 浏览: 171593 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
19941:
大神,提供的demo读取配置文件有问题啊,一直读取不到。。。
整合了DFS+DHT+MyFastClitn的java客户端实现 -
lobin:
为什么我启动的时候,能启动, 但报如下错误呢?[2016-12 ...
FastDHT(分布式hash系统)安装和与FastDFS整合实现自定义文件ID -
yuqiyi:
这篇文章为了凸显fst得效率也是醉了.其一:kryo不做任何优 ...
高性能序列化框架FST -
a6186694:
247687009 写道aiyoaiyo0330 写道请教个问 ...
淘宝消息中间件RocketMQ的安装和简单使用 -
bo_hai:
能详细讲讲吗?
FastDHT(分布式hash系统)安装和与FastDFS整合实现自定义文件ID
说句难听的话,FastDFS的java客户端,站在java程序员的角度来讲是相当的难用啊。
试着将FastDFS的javaClient整合进电商平台之中
FastDFS客户端初始化方式有两种一种是ClientGlobal.init(String)传入配置文件的路径,另外一种是通过ClientGlobal.set的方式,不过实在是不爽这种set方式啊,附上源码就知道了。
完全就是C程序的风格啊。作为一枚称职的java程序猿,实在是受不了这种方式。那么就用配置文件的方式了吧,来吧,试一试
看到这儿应该明白为啥读不了了吧!泪奔啊!附上改写的源代码
PropertiesLoader依赖了Spring的io包附上源码
试着将FastDFS的javaClient整合进电商平台之中
FastDFS客户端初始化方式有两种一种是ClientGlobal.init(String)传入配置文件的路径,另外一种是通过ClientGlobal.set的方式,不过实在是不爽这种set方式啊,附上源码就知道了。
public static int g_connect_timeout; //millisecond public static int g_network_timeout; //millisecond public static String g_charset; public static int g_tracker_http_port; public static boolean g_anti_steal_token; //if anti-steal token public static String g_secret_key; //generage token secret key public static TrackerGroup g_tracker_group; //set public static int getG_connect_timeout() { return g_connect_timeout; } public static void setG_connect_timeout(int connect_timeout) { ClientGlobal.g_connect_timeout = connect_timeout; } public static int getG_network_timeout() { return g_network_timeout; } public static void setG_network_timeout(int network_timeout) { ClientGlobal.g_network_timeout = network_timeout; } public static String getG_charset() { return g_charset; }
完全就是C程序的风格啊。作为一枚称职的java程序猿,实在是受不了这种方式。那么就用配置文件的方式了吧,来吧,试一试
//先来试试相对路径 ClientGlobal.init("/fastdfs.conf"); //运行,配置文件未找到 //那么在来试试classpath ClientGlobal.init("classpath:fastdfs.conf"); //运行配置文件未找到。 //看来要使用绝招了,直接给系统的绝对路径 ClientGlobal.init("D:/seafood_project/seafood-core/src/main/resources/fastdfs.conf"); //这下子总算是可以了。
但是又来问题了,项目部署的时候不可能这样子配置啊,好的选择肯定还是的从classpath下面找才是。没办法又看源码吧,直接上读取配置文件的源码,你就明白了为啥读取不到了
public class IniFileReader { //居然在用hashTable。。。。。 private Hashtable paramTable; private String conf_filename; /** * @param conf_filename config filename */ public IniFileReader(String conf_filename) throws FileNotFoundException, IOException { this.conf_filename = conf_filename; //看来这里是我们需要的 loadFromFile(conf_filename); } //看到loadFromFile的源码的时候,根本忍不住要改源码啊 private void loadFromFile(String conf_filename) throws FileNotFoundException, IOException { FileReader fReader; BufferedReader buffReader; String line; String[] parts; String name; String value; Object obj; ArrayList valueList; fReader = new FileReader(conf_filename); buffReader = new BufferedReader(fReader); this.paramTable = new Hashtable(); try { while ((line=buffReader.readLine()) != null) { line = line.trim(); if (line.length() == 0 || line.charAt(0) == '#') { continue; } parts = line.split("=", 2); if (parts.length != 2) { continue; } name = parts[0].trim(); value = parts[1].trim(); obj = this.paramTable.get(name); if (obj == null) { this.paramTable.put(name, value); } else if (obj instanceof String) { valueList = new ArrayList(); valueList.add(obj); valueList.add(value); this.paramTable.put(name, valueList); } else { valueList = (ArrayList)obj; valueList.add(value); } } } finally { fReader.close(); } }
看到这儿应该明白为啥读不了了吧!泪奔啊!附上改写的源代码
public class IniFileReader { private PropertiesLoader loader; private String conf_filename; /** * * <p>Title: </p> * <p>Description: </p> * @param conf_filename * @throws FileNotFoundException * @throws IOException */ public IniFileReader(String conf_filename) throws FileNotFoundException, IOException { this.conf_filename = conf_filename; loadFromFile(conf_filename); } /** * * @Description: TODO(这里用一句话描述这个方法的作用) * @author LiuYi * @date 2014年6月5日 上午10:11:14 * @return String */ public String getConfFilename() { return this.conf_filename; } /** * * @Description: TODO(这里用一句话描述这个方法的作用) * @author LiuYi * @date 2014年6月6日 上午10:11:11 * @param name * @return String */ public String getStrValue(String name) { return this.loader.getProperty(name); } /** * * @Description: TODO(这里用一句话描述这个方法的作用) * @author LiuYi * @date 2014年6月5日 上午10:11:01 * @param name * @param default_value * @return int */ public int getIntValue(String name, int default_value) { String szValue = this.loader.getProperty(name); if (szValue == null || "".equals(szValue)) { return default_value; } return Integer.parseInt(szValue); } /** * * @Description: TODO(这里用一句话描述这个方法的作用) * @author LiuYi * @date 2014年6月5日 上午10:10:53 * @param name * @param default_value * @return boolean */ public boolean getBoolValue(String name, boolean default_value) { String szValue = this.loader.getProperty(name); if (szValue == null) { return default_value; } return szValue.equalsIgnoreCase("yes") || szValue.equalsIgnoreCase("on") || szValue.equalsIgnoreCase("true") || szValue.equals("1"); } /** * * @Description: TODO() * @author LiuYi * @date 2014年6月5日 上午10:10:35 * @param name * @return String[] */ public String[] getValues(String name) { List<String> values = new ArrayList<String>(); String val = this.loader.getProperty(name); if (val.contains(",")) { for (String v : val.split(",")) { values.add(v); } } else { values.add(val); } return values.toArray(new String[values.size()]); } /** * * @Description: TODO(这里用一句话描述这个方法的作用) * @author LiuYi * @date 2014年6月5日 上午10:11:54 * @param resourcesPaths * @throws FileNotFoundException * @throws IOException void */ private void loadFromFile(String... resourcesPaths) throws FileNotFoundException, IOException { this.loader = new PropertiesLoader(resourcesPaths); } }
PropertiesLoader依赖了Spring的io包附上源码
/** * Properties文件载入工具类. 可载入多个properties文件, 相同的属性在最后载入的文件中的值将会覆盖之前的值,但以System的Property优先. * @author LiuYi * @version 2014-05-21 */ public class PropertiesLoader { private static ResourceLoader resourceLoader = new DefaultResourceLoader(); private final Properties properties; public PropertiesLoader(String... resourcesPaths) { properties = loadProperties(resourcesPaths); } public Properties getProperties() { return properties; } /** * 取出Property,但以System的Property优先,取不到返回空字符串. */ private String getValue(String key) { String systemProperty = System.getProperty(key); if (systemProperty != null) { return systemProperty; } if (properties.containsKey(key)) { return properties.getProperty(key); } return ""; } /** * 取出String类型的Property,但以System的Property优先,如果都为Null则抛出异常. */ public String getProperty(String key) { String value = getValue(key); if (value == null) { throw new NoSuchElementException(); } return value; } /** * 取出String类型的Property,但以System的Property优先.如果都为Null则返回Default值. */ public String getProperty(String key, String defaultValue) { String value = getValue(key); return value != null ? value : defaultValue; } /** * 取出Integer类型的Property,但以System的Property优先.如果都为Null或内容错误则抛出异常. */ public Integer getInteger(String key) { String value = getValue(key); if (value == null) { return null; } return Integer.valueOf(value); } /** * 取出Integer类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容错误则抛出异常 */ public Integer getInteger(String key, Integer defaultValue) { String value = getValue(key); return value != null ? Integer.valueOf(value) : defaultValue; } /** * 取出Double类型的Property,但以System的Property优先.如果都为Null或内容错误则抛出异常. */ public Double getDouble(String key) { String value = getValue(key); if (value == null) { throw new NoSuchElementException(); } return Double.valueOf(value); } /** * 取出Double类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容错误则抛出异常 */ public Double getDouble(String key, Integer defaultValue) { String value = getValue(key); return value != null ? Double.valueOf(value) : defaultValue; } /** * 取出Boolean类型的Property,但以System的Property优先.如果都为Null抛出异常,如果内容不是true/false则返回false. */ public Boolean getBoolean(String key) { String value = getValue(key); if (value == null) { throw new NoSuchElementException(); } return Boolean.valueOf(value); } /** * 取出Boolean类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容不为true/false则返回false. */ public Boolean getBoolean(String key, boolean defaultValue) { String value = getValue(key); return value != null ? Boolean.valueOf(value) : defaultValue; } /** * 载入多个文件, 文件路径使用Spring Resource格式. */ private Properties loadProperties(String... resourcesPaths) { Properties props = new Properties(); for (String location : resourcesPaths) { // logger.debug("Loading properties file from:" + location); InputStream is = null; try { Resource resource = resourceLoader.getResource(location); is = resource.getInputStream(); props.load(is); } catch (IOException ex) { } finally { try { if(is!=null) is.close(); } catch (IOException e) { e.printStackTrace(); } } } return props; } }
发表评论
-
分布式文件系统TFS(taobao File System)安装
2014-10-31 16:17 1916一。准备编译环境 请在centos5的环境中安装 ... -
FastDFS+nginx实现高可用HA解决单点问题
2014-06-08 22:33 3661参考我之前写的三篇文章。连接给出来了。 FastDFSD的安装 ... -
整合了DFS+DHT+MyFastClitn的java客户端实现
2014-06-06 10:40 3579使用FastDFS的一套东西DFS+DHT+myfastCli ... -
FastDFS错误集合
2014-06-03 17:54 1178Q1.通过命令行上传文件时出现错误:tracker_query ... -
FastDHT(分布式hash系统)安装和与FastDFS整合实现自定义文件ID
2014-05-21 16:54 12871由于项目需要自定义文件的路径名称,而Fastdfs天生就是不支 ... -
FastDFS(三)使用jdk5新增的并发库中的LinkedBlockingQueue实现fifo池
2014-05-19 15:02 2890最近做的电商项目中,使用了fastDFS文件系统来作为图片和 ... -
FastDFS(二)之原生java API的操作
2014-05-19 14:42 7190fastDFS 官方提供了原生的javaAPI支持,可是的是 ... -
FastDFS+Nginx轻量级分布式文件系统安装使用
2014-05-12 23:14 8588一 简介 FastDFS是一个开源的轻量级分布式文件系统 ...
相关推荐
FastDFS_配置文件详解
fastDFS配置文件,主要修改其中的Service就可以了,其他可默认。
FastDFS 是用 c 语言编写的一款开源的分布式文件系统,由阿里巴巴公司开发。FastDFS 为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用 FastDFS很容易搭建一套高...
FastDFS客户端配置文件,主要是为了配置FastDFS服务器的ip地址
整合配置fastdfs、nginx、nginx扩张插件,配置文件配置说明以及需要创建文件说明(zip是对应安装需要的zip)
压缩包内置: 1、FastDFS 相关安装包 2、Nginx 相关安装包 3、Java客户端Demo 4、配置文档(从下载文件到部署上线)
FastDFS是一款分布式文件系统,功能主要包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了文件大容量存储和 高性能访问的问题。FastDFS特别适合以文件为载体的在线服务,如图片、视频、文档等等...
包含4个安装文件:FastDFS_v5.05、fastdfs-nginx-module_v1.16、libfastcommon-1.0.7、nginx-1.8.0。 包含配置文件:tracker.conf、storage.conf、mod_fastdfs.conf、nginx.conf。tracker和storage、mod_fastdfs均已...
FastDFS(Fast Distributed File System)是一个开源的轻量级分布式文件系统,它是以C语言实现的,主要用于存储大规模文件的分布式存储系统。FastDFS 的设计目标是高性能、高可靠性和易扩展。 FastDFS 的核心组件...
fastdfs-6.07.tar,fastdfs-nginx-module-1.22.tar,nginx-1.21.1.tar,libfastcommon-1.0.53.tar,fastcommon-1.0.53.tar,ngx_cache_purge-2.3.tar,mod_fastdfs.conf,nginx.conf,storage.conf,tracker.conf,gcc,pcre,...
FastDFS是一款开源的轻量级分布式文件系统 纯C实现,支持Linux、FreeBSD等UNIX系统 类google FS,不是通用的文件系统,只能通过专有API访问,目前提供了C、Java和PHP API 为互联网应用量身定做,解决大容量文件存储...
vs2017 FastDFSClient C# 源码,经过测试可以正常使用
fastdfs的安装手册说明+配置文件+fastdfs安装包+nginx安装包,压缩包内是自己结合网上资料整理的fastdfs的全套配置及说明,已成功安装并运行
storage/group1--group2,mod_fastdfs.conf;master/backup--keepalived.conf,nginx.conf,nginx_check.sh
FastDFS配置文件
详细的搭建fastdfs文件系统教程文档 包括:介绍 配置 安装包 java操作api。包括:介绍 配置 安装包 java操作api
FastDFS源码流程图,
fastdfs分布式文件系统的安装包以及其中主要模块的配置文件,当中不包括安装手册以及使用方法,安装方法可以参考https://blog.csdn.net/xyang81/article/details/52928230 实现FastDFS分布式文件系统集群安装与配置
fastdfs-client-java-1.25.jar包
FastDFS配置反向代理时nginx.conf配置文件.confFastDFS配置反向代理时nginx.conf配置文件.confFastDFS配置反向代理时nginx.conf配置文件.confFastDFS配置反向代理时nginx.conf配置文件.confFastDFS配置反向代理时...