淘宝tfs-client java配置
来源:互联网 发布:yy制作头像软件 编辑:程序博客网 时间:2024/06/06 16:36
pom.xml
[html] view plain copy
- <dependency>
- <groupId>com.taobao.tair</groupId>
- <artifactId>tair-client</artifactId>
- <version>2.3.1</version>
- </dependency>
- <dependency>
- <groupId>com.taobao.common.tair</groupId>
- <artifactId>common-tair</artifactId>
- <version>2.3.1</version>
- </dependency>
- <dependency>
- <groupId>com.taobao.common.tfs</groupId>
- <artifactId>tfs-javaclient</artifactId>
- <version>2.1.6</version>
- </dependency>
[java] view plain copy
- tfs.client.maxWaitThread=100
- tfs.client.timeout=2000
- tfs.client.nsip=192.168.229.3:8108
- tfs.client.tfsClusterIndex=1
- tfs.client.maxCacheItemCount=10000
- tfs.client.maxCacheTime=5000
[html] view plain copy
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
- <beans>
- <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="location">
- <value>classpath:tfs.properties</value>
- </property>
- </bean>
- <bean id="tfsManager" class="com.taobao.common.tfs.DefaultTfsManager" init-method="init" >
- <!-- 整个进程中系统最多等待多少个请求,取决于你有多少个线程并发的请求TFS -->
- <property name="maxWaitThread" value="${tfs.client.maxWaitThread}" />
- <!-- 单个请求最大的等待时间(ms) 超过这个时间放弃这次请求-->
- <property name="timeout" value="${tfs.client.timeout}" />
- <!-- Tfs master nameserver ip address -->
- <property name="nsip" value="${tfs.client.nsip}" />
- <!-- TFS 集群的编号,这个编号只是一种参考,系统初始化的时候会从ns上取,取不到才用本地设置的.!-->
- <property name="tfsClusterIndex" value="${tfs.client.tfsClusterIndex}" />
- <!-- TFS在读取文件的时候会缓存block所在的数据服务器ip,这个参数配置了最多缓存的记录个数!-->
- <property name="maxCacheItemCount" value="${tfs.client.maxCacheItemCount}" />
- <!-- 上一项缓存最大有效的时间(ms)!-->
- <property name="maxCacheTime" value="${tfs.client.maxCacheTime}" />
- <!-- tair排重数据库的serverlist, 至少指定一个ip address -->
- <!--
- <property name="uniqueServerList">
- <list>
- <value>10.232.12.141:5198</value>
- </list>
- </property>
- -->
- <!-- tair排重数据库的groupName -->
- <!--
- <property name="groupName">
- <value>group_1</value>
- </property>
- <property name="namespace">
- <value>100</value>
- </property>
- -->
- </bean>
- <bean id="tfsClientService" class="xxx.xxx.xxx.TfsClientService">
- <property name="tfsManager" ref="tfsManager" />
- </bean>
- </beans>
[java] view plain copy
- public class TfsClientService {
- /**
- * tfs 管理器
- */
- private DefaultTfsManager tfsManager ;
- /**
- * 保存一个文件到 tfs中,文件小于2M
- *
- * @param localFileName 本地文件名
- * @param tfsSuffix 文件后缀
- * @return 保存成功,返回成功后 的tfs文件名,失败返回null
- */
- public String saveFile(String localFileName, String tfsSuffix){
- if(null == localFileName || null == tfsSuffix){
- throw new IllegalArgumentException("保存文件的入参不能为空!localFileName=" + localFileName + ",tfsSuffix=" + tfsSuffix);
- }
- return tfsManager.saveFile(localFileName, null, tfsSuffix);
- }
- /**
- * 保存一个文件字节流到 tfs中,文件小于2M
- *
- * @param data 文件字节流
- * @param tfsSuffix 文件后缀
- * @return 保存成功,返回成功后 的tfs文件名,失败返回null
- */
- public String saveFile(byte[] data, String tfsSuffix){
- if(null == data || null == tfsSuffix){
- throw new IllegalArgumentException("保存文件字节流入参不能为空!data=" + data + ",tfsSuffix=" + tfsSuffix);
- }
- return tfsManager.saveFile(data, null, tfsSuffix);
- }
- /**
- * 保存一个大文件到tfs(文件大于2M),成功返回tfs文件名(L开头),失败返回null
- * tfs文件写大文件,为了断点续传,必须传入一个key参数,来标识此次大文件的写。一次写失败后,再次传入相同的key写,tfsclient会根据key找到前一次已经写完成的部分重用
- * 默认使用localFileName作为key
- *
- * @param localFileName 本地文件名
- * @param tfsFileName 保存到tfs中的文件名 (目前都为null,不支持自定义文件名)
- * @param tfsSuffix 文件后缀
- * @return 保存成功,返回成功后 的tfs文件名,失败返回null
- */
- public String saveLargeFile(String localFileName, String tfsSuffix){
- if(null == localFileName || null == tfsSuffix){
- throw new IllegalArgumentException("保存大文件入参不能为空! localFileName=" + localFileName + ",tfsSuffix=" + tfsSuffix);
- }
- return tfsManager.saveLargeFile(localFileName, null, tfsSuffix);
- }
- /**
- * 保存一个字节流data到tfs(文件大于2M),成功返回tfs文件名,失败返回null,
- * tfs文件写大文件,为了断点续传,必须传入一个key参数,来标识此次大文件的写。一次写失败后,再次传入相同的key写,tfsclient会根据key找到前一次已经写完成的部分重用
- *
- * @param data
- * @param tfsSuffix
- * @param key key name
- * @return
- */
- public String saveLargeFile(byte[] data, String tfsSuffix, String key){
- if(null == data || null == tfsSuffix){
- throw new IllegalArgumentException("保存大文件字节流入参不能为空! data=" + data + ",tfsSuffix=" + tfsSuffix);
- }
- return tfsManager.saveLargeFile(data, null, tfsSuffix, key);
- }
- /**
- * 删除一个文件
- *
- * @param tfsFileName 文件名
- * @param tfsSuffix 文件后缀
- * @return true if delete successully, or false if fail
- */
- public boolean deleteFile(String tfsFileName, String tfsSuffix){
- if(null == tfsFileName || null == tfsSuffix){
- throw new IllegalArgumentException("删除文件名或文件后缀不能为空! tfsFileName=" + tfsFileName + ",tfsSuffix=" + tfsSuffix);
- }
- return tfsManager.unlinkFile(tfsFileName, tfsSuffix);
- }
- /**
- * 从tfs 获取文件到本地
- *
- * @param tfsFileName 需要读取的tfs文件名
- * @param tfsSuffix 需要读取的文件名后缀,需要和存入时后缀相同。
- * @param localFileName 本地文件名
- * @return 读操作成功返回true,读操作失败返回false
- */
- public boolean fetchFile(String tfsFileName, String tfsSuffix, String localFileName){
- if(null == tfsFileName || null == tfsSuffix || null == localFileName ){
- throw new IllegalArgumentException("获取文件入参不能为空! tfsFileName=" + tfsFileName + ",tfsSuffix=" + tfsSuffix + ",localFileName=" + localFileName);
- }
- return tfsManager.fetchFile(tfsFileName, tfsSuffix, localFileName);
- }
- /**
- * 从tfs 获取文件到本地,数据存到输出流
- *
- * @param tfsFileName
- * @param tfsSuffix
- * @param output 数据流
- * @return 读操作成功返回true,读操作失败返回false
- */
- public boolean fetchFile(String tfsFileName, String tfsSuffix, OutputStream output){
- if(null == tfsFileName || null == tfsSuffix || null == output ){
- throw new IllegalArgumentException("获取文件入参不能为空! tfsFileName=" + tfsFileName + ",tfsSuffix=" + tfsSuffix + ",output=" + output);
- }
- return tfsManager.fetchFile(tfsFileName, tfsSuffix, output);
- }
- /**
- * stat一个tfs文件
- *文件的状态有0(正常), 1(删除), 4(隐藏)
- * @param tfsFileName 需要读取的tfs文件名
- * @param tfsSuffix 需要读取的文件名后缀,需要和存入时后缀相同
- * @return 操作成功返回FileInfo,操作失败返回null
- */
- public FileInfo statFile(String tfsFileName, String tfsSuffix){
- if(null == tfsFileName || null == tfsSuffix ){
- throw new IllegalArgumentException("stat文件入参不能为空! tfsFileName=" + tfsFileName + ",tfsSuffix=" + tfsSuffix );
- }
- return tfsManager.statFile(tfsFileName, tfsSuffix);
- }
- public void setTfsManager(DefaultTfsManager tfsManager){
- this.tfsManager = tfsManager;
- }
- public DefaultTfsManager getTfsManager(){
- return this.tfsManager ;
- }
阅读全文
0 0
- 淘宝tfs-client java配置
- 淘宝tfs-client java配置
- 淘宝TFS文件系统配置(集群)
- 淘宝TFS
- 淘宝动态配置diamond-client 准备工作
- 淘宝动态配置diamond-client 源码讲解
- 淘宝技术发展 5.Java时代:创造技术-TFS
- 淘宝技术发展 6.Java时代,创造技术-TFS
- 淘宝技术发展(Java时代:创造技术-TFS)
- 淘宝技术发展(Java时代:创造技术-TFS)
- 淘宝技术发展(Java时代:创造技术-TFS)之七
- 淘宝技术发展6(Java时代:创造技术-TFS)
- 六、淘宝技术发展(Java时代:创造技术-TFS)
- 淘宝技术发展(Java时代:创造技术-TFS)
- TFS(Taobao File System)Java Client 使用经验
- TFS(Taobao File System)Java Client 使用经验
- TFS(Taobao File System)Java Client 使用经验
- 转 淘宝的TFS
- HttpLoggingInterceptor的用法简介
- 工厂模式,抽象工厂模式区别
- 【CUGBACM15级BC第37场 A】hdu 5202 Rikka with string
- my first blog
- 安装qcadoo开源MES的几个坑
- 淘宝tfs-client java配置
- Java-新闻news案例
- LINUX上pycharm远程解释器运行py程序在本地机器上显示plot命令画出来的图像
- 【ExtJs学习笔记】4.DOM操作
- 矩阵快速幂
- PAT-乙级-1016-部分A+B
- LeetCode--4Sum
- 栈(c语言)
- LeetCode:384. Shuffle an Array