74 Commits
Author SHA1 Message Date
YuQing e56870bdd8 ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_FETCH_ALL protocol changed 2026-06-28 10:09:16 +08:00
YuQing 4e7b6b3419 README.md changed for v1.39 2025-12-19 11:23:03 +08:00
YuQing ac59ecec49 prevent re-entrancy for closeConnection 2025-12-19 11:15:07 +08:00
YuQing 7825aa0b94 remove private AtomicInteger freeCount 2025-12-18 11:18:46 +08:00
YuQing d29ca63106 ConnectionPool.getKey() use '-' instead of ':' 2025-12-18 10:39:33 +08:00
YuQing 91a5cc2e36 connection broken message with address and port 2025-11-28 09:50:09 +08:00
YuQing cc95bc0244 throw IOException with msg "connection broken" when in.read() < 0 2025-11-27 17:13:23 +08:00
YuQing 7b7a7d76f6 bugfixed: loadStorageServersFromTracker correctly with rw option 2025-11-27 17:04:46 +08:00
YuQing f4c00d7b2a query file info support two combined flags 2025-11-06 15:51:14 +08:00
YuQing 1c1dc946e3 correct spell wrong in HISTORY 2025-10-30 10:25:56 +08:00
YuQing 807be5acd9 monitor protocol compatible with IPv4/IPv6 address automatically 2025-10-26 12:20:11 +08:00
YuQing 1d75bb50d0 monitor API output reserved and available space 2025-09-04 19:39:39 +08:00
YuQing 907239cb67 adapt to FastDFS server V6.13 for read-write separation 2025-08-28 16:09:48 +08:00
YuQing fa0b79527c add config itme: fetch_storage_ids.have_allow_empty_field 2025-07-22 10:01:17 +08:00
YuQing 496da3f0c4 protocol automatically compatible with IPv4/IPv6 address 2025-07-21 16:51:16 +08:00
YuQing 0c954e697b fastdfs-client.properties.sample changed 2025-07-18 10:54:38 +08:00
YuQing 7e644f1ba4 change FDFS_VERSION_SIZE from 6 to 8 2024-02-12 20:23:41 +08:00
YuQing 9d9b1d7fdb correct spell wrong 2023-12-13 11:17:20 +08:00
YuQing bb203bdc71 connect to storage server failover with multi IPs 2023-12-13 10:06:39 +08:00
YuQing 020857dbf1 adapt to FastDFS server V6.11 for IPv6 2023-12-07 16:31:46 +08:00
YuQing da417c7d1c Merge pull request #108 from sunqiangwei1988/master
Added: 增加IPv6支持
2023-11-25 09:29:30 +08:00
zl9527 31eb6beb09 Merge branch 'master' of https://github.com/sunqiangwei1988/fastdfs-client-java 2023-11-02 10:53:27 +08:00
zl9527 208f63f14c Added: 增加IPv6支持
1、增加IPv6地址支持功能。
2、增加 server_ipv6.enabled 配置参数,用来说明服务器端是否开启IPv6支持。
3、修改fdht客户端增加IPv6支持。
2023-11-02 10:53:06 +08:00
YuQing a04626523a Merge pull request #107 from sunqiangwei1988/master
Fixed: 修复Tracker Server返回的TrackerStorageStat数据src_id字段解析问题
2023-10-11 18:20:30 +08:00
zl9527 697bf97442 Fixed: 修复Tracker Server返回的TrackerStorageStat数据src_id字段解析问题
1、在FastDFS中, Tracker Server返回的TrackerStorageStat数据中src_id字段为src storage id。在数据解析的时候变成了srcIpAddr,这与原始含义有出入,特将srcIpAddr改回srcId。
2、修改srcId的数据长度引用,从FDFS_IPADDR_SIZE修改为FDFS_STORAGE_ID_MAX_SIZE,既与FastDFS中的保持一致,又为后续IPv6兼容做准备。
2023-09-30 20:39:28 +08:00
YuQing 45d9a89e25 upgrade version to v1.30 2023-01-30 09:27:21 +08:00
YuQing 42132c694c add @SuppressWarnings(unchecked) 2023-01-29 14:47:09 +08:00
YuQing 1b263e6436 add *.class to .gitignore 2023-01-29 14:16:17 +08:00
tanyawen01770 41655defd8 feature:add history 2023-01-29 11:46:55 +08:00
tanyawen01770 a1df79c50e fix:upgrade pom version 1.30 2023-01-29 09:49:29 +08:00
tanyawen01770 2b4693643a fix:not use code 2023-01-29 09:45:14 +08:00
tanyawen01770 4de15ae592 fix:fail over 2023-01-28 21:37:29 +08:00
tanyawen01770 0087216c0a feature: fail over from index 2023-01-28 19:53:06 +08:00
tanyawen01770 77946b2382 feature: set default failover size 2023-01-28 16:51:33 +08:00
tanyawen01770 0b2ec3aa10 fix:remove not use code 2023-01-28 15:27:19 +08:00
tanyawen01770 8d966af4a4 feature:add tracker server fail over 2023-01-28 15:02:40 +08:00
YuQing 9cc79ed75d Merge pull request #94 from niloay6/fix_configInfo_print
fix: 修复tracker_server配置为域名时,打印信息有误的问题
2021-12-10 15:52:15 +08:00
niloay6 8db4ff7dd0 fix: 修复tracker_server配置为域名时,打印信息有误的问题 2021-07-27 10:50:18 +08:00
YuQing 4987967e0b Merge pull request #88 from happyfish100/dependabot/maven/junit-junit-4.13.1
build(deps-dev): bump junit from 4.12 to 4.13.1
2021-04-20 21:48:12 +08:00
YuQing 56af1ae72f Merge pull request #91 from rui8832/master
feat: 日志依赖 log4j,具体实现由使用方决定
2021-04-20 21:47:11 +08:00
Alvin Zhang 987e9194ad feat: 日志依赖 log4j,具体实现由使用方决定
* 如 Spring Boot 默认使用了 Logback,与 slf4j-log4j12 同时存在时会冲突
2021-04-20 14:11:49 +08:00
dependabot[bot] 670909eed1 build(deps-dev): bump junit from 4.12 to 4.13.1
Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1.
- [Release notes](https://github.com/junit-team/junit4/releases)
- [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md)
- [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-13 14:34:35 +00:00
YuQing 1ba6fb7975 update version for README.md 2020-01-03 08:52:34 +08:00
YuQing aafd0b4b8c upgrade version to v1.29 2020-01-03 08:51:17 +08:00
YuQing 06f5624a8d Merge branch 'feature_add_connect_pool_20191205' 2020-01-01 14:45:04 +08:00
tanyawen 47d53c9a19 fix:active test flag 2019-12-31 15:33:48 +08:00
tanyawen bb13294205 fix:active test flag 2019-12-31 15:32:48 +08:00
tanyawen f742f3c6aa feature:add active test flag 2019-12-31 15:28:43 +08:00
YuQing 0faaa2372b Merge branch 'master' of gitee.com:fastdfs100/fastdfs-client-java 2019-12-31 07:51:40 +08:00
tanyawen 70599a1656 feature: README add connection pool config 2019-12-30 22:28:08 +08:00
YuQing a2bbd5fe33 Merge branch 'feature_add_connect_pool_20191205' of github.com:happyfish100/fastdfs-client-java into feature_add_connect_pool_20191205 2019-12-30 20:57:23 +08:00
YuQing d5589faceb upgrade version to 1.28 2019-12-30 20:57:05 +08:00
tanyawen a5786207cc fix:config sample 2019-12-30 20:55:57 +08:00
YuQing 8b771e37ae change config files 2019-12-30 20:48:09 +08:00
tanyawen 66f3fff05e fix:use global var 2019-12-30 20:35:21 +08:00
tanyawen 4300ca717a fix:getHost change use to getHostAddress 2019-12-30 20:18:35 +08:00
tanyawen b7739178c9 fxi 2019-12-30 19:15:12 +08:00
tanyawen 1b99e59cf7 fix: trim host 2019-12-30 18:28:00 +08:00
tanyawen 4387b89026 fix: factory create connection check 2019-12-30 14:58:40 +08:00
tanyawen 9a9e1cf9f0 fix: throw exception 2019-12-30 14:53:15 +08:00
tanyawen 0bfa4ff1fa fix:delete test config 2019-12-29 21:32:37 +08:00
tanyawen 98f55774cf fix:some function rename 2019-12-29 20:53:37 +08:00
tanyawen 82105c4483 fix:config default value 2019-12-29 09:41:25 +08:00
tanyawen 94d4fab52a fix: trackerServer connection param check 2019-12-29 09:30:26 +08:00
tanyawen 31ad07bae8 fix: pool throw exceptipn 2019-12-29 09:18:23 +08:00
tanyawen 32167310dd feature:add connection pool v2 2019-12-29 03:28:26 +08:00
tanyawen 1336b2b07f feature:add about connection config 2019-12-28 05:36:49 +08:00
tanyawen 006af0379f fix:connection pool 2019-12-28 05:18:42 +08:00
tanyawen 6aa61096b2 feature: add socket connection pool 2019-12-28 01:43:42 +08:00
tanyawen 3c61ba0e7a feature: add socket connection pool 2019-12-28 00:08:45 +08:00
tanyawen 145d80c6ac feature: add socket connection pool 2019-12-27 23:25:16 +08:00
tanyawen 3ad9f94a69 feature: add socket connection pool 2019-12-27 21:41:10 +08:00
happyfish100 61007e579f add LICENSE. 2019-12-26 10:48:41 +08:00
YuQing 70c292f0fc change HISTORY file 2019-11-19 14:40:51 +08:00
41 changed files with 5059 additions and 3919 deletions
+2 -1
View File
@@ -12,6 +12,7 @@ target
*.iws
*.log
.idea
*.conf
*.PNG
*.class
*.swp
+65
View File
@@ -1,7 +1,72 @@
Version 1.40 2026-06-28
* ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_FETCH_ALL protocol changed
you must upgrade your FastDFS server V6.16.0 and higher version
Version 1.39 2025-12-19
* ConnectionPool.getKey() use '-' instead of ':'
* ConnectionManager.java: remove private AtomicInteger freeCount
* ConnectionManager.java: prevent re-entrancy for closeConnection
Version 1.38 2025-11-28
* bugfixed: loadStorageServersFromTracker correctly with rw option
* throw IOException with msg "connection broken" when in.read() < 0
Version 1.37 2025-11-06
* query file info support two combined flags:
ProtoCommon.FDFS_QUERY_FINFO_FLAGS_NOT_CALC_CRC32
ProtoCommon.FDFS_QUERY_FINFO_FLAGS_KEEP_SILENCE
you must upgrade your FastDFS server V6.15.1 and higher version
Version 1.36 2025-10-26
* monitor protocol compatible with IPv4/IPv6 address automatically
* FastDFS server version requirements:
# group and storage statistics / monitor APIs: FastDFS server >= V6.13.1
# other APIs: FastDFS server >= V6.06
Version 1.35 2025-09-04
* group and storage statistics / monitor API output reserved
and available space
* you must upgrade your FastDFS server V6.13.1 and higher version
Version 1.34 2025-08-28
* adapt to FastDFS server V6.13 for read-write separation
you must upgrade your FastDFS server V6.13 and higher version
Version 1.33 2025-07-21
* protocol automatically compatible with IPv4/IPv6 address
this version for FastDFS server V6.06 and higher version
Version 1.32 2024-02-12
* change FDFS_VERSION_SIZE from 6 to 8
you must upgrade your FastDFS server to V6.12 or higher version
Version 1.31 2023-12-13
* adapt to FastDFS server V6.11 for IPv6
you must upgrade your FastDFS server to V6.11 or higher version
* connect to storage server failover with multi IPs
Version 1.30 2023-01-29
* support tracker server fail over
If the tracker server is not specified, when the tracker server fails to
get the connection, it will try to get the connection from other tracker servers.
The maximum number of attempts is the number of tracker servers minus 1
Version 1.29 2020-01-03
* support active test for connection pool.
when the tracker / storage server restarts or the network burst failure
occurs, only one request will be sacrificed (failed), the rest of
the connections in the pool will be enabled to active test for validation.
Version 1.28 2019-12-30
* support connection pool. you can use connection pool or a short connection.
configuration items please see fdfs_client.conf and client.properties
* you must upgrade your FastDFS server to V6.06 or higher version
Version 1.27 2019-11-11
* StorageClient add function: regenerate_filename for appender file
StorageClient1 add function: regenerate_filename1 for appender file
* you must upgrade your FastDFS server to V6.02 or higher version
Version 1.26 2017-04-17
* IniFileReader use getResourceAsStream first
+29
View File
@@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2019, happyfish100
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+15 -1
View File
@@ -26,7 +26,7 @@ mvn install:install-file -DgroupId=org.csource -DartifactId=fastdfs-client-java
<dependency>
<groupId>org.csource</groupId>
<artifactId>fastdfs-client-java</artifactId>
<version>1.27-SNAPSHOT</version>
<version>1.39-SNAPSHOT</version>
</dependency>
```
@@ -53,6 +53,11 @@ http.secret_key = FastDFS1234567890
tracker_server = 10.0.11.247:22122
tracker_server = 10.0.11.248:22122
tracker_server = 10.0.11.249:22122
connection_pool.enabled = true
connection_pool.max_count_per_entry = 500
connection_pool.max_idle_time = 3600
connection_pool.max_wait_time_in_ms = 3000
```
注1tracker_server指向您自己IP地址和端口,1-n个
@@ -80,6 +85,11 @@ fastdfs.http_secret_key = FastDFS1234567890
fastdfs.http_tracker_http_port = 80
fastdfs.tracker_servers = 10.0.11.201:22122,10.0.11.202:22122,10.0.11.203:22122
fastdfs.connection_pool.enabled = true
fastdfs.connection_pool.max_count_per_entry = 500
fastdfs.connection_pool.max_idle_time = 3600
fastdfs.connection_pool.max_wait_time_in_ms = 3000
```
注1properties 配置文件中属性名跟 conf 配置文件不尽相同,并且统一加前缀"fastdfs.",便于整合到用户项目配置文件
@@ -122,6 +132,10 @@ ClientGlobal.configInfo(): {
g_anti_steal_token = false
g_secret_key = FastDFS1234567890
g_tracker_http_port = 80
g_connection_pool_enabled = true
g_connection_pool_max_count_per_entry = 500
g_connection_pool_max_idle_time(ms) = 3600000
g_connection_pool_max_wait_time_in_ms(ms) = 3000
trackerServers = 10.0.11.101:22122,10.0.11.102:22122
}
```
+1 -1
View File
@@ -4,7 +4,7 @@
<target name="init">
<property name="project.name" value="fastdfs-client-java"/>
<property name="project.version" value="1.27-SNAPSHOT"/>
<property name="project.version" value="1.39-SNAPSHOT"/>
<property name="project.java" value="${basedir}/src/main/java"/>
<property name="project.resources" value="${basedir}/src/main/resources"/>
<property name="project.build" value="${basedir}/build"/>
+11
View File
@@ -11,3 +11,14 @@ fastdfs.http_tracker_http_port = 80
fastdfs.tracker_servers = 10.0.11.201:22122,10.0.11.202:22122,10.0.11.203:22122
## Whether to open the connection pool, if not, create a new connection every time
fastdfs.connection_pool.enabled = true
## max_count_per_entry: max connection count per host:port , 0 is not limit
fastdfs.connection_pool.max_count_per_entry = 500
## connections whose the idle time exceeds this time will be closed, unit: second, default value is 3600
fastdfs.connection_pool.max_idle_time = 3600
## Maximum waiting time when the maximum number of connections is reached, unit: millisecond, default value is 1000
fastdfs.connection_pool.max_wait_time_in_ms = 3000
+18
View File
@@ -5,6 +5,24 @@ http.tracker_http_port = 8080
http.anti_steal_token = no
http.secret_key = FastDFS1234567890
#tracker_server
# IPv4:
# for example: 192.168.2.100,122.244.141.46:22122
#
# IPv6:
# for example: [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e]:22122
#
tracker_server = 10.0.11.247:22122
tracker_server = 10.0.11.248:22122
tracker_server = 10.0.11.249:22122
# connect which ip address first for multi IPs of a storage server, value list:
## tracker: connect to the ip address return by tracker server first
## last-connected: connect to the ip address last connected first
# default value is tracker
connect_first_by = tracker
connection_pool.enabled = true
connection_pool.max_count_per_entry = 500
connection_pool.max_idle_time = 3600
connection_pool.max_wait_time_in_ms = 3000
+11 -4
View File
@@ -4,7 +4,7 @@
<groupId>org.csource</groupId>
<artifactId>fastdfs-client-java</artifactId>
<version>1.27-SNAPSHOT</version>
<version>1.40-SNAPSHOT</version>
<name>fastdfs-client-java</name>
<description>fastdfs client for java</description>
<packaging>jar</packaging>
@@ -15,19 +15,26 @@
<maven.test.failure.ignore>true</maven.test.failure.ignore>
<maven.test.skip>true</maven.test.skip>
<jdk.version>1.6</jdk.version>
<slf4j.version>1.7.26</slf4j.version>
</properties>
<dependencies>
<dependency>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.26</version>
<version>${slf4j.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -155,13 +155,13 @@ public class IniFileReader {
} finally {
try {
if (in != null) in.close();
//System.out.println("loadFrom...finally...in.close(); done");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
private void readToParamTable(InputStream in) throws IOException {
this.paramTable = new Hashtable();
if (in == null) return;
@@ -206,7 +206,6 @@ public class IniFileReader {
try {
if (bufferedReader != null) bufferedReader.close();
if (inReader != null) inReader.close();
//System.out.println("readToParamTable...finally...bufferedReader.close();inReader.close(); done");
} catch (Exception ex) {
ex.printStackTrace();
}
@@ -15,7 +15,7 @@ package org.csource.common;
* @version Version 1.0
*/
public class MyException extends Exception {
public MyException() {
public MyException(String s, Exception e) {
}
public MyException(String message) {
@@ -13,6 +13,7 @@ import org.csource.common.MyException;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
@@ -23,7 +24,7 @@ import java.util.Properties;
* Global variables
*
* @author Happy Fish / YuQing
* @version Version 1.11
* @version Version 1.33
*/
public class ClientGlobal {
@@ -34,7 +35,6 @@ public class ClientGlobal {
public static final String CONF_KEY_HTTP_SECRET_KEY = "http.secret_key";
public static final String CONF_KEY_HTTP_TRACKER_HTTP_PORT = "http.tracker_http_port";
public static final String CONF_KEY_TRACKER_SERVER = "tracker_server";
public static final String PROP_KEY_CONNECT_TIMEOUT_IN_SECONDS = "fastdfs.connect_timeout_in_seconds";
public static final String PROP_KEY_NETWORK_TIMEOUT_IN_SECONDS = "fastdfs.network_timeout_in_seconds";
public static final String PROP_KEY_CHARSET = "fastdfs.charset";
@@ -42,6 +42,14 @@ public class ClientGlobal {
public static final String PROP_KEY_HTTP_SECRET_KEY = "fastdfs.http_secret_key";
public static final String PROP_KEY_HTTP_TRACKER_HTTP_PORT = "fastdfs.http_tracker_http_port";
public static final String PROP_KEY_TRACKER_SERVERS = "fastdfs.tracker_servers";
public static final String PROP_KEY_CONNECT_FIRST_BY = "fastdfs.connect_first_by";
public static final String PROP_KEY_CONNECTION_POOL_ENABLED = "fastdfs.connection_pool.enabled";
public static final String PROP_KEY_CONNECTION_POOL_MAX_COUNT_PER_ENTRY = "fastdfs.connection_pool.max_count_per_entry";
public static final String PROP_KEY_CONNECTION_POOL_MAX_IDLE_TIME = "fastdfs.connection_pool.max_idle_time";
public static final String PROP_KEY_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS = "fastdfs.connection_pool.max_wait_time_in_ms";
public static final String PROP_KEY_HAVE_ALLOW_EMPTY_FIELD = "fastdfs.fetch_storage_ids.have_allow_empty_field";
public static final int DEFAULT_CONNECT_TIMEOUT = 5; //second
public static final int DEFAULT_NETWORK_TIMEOUT = 30; //second
@@ -50,18 +58,109 @@ public class ClientGlobal {
public static final String DEFAULT_HTTP_SECRET_KEY = "FastDFS1234567890";
public static final int DEFAULT_HTTP_TRACKER_HTTP_PORT = 80;
public static final int CONNECT_FIRST_BY_TRACKER = 0;
public static final int CONNECT_FIRST_BY_LAST_CONNECTED = 1;
public static final boolean DEFAULT_CONNECTION_POOL_ENABLED = true;
public static final int DEFAULT_CONNECTION_POOL_MAX_COUNT_PER_ENTRY = 100;
public static final int DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME = 3600 ;//second
public static final int DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS = 1000 ;//millisecond
public static int g_connect_timeout = DEFAULT_CONNECT_TIMEOUT * 1000; //millisecond
public static int g_network_timeout = DEFAULT_NETWORK_TIMEOUT * 1000; //millisecond
public static String g_charset = DEFAULT_CHARSET;
public static boolean g_anti_steal_token = DEFAULT_HTTP_ANTI_STEAL_TOKEN; //if anti-steal token
public static String g_secret_key = DEFAULT_HTTP_SECRET_KEY; //generage token secret key
public static int g_tracker_http_port = DEFAULT_HTTP_TRACKER_HTTP_PORT;
public static int g_connect_first_by = CONNECT_FIRST_BY_TRACKER;
public static boolean g_multi_storage_ips = false;
public static StorageAddressMap g_storages_address_map;
public static boolean g_connection_pool_enabled = DEFAULT_CONNECTION_POOL_ENABLED;
public static int g_connection_pool_max_count_per_entry = DEFAULT_CONNECTION_POOL_MAX_COUNT_PER_ENTRY;
public static int g_connection_pool_max_idle_time = DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME * 1000; //millisecond
public static int g_connection_pool_max_wait_time_in_ms = DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS; //millisecond
public static final boolean DEFAULT_HAVE_ALLOW_EMPTY_FIELD = true;
public static boolean g_have_allow_empty_field = DEFAULT_HAVE_ALLOW_EMPTY_FIELD;
public static TrackerGroup g_tracker_group;
private ClientGlobal() {
}
private static void loadStorageServersFromTracker() throws IOException, MyException {
TrackerClient tracker = new TrackerClient();
StringBuilder builder = tracker.fetchStorageIds(g_have_allow_empty_field);
if (builder == null && g_have_allow_empty_field) {
builder = tracker.fetchStorageIds(false);
}
if (builder == null || builder.length() == 0) {
return;
}
boolean without_port = true;
int count = 0;
String[] lines = builder.toString().split("\n");
String[] ipAddresses = new String[lines.length];
for (String line : lines) {
String[] cols = line.split(" ");
if (!(cols.length == 3 || cols.length == 4)) {
throw new MyException("invalid line: " + line);
}
String ipAddrs = cols[2];
if (ipAddrs.indexOf(',') > 0) {
ipAddresses[count++] = ipAddrs;
}
}
if (count == 0) {
return;
}
int startIndex;
if (ipAddresses[0].charAt(0) == '[') { //IPv6
if ((startIndex=ipAddresses[0].indexOf(']')) < 0) {
throw new MyException("invalid IPv6 address: " + ipAddresses[0]);
}
} else {
startIndex = 0;
}
if (ipAddresses[0].indexOf(':', startIndex) > 0) {
without_port = false;
}
g_multi_storage_ips = true;
g_storages_address_map = new StorageAddressMap(without_port);
if (without_port) {
for (String ipAddr: ipAddresses) {
if (ipAddr.charAt(0) == '[') { //IPv6
ipAddr = ipAddr.substring(1, ipAddr.length() - 1);
}
String[] cols = ipAddr.split(",");
g_storages_address_map.puts(cols[0], cols[1]);
}
} else {
for (String ipPort: ipAddresses) {
int colonIndex = ipPort.lastIndexOf(':');
if (colonIndex < 0) {
throw new MyException("invalid ip and port: " + ipPort);
}
String ipAddr = ipPort.substring(0, colonIndex);
int port = Integer.parseInt(ipPort.substring(colonIndex + 1));
if (ipAddr.charAt(0) == '[') { //IPv6
ipAddr = ipAddr.substring(1, ipAddr.length() - 1);
}
String[] cols = ipAddr.split(",");
g_storages_address_map.puts(cols[0], cols[1], port);
}
}
}
/**
* load global variables
*
@@ -98,20 +197,46 @@ public class ClientGlobal {
InetSocketAddress[] tracker_servers = new InetSocketAddress[szTrackerServers.length];
for (int i = 0; i < szTrackerServers.length; i++) {
parts = szTrackerServers[i].split("\\:", 2);
if (szTrackerServers[i].contains("[")) {
parts = new String[2];
parts[0] = szTrackerServers[i].substring(1, szTrackerServers[i].indexOf("]"));
parts[1] = szTrackerServers[i].substring(szTrackerServers[i].lastIndexOf(":") + 1);
} else {
parts = szTrackerServers[i].split("\\:", 2);
}
if (parts.length != 2) {
throw new MyException("the value of item \"tracker_server\" is invalid, the correct format is host:port");
}
tracker_servers[i] = new InetSocketAddress(parts[0].trim(), Integer.parseInt(parts[1].trim()));
tracker_servers[i] = new InetSocketAddress(InetAddress.getByName(parts[0].trim()), Integer.parseInt(parts[1].trim()));
}
g_tracker_group = new TrackerGroup(tracker_servers);
String connect_first_by = iniReader.getStrValue("connect_first_by");
if (connect_first_by != null && connect_first_by.equalsIgnoreCase("last-connected")) {
g_connect_first_by = CONNECT_FIRST_BY_LAST_CONNECTED;
}
g_tracker_http_port = iniReader.getIntValue("http.tracker_http_port", 80);
g_anti_steal_token = iniReader.getBoolValue("http.anti_steal_token", false);
if (g_anti_steal_token) {
g_secret_key = iniReader.getStrValue("http.secret_key");
}
g_connection_pool_enabled = iniReader.getBoolValue("connection_pool.enabled", DEFAULT_CONNECTION_POOL_ENABLED);
g_connection_pool_max_count_per_entry = iniReader.getIntValue("connection_pool.max_count_per_entry", DEFAULT_CONNECTION_POOL_MAX_COUNT_PER_ENTRY);
g_connection_pool_max_idle_time = iniReader.getIntValue("connection_pool.max_idle_time", DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME);
if (g_connection_pool_max_idle_time < 0) {
g_connection_pool_max_idle_time = DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME;
}
g_connection_pool_max_idle_time *= 1000;
g_connection_pool_max_wait_time_in_ms = iniReader.getIntValue("connection_pool.max_wait_time_in_ms", DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS);
if (g_connection_pool_max_wait_time_in_ms < 0) {
g_connection_pool_max_wait_time_in_ms = DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS;
}
g_have_allow_empty_field = iniReader.getBoolValue("fetch_storage_ids.have_allow_empty_field", DEFAULT_HAVE_ALLOW_EMPTY_FIELD);
loadStorageServersFromTracker();
}
/**
@@ -149,6 +274,12 @@ public class ClientGlobal {
String httpAntiStealTokenConf = props.getProperty(PROP_KEY_HTTP_ANTI_STEAL_TOKEN);
String httpSecretKeyConf = props.getProperty(PROP_KEY_HTTP_SECRET_KEY);
String httpTrackerHttpPortConf = props.getProperty(PROP_KEY_HTTP_TRACKER_HTTP_PORT);
String connectFirstBy = props.getProperty(PROP_KEY_CONNECT_FIRST_BY);
String poolEnabled = props.getProperty(PROP_KEY_CONNECTION_POOL_ENABLED);
String poolMaxCountPerEntry = props.getProperty(PROP_KEY_CONNECTION_POOL_MAX_COUNT_PER_ENTRY);
String poolMaxIdleTime = props.getProperty(PROP_KEY_CONNECTION_POOL_MAX_IDLE_TIME);
String poolMaxWaitTimeInMS = props.getProperty(PROP_KEY_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS);
if (connectTimeoutInSecondsConf != null && connectTimeoutInSecondsConf.trim().length() != 0) {
g_connect_timeout = Integer.parseInt(connectTimeoutInSecondsConf.trim()) * 1000;
}
@@ -167,6 +298,29 @@ public class ClientGlobal {
if (httpTrackerHttpPortConf != null && httpTrackerHttpPortConf.trim().length() != 0) {
g_tracker_http_port = Integer.parseInt(httpTrackerHttpPortConf);
}
if (connectFirstBy != null && connectFirstBy.equalsIgnoreCase("last-connected")) {
g_connect_first_by = CONNECT_FIRST_BY_LAST_CONNECTED;
}
if (poolEnabled != null && poolEnabled.trim().length() != 0) {
g_connection_pool_enabled = Boolean.parseBoolean(poolEnabled);
}
if (poolMaxCountPerEntry != null && poolMaxCountPerEntry.trim().length() != 0 ) {
g_connection_pool_max_count_per_entry = Integer.parseInt(poolMaxCountPerEntry);
}
if (poolMaxIdleTime != null && poolMaxIdleTime.trim().length() != 0) {
g_connection_pool_max_idle_time = Integer.parseInt(poolMaxIdleTime) * 1000;
}
if (poolMaxWaitTimeInMS != null && poolMaxWaitTimeInMS.trim().length() != 0) {
g_connection_pool_max_wait_time_in_ms = Integer.parseInt(poolMaxWaitTimeInMS);
}
String haveAllowEmptyField = props.getProperty(PROP_KEY_HAVE_ALLOW_EMPTY_FIELD);
if (haveAllowEmptyField != null && haveAllowEmptyField.trim().length() != 0) {
g_have_allow_empty_field = Boolean.parseBoolean(haveAllowEmptyField);
}
loadStorageServersFromTracker();
}
/**
@@ -177,15 +331,21 @@ public class ClientGlobal {
* server之间用逗号','分隔
*/
public static void initByTrackers(String trackerServers) throws IOException, MyException {
List<InetSocketAddress> list = new ArrayList();
List<InetSocketAddress> list = new ArrayList<InetSocketAddress>();
String spr1 = ",";
String spr2 = ":";
String[] arr1 = trackerServers.trim().split(spr1);
for (String addrStr : arr1) {
String[] arr2 = addrStr.trim().split(spr2);
String host = arr2[0].trim();
int port = Integer.parseInt(arr2[1].trim());
list.add(new InetSocketAddress(host, port));
if(addrStr.contains("[")) {
String host = addrStr.substring(1, addrStr.indexOf("]"));
int port = Integer.parseInt(addrStr.substring(addrStr.lastIndexOf(":") + 1));
list.add(new InetSocketAddress(InetAddress.getByName(host), port));
} else {
String[] arr2 = addrStr.trim().split(spr2);
String host = arr2[0].trim();
int port = Integer.parseInt(arr2[1].trim());
list.add(new InetSocketAddress(InetAddress.getByName(host), port));
}
}
InetSocketAddress[] trackerAddresses = list.toArray(new InetSocketAddress[list.size()]);
initByTrackers(trackerAddresses);
@@ -205,7 +365,7 @@ public class ClientGlobal {
public static Socket getSocket(String ip_addr, int port) throws IOException {
Socket sock = new Socket();
sock.setSoTimeout(ClientGlobal.g_network_timeout);
sock.connect(new InetSocketAddress(ip_addr, port), ClientGlobal.g_connect_timeout);
sock.connect(new InetSocketAddress(InetAddress.getByName(ip_addr), port), ClientGlobal.g_connect_timeout);
return sock;
}
@@ -217,6 +377,7 @@ public class ClientGlobal {
*/
public static Socket getSocket(InetSocketAddress addr) throws IOException {
Socket sock = new Socket();
sock.setReuseAddress(true);
sock.setSoTimeout(ClientGlobal.g_network_timeout);
sock.connect(addr, ClientGlobal.g_connect_timeout);
return sock;
@@ -282,13 +443,18 @@ public class ClientGlobal {
ClientGlobal.g_tracker_group = tracker_group;
}
public static boolean isG_connection_pool_enabled() {
return g_connection_pool_enabled;
}
public static String configInfo() {
String trackerServers = "";
if (g_tracker_group != null) {
InetSocketAddress[] trackerAddresses = g_tracker_group.tracker_servers;
for (InetSocketAddress inetSocketAddress : trackerAddresses) {
if(trackerServers.length() > 0) trackerServers += ",";
trackerServers += inetSocketAddress.toString().substring(1);
String address = inetSocketAddress.toString();
trackerServers += address.startsWith("/") ? address.substring(1) : address;
}
}
return "{"
@@ -298,6 +464,13 @@ public class ClientGlobal {
+ "\n g_anti_steal_token = " + g_anti_steal_token
+ "\n g_secret_key = " + g_secret_key
+ "\n g_tracker_http_port = " + g_tracker_http_port
+ "\n g_multi_storage_ips = " + g_multi_storage_ips
+ "\n g_connect_first_by = " + (g_connect_first_by == CONNECT_FIRST_BY_TRACKER ? "tracker" : "last-connected")
+ "\n g_connection_pool_enabled = " + g_connection_pool_enabled
+ "\n g_connection_pool_max_count_per_entry = " + g_connection_pool_max_count_per_entry
+ "\n g_connection_pool_max_idle_time(ms) = " + g_connection_pool_max_idle_time
+ "\n g_connection_pool_max_wait_time_in_ms(ms) = " + g_connection_pool_max_wait_time_in_ms
+ "\n g_have_allow_empty_field = " + g_have_allow_empty_field
+ "\n trackerServers = " + trackerServers
+ "\n}";
}
@@ -15,6 +15,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.net.InetSocketAddress;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@@ -26,6 +27,7 @@ import java.util.Arrays;
*/
public class ProtoCommon {
public static final byte FDFS_PROTO_CMD_QUIT = 82;
public static final byte TRACKER_PROTO_CMD_FETCH_STORAGE_IDS = 69;
public static final byte TRACKER_PROTO_CMD_SERVER_LIST_GROUP = 91;
public static final byte TRACKER_PROTO_CMD_SERVER_LIST_STORAGE = 92;
public static final byte TRACKER_PROTO_CMD_SERVER_DELETE_STORAGE = 93;
@@ -72,16 +74,20 @@ public class ProtoCommon {
public static final int FDFS_PROTO_PKG_LEN_SIZE = 8;
public static final int FDFS_PROTO_CMD_SIZE = 1;
public static final int FDFS_GROUP_NAME_MAX_LEN = 16;
public static final int FDFS_IPADDR_SIZE = 16;
public static final int FDFS_DOMAIN_NAME_MAX_SIZE = 128;
public static final int FDFS_VERSION_SIZE = 6;
public static final int FDFS_IPV4_SIZE = 16;
public static final int FDFS_IPV6_SIZE = 46;
public static final int FDFS_VERSION_SIZE = 8;
public static final int FDFS_STORAGE_ID_MAX_SIZE = 16;
public static final String FDFS_RECORD_SEPERATOR = "\u0001";
public static final String FDFS_FIELD_SEPERATOR = "\u0002";
public static final int TRACKER_QUERY_STORAGE_FETCH_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN
+ FDFS_IPADDR_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE;
public static final int TRACKER_QUERY_STORAGE_STORE_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN
+ FDFS_IPADDR_SIZE + FDFS_PROTO_PKG_LEN_SIZE;
public static final int TRACKER_QUERY_STORAGE_FETCH_IPV4_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN
+ FDFS_IPV4_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE;
public static final int TRACKER_QUERY_STORAGE_FETCH_IPV6_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN
+ FDFS_IPV6_SIZE - 1 + FDFS_PROTO_PKG_LEN_SIZE;
public static final int TRACKER_QUERY_STORAGE_STORE_IPV4_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN
+ FDFS_IPV4_SIZE + FDFS_PROTO_PKG_LEN_SIZE;
public static final int TRACKER_QUERY_STORAGE_STORE_IPV6_BODY_LEN = FDFS_GROUP_NAME_MAX_LEN
+ FDFS_IPV6_SIZE + FDFS_PROTO_PKG_LEN_SIZE;
public static final byte FDFS_FILE_EXT_NAME_MAX_LEN = 6;
public static final byte FDFS_FILE_PREFIX_MAX_LEN = 16;
public static final byte FDFS_FILE_PATH_LEN = 10;
@@ -102,6 +108,15 @@ public class ProtoCommon {
protected static final int PROTO_HEADER_CMD_INDEX = FDFS_PROTO_PKG_LEN_SIZE;
protected static final int PROTO_HEADER_STATUS_INDEX = FDFS_PROTO_PKG_LEN_SIZE + 1;
//read write mode
public static final byte FDFS_RW_MODE_NONE = 0;
public static final byte FDFS_RW_MODE_READONLY = 4;
public static final byte FDFS_RW_MODE_WRITEONLY = 2;
public static final byte FDFS_RW_MODE_BOTH = FDFS_RW_MODE_READONLY + FDFS_RW_MODE_WRITEONLY;
public static final byte FDFS_QUERY_FINFO_FLAGS_NOT_CALC_CRC32 = 1;
public static final byte FDFS_QUERY_FINFO_FLAGS_KEEP_SILENCE = 2;
private ProtoCommon() {
}
@@ -160,35 +175,48 @@ public class ProtoCommon {
* @param expect_body_len expect response package body length
* @return RecvHeaderInfo: errno and pkg body length
*/
public static RecvHeaderInfo recvHeader(InputStream in, byte expect_cmd, long expect_body_len) throws IOException {
byte[] header;
int bytes;
long pkg_len;
public static RecvHeaderInfo recvHeader(InputStream in, InetSocketAddress socketAddr,
byte expect_cmd, long expect_body_len) throws IOException
{
byte[] header;
int bytes;
long pkg_len;
header = new byte[FDFS_PROTO_PKG_LEN_SIZE + 2];
header = new byte[FDFS_PROTO_PKG_LEN_SIZE + 2];
bytes = in.read(header);
if (bytes != header.length) {
if (bytes < 0) {
throw new IOException("server " + socketAddr.getAddress().getHostAddress()
+ ":" + socketAddr.getPort() + ", connection broken");
} else {
throw new IOException("server " + socketAddr.getAddress().getHostAddress() + ":"
+ socketAddr.getPort() + ", recv package size " + bytes + " != " + header.length);
}
}
if ((bytes = in.read(header)) != header.length) {
throw new IOException("recv package size " + bytes + " != " + header.length);
}
if (header[PROTO_HEADER_CMD_INDEX] != expect_cmd) {
throw new IOException("server " + socketAddr.getAddress().getHostAddress() + ":"
+ socketAddr.getPort() + ", recv cmd: " + header[PROTO_HEADER_CMD_INDEX]
+ " is not correct, expect cmd: " + expect_cmd);
}
if (header[PROTO_HEADER_CMD_INDEX] != expect_cmd) {
throw new IOException("recv cmd: " + header[PROTO_HEADER_CMD_INDEX] + " is not correct, expect cmd: " + expect_cmd);
}
if (header[PROTO_HEADER_STATUS_INDEX] != 0) {
return new RecvHeaderInfo(header[PROTO_HEADER_STATUS_INDEX], 0);
}
if (header[PROTO_HEADER_STATUS_INDEX] != 0) {
return new RecvHeaderInfo(header[PROTO_HEADER_STATUS_INDEX], 0);
}
pkg_len = ProtoCommon.buff2long(header, 0);
if (pkg_len < 0) {
throw new IOException("server " + socketAddr.getAddress().getHostAddress() + ":"
+ socketAddr.getPort() + ", recv body length: " + pkg_len + " < 0!");
}
pkg_len = ProtoCommon.buff2long(header, 0);
if (pkg_len < 0) {
throw new IOException("recv body length: " + pkg_len + " < 0!");
}
if (expect_body_len >= 0 && pkg_len != expect_body_len) {
throw new IOException("server " + socketAddr.getAddress().getHostAddress() + ":"
+ socketAddr.getPort() + ", recv body length: " + pkg_len
+ " is not correct, expect length: " + expect_body_len);
}
if (expect_body_len >= 0 && pkg_len != expect_body_len) {
throw new IOException("recv body length: " + pkg_len + " is not correct, expect length: " + expect_body_len);
}
return new RecvHeaderInfo((byte) 0, pkg_len);
return new RecvHeaderInfo((byte)0, pkg_len);
}
/**
@@ -199,31 +227,40 @@ public class ProtoCommon {
* @param expect_body_len expect response package body length
* @return RecvPackageInfo: errno and reponse body(byte buff)
*/
public static RecvPackageInfo recvPackage(InputStream in, byte expect_cmd, long expect_body_len) throws IOException {
RecvHeaderInfo header = recvHeader(in, expect_cmd, expect_body_len);
if (header.errno != 0) {
return new RecvPackageInfo(header.errno, null);
}
byte[] body = new byte[(int) header.body_len];
int totalBytes = 0;
int remainBytes = (int) header.body_len;
int bytes;
while (totalBytes < header.body_len) {
if ((bytes = in.read(body, totalBytes, remainBytes)) < 0) {
break;
public static RecvPackageInfo recvPackage(InputStream in, InetSocketAddress socketAddr,
byte expect_cmd, long expect_body_len) throws IOException
{
RecvHeaderInfo header = recvHeader(in, socketAddr, expect_cmd, expect_body_len);
if (header.errno != 0) {
return new RecvPackageInfo(header.errno, null);
}
totalBytes += bytes;
remainBytes -= bytes;
}
byte[] body = new byte[(int) header.body_len];
int totalBytes = 0;
int remainBytes = (int) header.body_len;
int bytes = 0;
if (totalBytes != header.body_len) {
throw new IOException("recv package size " + totalBytes + " != " + header.body_len);
}
while (totalBytes < header.body_len) {
if ((bytes = in.read(body, totalBytes, remainBytes)) < 0) {
break;
}
return new RecvPackageInfo((byte) 0, body);
totalBytes += bytes;
remainBytes -= bytes;
}
if (totalBytes != header.body_len) {
String msg = "server " + socketAddr.getAddress().getHostAddress()
+ ":" + socketAddr.getPort() + " connection broken";
if (totalBytes == 0) {
throw new IOException(msg);
} else {
throw new IOException(msg + ", recv length: " + totalBytes
+ ", expect length: " + header.body_len);
}
}
return new RecvPackageInfo((byte)0, body);
}
/**
@@ -306,10 +343,28 @@ public class ProtoCommon {
header = packHeader(FDFS_PROTO_CMD_ACTIVE_TEST, 0, (byte) 0);
sock.getOutputStream().write(header);
RecvHeaderInfo headerInfo = recvHeader(sock.getInputStream(), TRACKER_PROTO_CMD_RESP, 0);
InetSocketAddress socketAddr = new InetSocketAddress(sock.getInetAddress(), sock.getPort());
RecvHeaderInfo headerInfo = recvHeader(sock.getInputStream(), socketAddr, TRACKER_PROTO_CMD_RESP, 0);
return headerInfo.errno == 0 ? true : false;
}
/**
* int convert to buff (big-endian)
*
* @param n int number
* @return 4 bytes buff
*/
public static byte[] int2buff(int n) {
byte[] bs;
bs = new byte[4];
bs[0] = (byte) ((n >> 24) & 0xFF);
bs[1] = (byte) ((n >> 16) & 0xFF);
bs[2] = (byte) ((n >> 8) & 0xFF);
bs[3] = (byte) (n & 0xFF);
return bs;
}
/**
* long convert to buff (big-endian)
*
@@ -317,19 +372,18 @@ public class ProtoCommon {
* @return 8 bytes buff
*/
public static byte[] long2buff(long n) {
byte[] bs;
byte[] bs;
bs = new byte[8];
bs[0] = (byte) ((n >> 56) & 0xFF);
bs[1] = (byte) ((n >> 48) & 0xFF);
bs[2] = (byte) ((n >> 40) & 0xFF);
bs[3] = (byte) ((n >> 32) & 0xFF);
bs[4] = (byte) ((n >> 24) & 0xFF);
bs[5] = (byte) ((n >> 16) & 0xFF);
bs[6] = (byte) ((n >> 8) & 0xFF);
bs[7] = (byte) (n & 0xFF);
return bs;
bs = new byte[8];
bs[0] = (byte) ((n >> 56) & 0xFF);
bs[1] = (byte) ((n >> 48) & 0xFF);
bs[2] = (byte) ((n >> 40) & 0xFF);
bs[3] = (byte) ((n >> 32) & 0xFF);
bs[4] = (byte) ((n >> 24) & 0xFF);
bs[5] = (byte) ((n >> 16) & 0xFF);
bs[6] = (byte) ((n >> 8) & 0xFF);
bs[7] = (byte) (n & 0xFF);
return bs;
}
/**
@@ -27,6 +27,7 @@ public class ProtoStructDecoder<T extends StructBase> {
/**
* decode byte buffer
*/
@SuppressWarnings("unchecked")
public T[] decode(byte[] bs, Class<T> clazz, int fieldsTotalSize) throws Exception {
if (bs.length % fieldsTotalSize != 0) {
throw new IOException("byte array length: " + bs.length + " is invalid!");
@@ -0,0 +1,62 @@
/**
* Copyright (C) 2023 Happy Fish / YuQing
* <p>
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
* General Public License (LGPL).
* Please visit the FastDFS Home Page https://github.com/happyfish100/fastdfs for more detail.
*/
package org.csource.fastdfs;
import java.util.HashMap;
import java.net.InetSocketAddress;
/**
* Storage Server Address Map
*
* @author Happy Fish / YuQing
* @version Version 1.31
*/
public class StorageAddressMap {
protected boolean without_port;
protected HashMap<String, InetSocketAddress> storages;
public StorageAddressMap(boolean without_port) {
this.without_port = without_port;
this.storages = new HashMap<String, InetSocketAddress>();
}
protected String getKey(String ipAddr, int port) {
return ipAddr + "@" + port;
}
public void puts(String srcIpAddr, String destIpAddr, int port) {
storages.put(this.getKey(srcIpAddr, port),
new InetSocketAddress(destIpAddr, port));
storages.put(this.getKey(destIpAddr, port),
new InetSocketAddress(srcIpAddr, port));
}
public void puts(String srcIpAddr, String destIpAddr) {
storages.put(srcIpAddr, new InetSocketAddress(destIpAddr, 0));
storages.put(destIpAddr, new InetSocketAddress(srcIpAddr, 0));
}
public InetSocketAddress get(String ipAddr, int port) {
if (this.without_port) {
InetSocketAddress sockAddr;
if ((sockAddr=storages.get(ipAddr)) == null) {
return null;
}
return new InetSocketAddress(sockAddr.getAddress(), port);
} else {
return storages.get(this.getKey(ipAddr, port));
}
}
public InetSocketAddress get(InetSocketAddress sockAddr) {
return this.get(sockAddr.getAddress().getHostAddress(), sockAddr.getPort());
}
}
File diff suppressed because it is too large Load Diff
@@ -735,16 +735,26 @@ public class StorageClient1 extends StorageClient {
* get file info from storage server
*
* @param file_id the file id(including group name and filename)
* @param flags combined flags as following:
* ProtoCommon.FDFS_QUERY_FINFO_FLAGS_NOT_CALC_CRC32 : do NOT calculate CRC32
* for appender file or slave file
* ProtoCommon.FDFS_QUERY_FINFO_FLAGS_KEEP_SILENCE : keep silence,
* when this file not exist, do not log error on storage server
* @return FileInfo object for success, return null for fail
*/
public FileInfo query_file_info1(String file_id) throws IOException, MyException {
String[] parts = new String[2];
this.errno = this.split_file_id(file_id, parts);
if (this.errno != 0) {
return null;
}
public FileInfo query_file_info1(String file_id, byte flags) throws IOException, MyException {
String[] parts = new String[2];
this.errno = this.split_file_id(file_id, parts);
if (this.errno != 0) {
return null;
}
return this.query_file_info(parts[0], parts[1]);
return this.query_file_info(parts[0], parts[1], flags);
}
public FileInfo query_file_info1(String file_id) throws IOException, MyException {
final byte flags = 0;
return this.query_file_info1(file_id, flags);
}
/**
@@ -9,6 +9,9 @@
package org.csource.fastdfs;
import java.io.IOException;
import java.util.Hashtable;
import org.csource.common.MyException;
import org.csource.fastdfs.pool.Connection;
import java.net.InetSocketAddress;
/**
@@ -18,40 +21,112 @@ import java.net.InetSocketAddress;
* @version Version 1.11
*/
public class StorageServer extends TrackerServer {
protected int store_path_index = 0;
protected int store_path_index = 0;
/**
* Constructor
*
* @param ip_addr the ip address of storage server
* @param port the port of storage server
* @param store_path the store path index on the storage server
*/
public StorageServer(String ip_addr, int port, int store_path) throws IOException {
super(ClientGlobal.getSocket(ip_addr, port), new InetSocketAddress(ip_addr, port));
this.store_path_index = store_path;
}
protected static Hashtable<String, InetSocketAddress> sockAddressCache = new Hashtable<String, InetSocketAddress>();
/**
* Constructor
*
* @param ip_addr the ip address of storage server
* @param port the port of storage server
* @param store_path the store path index on the storage server
*/
public StorageServer(String ip_addr, int port, byte store_path) throws IOException {
super(ClientGlobal.getSocket(ip_addr, port), new InetSocketAddress(ip_addr, port));
if (store_path < 0) {
this.store_path_index = 256 + store_path;
} else {
this.store_path_index = store_path;
/**
* Constructor
*
* @param ip_addr the ip address of storage server
* @param port the port of storage server
* @param store_path the store path index on the storage server
*/
public StorageServer(String ip_addr, int port, int store_path) throws IOException {
super(new InetSocketAddress(ip_addr, port));
this.store_path_index = store_path;
}
}
/**
* @return the store path index on the storage server
*/
public int getStorePathIndex() {
return this.store_path_index;
}
/**
* Constructor
*
* @param ip_addr the ip address of storage server
* @param port the port of storage server
* @param store_path the store path index on the storage server
*/
public StorageServer(String ip_addr, int port, byte store_path) throws IOException {
super(new InetSocketAddress(ip_addr, port));
if (store_path < 0) {
this.store_path_index = 256 + store_path;
} else {
this.store_path_index = store_path;
}
}
/**
* @return the store path index on the storage server
*/
public int getStorePathIndex() {
return this.store_path_index;
}
public Connection getConnection() throws MyException, IOException {
Connection connection;
InetSocketAddress sockAddr;
MyException myException = null;
IOException ioException = null;
if (!ClientGlobal.g_multi_storage_ips) {
return super.getConnection();
}
if (ClientGlobal.g_connect_first_by == ClientGlobal.CONNECT_FIRST_BY_TRACKER) {
try {
if ((connection=super.getConnection()) != null) {
return connection;
}
} catch (MyException ex1) {
myException = ex1;
} catch (IOException ex2) {
ioException = ex2;
}
sockAddr = ClientGlobal.g_storages_address_map.get(this.inetSockAddr);
if (sockAddr != null) {
return super.getConnection(sockAddr);
} else if (myException != null) {
throw myException;
} else if (ioException != null) {
throw ioException;
}
} else {
String key = this.inetSockAddr.getAddress().getHostAddress() +
"@" + this.inetSockAddr.getPort();
sockAddr = sockAddressCache.get(key);
try {
if (sockAddr == null) {
sockAddr = this.inetSockAddr;
if ((connection=super.getConnection(sockAddr)) != null) {
sockAddressCache.put(key, sockAddr);
return connection;
}
} else {
if ((connection=super.getConnection(sockAddr)) != null) {
return connection;
}
}
} catch (MyException ex1) {
myException = ex1;
} catch (IOException ex2) {
ioException = ex2;
}
//retry another ip address
if ((sockAddr=ClientGlobal.g_storages_address_map.get(sockAddr)) == null) {
if (myException != null) {
throw myException;
} else if (ioException != null) {
throw ioException;
}
return null;
}
if ((connection=super.getConnection(sockAddr)) != null) {
sockAddressCache.put(key, sockAddr);
return connection;
}
}
return null;
}
}
@@ -12,74 +12,94 @@ package org.csource.fastdfs;
* C struct body decoder
*
* @author Happy Fish / YuQing
* @version Version 1.18
* @version Version 1.34
*/
public class StructGroupStat extends StructBase {
protected static final int FIELD_INDEX_GROUP_NAME = 0;
protected static final int FIELD_INDEX_TOTAL_MB = 1;
protected static final int FIELD_INDEX_FREE_MB = 2;
protected static final int FIELD_INDEX_TRUNK_FREE_MB = 3;
protected static final int FIELD_INDEX_STORAGE_COUNT = 4;
protected static final int FIELD_INDEX_STORAGE_PORT = 5;
protected static final int FIELD_INDEX_STORAGE_HTTP_PORT = 6;
protected static final int FIELD_INDEX_ACTIVE_COUNT = 7;
protected static final int FIELD_INDEX_CURRENT_WRITE_SERVER = 8;
protected static final int FIELD_INDEX_STORE_PATH_COUNT = 9;
protected static final int FIELD_INDEX_SUBDIR_COUNT_PER_PATH = 10;
protected static final int FIELD_INDEX_CURRENT_TRUNK_FILE_ID = 11;
protected static final int FIELD_INDEX_RESERVED_MB = 3;
protected static final int FIELD_INDEX_TRUNK_FREE_MB = 4;
protected static final int FIELD_INDEX_STORAGE_COUNT = 5;
protected static final int FIELD_INDEX_STORAGE_PORT = 6;
protected static final int FIELD_INDEX_READABLE_SERVER_COUNT = 7;
protected static final int FIELD_INDEX_WRITABLE_SERVER_COUNT = 8;
protected static final int FIELD_INDEX_CURRENT_WRITE_SERVER = 9;
protected static final int FIELD_INDEX_STORE_PATH_COUNT = 10;
protected static final int FIELD_INDEX_SUBDIR_COUNT_PER_PATH = 11;
protected static final int FIELD_INDEX_CURRENT_TRUNK_FILE_ID = 12;
protected static final int FIELD_COUNT = 13;
protected static int fieldsTotalSize;
protected static StructBase.FieldInfo[] fieldsArray = new StructBase.FieldInfo[12];
protected static StructBase.FieldInfo[] fieldsArray = new StructBase.FieldInfo[FIELD_COUNT];
static {
int offset = 0;
fieldsArray[FIELD_INDEX_GROUP_NAME] = new StructBase.FieldInfo("groupName", offset, ProtoCommon.FDFS_GROUP_NAME_MAX_LEN + 1);
fieldsArray[FIELD_INDEX_GROUP_NAME] = new StructBase.FieldInfo(
"groupName", offset, ProtoCommon.FDFS_GROUP_NAME_MAX_LEN + 1);
offset += ProtoCommon.FDFS_GROUP_NAME_MAX_LEN + 1;
fieldsArray[FIELD_INDEX_TOTAL_MB] = new StructBase.FieldInfo("totalMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_TOTAL_MB] = new StructBase.FieldInfo(
"totalMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_FREE_MB] = new StructBase.FieldInfo("freeMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_FREE_MB] = new StructBase.FieldInfo(
"freeMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TRUNK_FREE_MB] = new StructBase.FieldInfo("trunkFreeMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_RESERVED_MB] = new StructBase.FieldInfo(
"reservedMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_STORAGE_COUNT] = new StructBase.FieldInfo("storageCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_TRUNK_FREE_MB] = new StructBase.FieldInfo(
"trunkFreeMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_STORAGE_PORT] = new StructBase.FieldInfo("storagePort", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_STORAGE_COUNT] = new StructBase.FieldInfo(
"storageCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_STORAGE_HTTP_PORT] = new StructBase.FieldInfo("storageHttpPort", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_STORAGE_PORT] = new StructBase.FieldInfo(
"storagePort", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_ACTIVE_COUNT] = new StructBase.FieldInfo("activeCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_READABLE_SERVER_COUNT] = new StructBase.FieldInfo(
"readableServerCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_CURRENT_WRITE_SERVER] = new StructBase.FieldInfo("currentWriteServer", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_WRITABLE_SERVER_COUNT] = new StructBase.FieldInfo(
"writableServerCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_STORE_PATH_COUNT] = new StructBase.FieldInfo("storePathCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_CURRENT_WRITE_SERVER] = new StructBase.FieldInfo(
"currentWriteServer", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUBDIR_COUNT_PER_PATH] = new StructBase.FieldInfo("subdirCountPerPath", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_STORE_PATH_COUNT] = new StructBase.FieldInfo(
"storePathCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_CURRENT_TRUNK_FILE_ID] = new StructBase.FieldInfo("currentTrunkFileId", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
fieldsArray[FIELD_INDEX_SUBDIR_COUNT_PER_PATH] = new StructBase.FieldInfo(
"subdirCountPerPath", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_CURRENT_TRUNK_FILE_ID] = new StructBase.FieldInfo(
"currentTrunkFileId", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsTotalSize = offset;
}
protected String groupName; //name of this group
protected long totalMB; //total disk storage in MB
protected long totalMB; //total disk space in MB
protected long freeMB; //free disk space in MB
protected long reservedMB; //reserved disk space in MB
protected long trunkFreeMB; //trunk free space in MB
protected int storageCount; //storage server count
protected int storagePort; //storage server port
protected int storageHttpPort; //storage server HTTP port
protected int activeCount; //active storage server count
protected int readableServerCount; //readable storage server count
protected int writableServerCount; //writable storage server count
protected int currentWriteServer; //current storage server index to upload file
protected int storePathCount; //store base path count of each storage server
protected int subdirCountPerPath; //sub dir count per store path
@@ -121,6 +141,15 @@ public class StructGroupStat extends StructBase {
return this.freeMB;
}
/**
* get reserved disk space in MB
*
* @return reserved disk space in MB
*/
public long getReservedMB() {
return this.reservedMB;
}
/**
* get trunk free space in MB
*
@@ -139,13 +168,22 @@ public class StructGroupStat extends StructBase {
return this.storageCount;
}
/**
* get readable storage server count
*
* @return readable storage server count
*/
public int getReadableServerCount() {
return this.readableServerCount;
}
/**
* get active storage server count in this group
*
* @return active storage server count in this group
*/
public int getActiveCount() {
return this.activeCount;
public int getWritableServerCount() {
return this.writableServerCount;
}
/**
@@ -157,15 +195,6 @@ public class StructGroupStat extends StructBase {
return this.storagePort;
}
/**
* get storage server HTTP port
*
* @return storage server HTTP port
*/
public int getStorageHttpPort() {
return this.storageHttpPort;
}
/**
* get current storage server index to upload file
*
@@ -212,11 +241,12 @@ public class StructGroupStat extends StructBase {
this.groupName = stringValue(bs, offset, fieldsArray[FIELD_INDEX_GROUP_NAME]);
this.totalMB = longValue(bs, offset, fieldsArray[FIELD_INDEX_TOTAL_MB]);
this.freeMB = longValue(bs, offset, fieldsArray[FIELD_INDEX_FREE_MB]);
this.reservedMB = longValue(bs, offset, fieldsArray[FIELD_INDEX_RESERVED_MB]);
this.trunkFreeMB = longValue(bs, offset, fieldsArray[FIELD_INDEX_TRUNK_FREE_MB]);
this.storageCount = intValue(bs, offset, fieldsArray[FIELD_INDEX_STORAGE_COUNT]);
this.storagePort = intValue(bs, offset, fieldsArray[FIELD_INDEX_STORAGE_PORT]);
this.storageHttpPort = intValue(bs, offset, fieldsArray[FIELD_INDEX_STORAGE_HTTP_PORT]);
this.activeCount = intValue(bs, offset, fieldsArray[FIELD_INDEX_ACTIVE_COUNT]);
this.readableServerCount = intValue(bs, offset, fieldsArray[FIELD_INDEX_READABLE_SERVER_COUNT]);
this.writableServerCount = intValue(bs, offset, fieldsArray[FIELD_INDEX_WRITABLE_SERVER_COUNT]);
this.currentWriteServer = intValue(bs, offset, fieldsArray[FIELD_INDEX_CURRENT_WRITE_SERVER]);
this.storePathCount = intValue(bs, offset, fieldsArray[FIELD_INDEX_STORE_PATH_COUNT]);
this.subdirCountPerPath = intValue(bs, offset, fieldsArray[FIELD_INDEX_SUBDIR_COUNT_PER_PATH]);
@@ -0,0 +1,46 @@
/**
* Copyright (C) 2025 Happy Fish / YuQing
* <p>
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
* General Public License (LGPL).
* Please visit the FastDFS Home Page https://github.com/happyfish100/fastdfs for more detail.
*/
package org.csource.fastdfs;
import java.util.Date;
/**
* C struct body decoder
*
* @author Happy Fish / YuQing
* @version Version 1.36
*/
public class StructIPv4StorageStat extends StructStorageStat {
protected static int fieldsTotalSize;
protected static StructBase.FieldInfo[] fieldsArray =
new StructBase.FieldInfo[StructStorageStat.FIELD_COUNT];
static {
fieldsTotalSize = StructStorageStat.initFieldsArray(
fieldsArray, ProtoCommon.FDFS_IPV4_SIZE);
}
/**
* get fields total size
*
* @return fields total size
*/
public static int getFieldsTotalSize() {
return fieldsTotalSize;
}
/**
*
* @param bs byte array
* @param offset start offset
*/
public void setFields(byte[] bs, int offset) {
super.setFields(fieldsArray, bs, offset);
}
}
@@ -0,0 +1,46 @@
/**
* Copyright (C) 2025 Happy Fish / YuQing
* <p>
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
* General Public License (LGPL).
* Please visit the FastDFS Home Page https://github.com/happyfish100/fastdfs for more detail.
*/
package org.csource.fastdfs;
import java.util.Date;
/**
* C struct body decoder
*
* @author Happy Fish / YuQing
* @version Version 1.36
*/
public class StructIPv6StorageStat extends StructStorageStat {
protected static int fieldsTotalSize;
protected static StructBase.FieldInfo[] fieldsArray =
new StructBase.FieldInfo[StructStorageStat.FIELD_COUNT];
static {
fieldsTotalSize = StructStorageStat.initFieldsArray(
fieldsArray, ProtoCommon.FDFS_IPV6_SIZE);
}
/**
* get fields total size
*
* @return fields total size
*/
public static int getFieldsTotalSize() {
return fieldsTotalSize;
}
/**
*
* @param bs byte array
* @param offset start offset
*/
public void setFields(byte[] bs, int offset) {
super.setFields(fieldsArray, bs, offset);
}
}
@@ -14,25 +14,26 @@ import java.util.Date;
* C struct body decoder
*
* @author Happy Fish / YuQing
* @version Version 1.25
* @version Version 1.35
*/
public class StructStorageStat extends StructBase {
protected static final int FIELD_INDEX_STATUS = 0;
protected static final int FIELD_INDEX_ID = 1;
protected static final int FIELD_INDEX_IP_ADDR = 2;
protected static final int FIELD_INDEX_DOMAIN_NAME = 3;
protected static final int FIELD_INDEX_SRC_IP_ADDR = 4;
protected static final int FIELD_INDEX_RW_MODE = 1;
protected static final int FIELD_INDEX_ID = 2;
protected static final int FIELD_INDEX_IP_ADDR = 3;
protected static final int FIELD_INDEX_SRC_ID = 4;
protected static final int FIELD_INDEX_VERSION = 5;
protected static final int FIELD_INDEX_JOIN_TIME = 6;
protected static final int FIELD_INDEX_UP_TIME = 7;
protected static final int FIELD_INDEX_TOTAL_MB = 8;
protected static final int FIELD_INDEX_FREE_MB = 9;
protected static final int FIELD_INDEX_UPLOAD_PRIORITY = 10;
protected static final int FIELD_INDEX_STORE_PATH_COUNT = 11;
protected static final int FIELD_INDEX_SUBDIR_COUNT_PER_PATH = 12;
protected static final int FIELD_INDEX_CURRENT_WRITE_PATH = 13;
protected static final int FIELD_INDEX_STORAGE_PORT = 14;
protected static final int FIELD_INDEX_STORAGE_HTTP_PORT = 15;
protected static final int FIELD_INDEX_RESERVED_MB = 10;
protected static final int FIELD_INDEX_UPLOAD_PRIORITY = 11;
protected static final int FIELD_INDEX_STORE_PATH_COUNT = 12;
protected static final int FIELD_INDEX_SUBDIR_COUNT_PER_PATH = 13;
protected static final int FIELD_INDEX_CURRENT_WRITE_PATH = 14;
protected static final int FIELD_INDEX_STORAGE_PORT = 15;
protected static final int FIELD_INDEX_CONNECTION_ALLOC_COUNT = 16;
protected static final int FIELD_INDEX_CONNECTION_CURRENT_COUNT = 17;
@@ -82,216 +83,277 @@ public class StructStorageStat extends StructBase {
protected static final int FIELD_INDEX_LAST_HEART_BEAT_TIME = 60;
protected static final int FIELD_INDEX_IF_TRUNK_FILE = 61;
protected static int fieldsTotalSize;
protected static StructBase.FieldInfo[] fieldsArray = new StructBase.FieldInfo[62];
protected static final int FIELD_COUNT = 62;
static {
int offset = 0;
protected static int initFieldsArray(StructBase.FieldInfo[] fieldsArray, int ipaddr_size) {
int offset = 0;
fieldsArray[FIELD_INDEX_STATUS] = new StructBase.FieldInfo("status", offset, 1);
offset += 1;
fieldsArray[FIELD_INDEX_STATUS] = new StructBase.FieldInfo(
"status", offset, 1);
offset += 1;
fieldsArray[FIELD_INDEX_ID] = new StructBase.FieldInfo("id", offset, ProtoCommon.FDFS_STORAGE_ID_MAX_SIZE);
offset += ProtoCommon.FDFS_STORAGE_ID_MAX_SIZE;
fieldsArray[FIELD_INDEX_RW_MODE] = new StructBase.FieldInfo(
"readWriteMode", offset, 1);
offset += 1;
fieldsArray[FIELD_INDEX_IP_ADDR] = new StructBase.FieldInfo("ipAddr", offset, ProtoCommon.FDFS_IPADDR_SIZE);
offset += ProtoCommon.FDFS_IPADDR_SIZE;
fieldsArray[FIELD_INDEX_ID] = new StructBase.FieldInfo(
"id", offset, ProtoCommon.FDFS_STORAGE_ID_MAX_SIZE);
offset += ProtoCommon.FDFS_STORAGE_ID_MAX_SIZE;
fieldsArray[FIELD_INDEX_DOMAIN_NAME] = new StructBase.FieldInfo("domainName", offset, ProtoCommon.FDFS_DOMAIN_NAME_MAX_SIZE);
offset += ProtoCommon.FDFS_DOMAIN_NAME_MAX_SIZE;
fieldsArray[FIELD_INDEX_IP_ADDR] = new StructBase.FieldInfo(
"ipAddr", offset, ipaddr_size);
offset += ipaddr_size;
fieldsArray[FIELD_INDEX_SRC_IP_ADDR] = new StructBase.FieldInfo("srcIpAddr", offset, ProtoCommon.FDFS_IPADDR_SIZE);
offset += ProtoCommon.FDFS_IPADDR_SIZE;
fieldsArray[FIELD_INDEX_SRC_ID] = new StructBase.FieldInfo(
"srcId", offset, ProtoCommon.FDFS_STORAGE_ID_MAX_SIZE);
offset += ProtoCommon.FDFS_STORAGE_ID_MAX_SIZE;
fieldsArray[FIELD_INDEX_VERSION] = new StructBase.FieldInfo("version", offset, ProtoCommon.FDFS_VERSION_SIZE);
offset += ProtoCommon.FDFS_VERSION_SIZE;
fieldsArray[FIELD_INDEX_VERSION] = new StructBase.FieldInfo(
"version", offset, ProtoCommon.FDFS_VERSION_SIZE);
offset += ProtoCommon.FDFS_VERSION_SIZE;
fieldsArray[FIELD_INDEX_JOIN_TIME] = new StructBase.FieldInfo("joinTime", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_JOIN_TIME] = new StructBase.FieldInfo(
"joinTime", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_UP_TIME] = new StructBase.FieldInfo("upTime", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_UP_TIME] = new StructBase.FieldInfo(
"upTime", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_MB] = new StructBase.FieldInfo("totalMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_MB] = new StructBase.FieldInfo(
"totalMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_FREE_MB] = new StructBase.FieldInfo("freeMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_FREE_MB] = new StructBase.FieldInfo(
"freeMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_UPLOAD_PRIORITY] = new StructBase.FieldInfo("uploadPriority", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_RESERVED_MB] = new StructBase.FieldInfo(
"reservedMB", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_STORE_PATH_COUNT] = new StructBase.FieldInfo("storePathCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_UPLOAD_PRIORITY] = new StructBase.FieldInfo(
"uploadPriority", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUBDIR_COUNT_PER_PATH] = new StructBase.FieldInfo("subdirCountPerPath", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_STORE_PATH_COUNT] = new StructBase.FieldInfo(
"storePathCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_CURRENT_WRITE_PATH] = new StructBase.FieldInfo("currentWritePath", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUBDIR_COUNT_PER_PATH] = new StructBase.FieldInfo(
"subdirCountPerPath", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_STORAGE_PORT] = new StructBase.FieldInfo("storagePort", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_CURRENT_WRITE_PATH] = new StructBase.FieldInfo(
"currentWritePath", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_STORAGE_HTTP_PORT] = new StructBase.FieldInfo("storageHttpPort", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_STORAGE_PORT] = new StructBase.FieldInfo(
"storagePort", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_CONNECTION_ALLOC_COUNT] = new StructBase.FieldInfo("connectionAllocCount", offset, 4);
offset += 4;
fieldsArray[FIELD_INDEX_CONNECTION_ALLOC_COUNT] = new StructBase.FieldInfo(
"connectionAllocCount", offset, 4);
offset += 4;
fieldsArray[FIELD_INDEX_CONNECTION_CURRENT_COUNT] = new StructBase.FieldInfo("connectionCurrentCount", offset, 4);
offset += 4;
fieldsArray[FIELD_INDEX_CONNECTION_CURRENT_COUNT] = new StructBase.FieldInfo(
"connectionCurrentCount", offset, 4);
offset += 4;
fieldsArray[FIELD_INDEX_CONNECTION_MAX_COUNT] = new StructBase.FieldInfo("connectionMaxCount", offset, 4);
offset += 4;
fieldsArray[FIELD_INDEX_CONNECTION_MAX_COUNT] = new StructBase.FieldInfo(
"connectionMaxCount", offset, 4);
offset += 4;
fieldsArray[FIELD_INDEX_TOTAL_UPLOAD_COUNT] = new StructBase.FieldInfo("totalUploadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_UPLOAD_COUNT] = new StructBase.FieldInfo(
"totalUploadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_UPLOAD_COUNT] = new StructBase.FieldInfo("successUploadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_UPLOAD_COUNT] = new StructBase.FieldInfo(
"successUploadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_APPEND_COUNT] = new StructBase.FieldInfo("totalAppendCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_APPEND_COUNT] = new StructBase.FieldInfo(
"totalAppendCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_APPEND_COUNT] = new StructBase.FieldInfo("successAppendCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_APPEND_COUNT] = new StructBase.FieldInfo(
"successAppendCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_MODIFY_COUNT] = new StructBase.FieldInfo("totalModifyCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_MODIFY_COUNT] = new StructBase.FieldInfo(
"totalModifyCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_MODIFY_COUNT] = new StructBase.FieldInfo("successModifyCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_MODIFY_COUNT] = new StructBase.FieldInfo(
"successModifyCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_TRUNCATE_COUNT] = new StructBase.FieldInfo("totalTruncateCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_TRUNCATE_COUNT] = new StructBase.FieldInfo(
"totalTruncateCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_TRUNCATE_COUNT] = new StructBase.FieldInfo("successTruncateCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_TRUNCATE_COUNT] = new StructBase.FieldInfo(
"successTruncateCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_SET_META_COUNT] = new StructBase.FieldInfo("totalSetMetaCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_SET_META_COUNT] = new StructBase.FieldInfo(
"totalSetMetaCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_SET_META_COUNT] = new StructBase.FieldInfo("successSetMetaCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_SET_META_COUNT] = new StructBase.FieldInfo(
"successSetMetaCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_DELETE_COUNT] = new StructBase.FieldInfo("totalDeleteCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_DELETE_COUNT] = new StructBase.FieldInfo(
"totalDeleteCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_DELETE_COUNT] = new StructBase.FieldInfo("successDeleteCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_DELETE_COUNT] = new StructBase.FieldInfo(
"successDeleteCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_DOWNLOAD_COUNT] = new StructBase.FieldInfo("totalDownloadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_DOWNLOAD_COUNT] = new StructBase.FieldInfo(
"totalDownloadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_DOWNLOAD_COUNT] = new StructBase.FieldInfo("successDownloadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_DOWNLOAD_COUNT] = new StructBase.FieldInfo(
"successDownloadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_GET_META_COUNT] = new StructBase.FieldInfo("totalGetMetaCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_GET_META_COUNT] = new StructBase.FieldInfo(
"totalGetMetaCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_GET_META_COUNT] = new StructBase.FieldInfo("successGetMetaCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_GET_META_COUNT] = new StructBase.FieldInfo(
"successGetMetaCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_CREATE_LINK_COUNT] = new StructBase.FieldInfo("totalCreateLinkCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_CREATE_LINK_COUNT] = new StructBase.FieldInfo(
"totalCreateLinkCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_CREATE_LINK_COUNT] = new StructBase.FieldInfo("successCreateLinkCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_CREATE_LINK_COUNT] = new StructBase.FieldInfo(
"successCreateLinkCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_DELETE_LINK_COUNT] = new StructBase.FieldInfo("totalDeleteLinkCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_DELETE_LINK_COUNT] = new StructBase.FieldInfo(
"totalDeleteLinkCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_DELETE_LINK_COUNT] = new StructBase.FieldInfo("successDeleteLinkCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_DELETE_LINK_COUNT] = new StructBase.FieldInfo(
"successDeleteLinkCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_UPLOAD_BYTES] = new StructBase.FieldInfo("totalUploadBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_UPLOAD_BYTES] = new StructBase.FieldInfo(
"totalUploadBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_UPLOAD_BYTES] = new StructBase.FieldInfo("successUploadBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_UPLOAD_BYTES] = new StructBase.FieldInfo(
"successUploadBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_APPEND_BYTES] = new StructBase.FieldInfo("totalAppendBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_APPEND_BYTES] = new StructBase.FieldInfo(
"totalAppendBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_APPEND_BYTES] = new StructBase.FieldInfo("successAppendBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_APPEND_BYTES] = new StructBase.FieldInfo(
"successAppendBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_MODIFY_BYTES] = new StructBase.FieldInfo("totalModifyBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_MODIFY_BYTES] = new StructBase.FieldInfo(
"totalModifyBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_MODIFY_BYTES] = new StructBase.FieldInfo("successModifyBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_MODIFY_BYTES] = new StructBase.FieldInfo(
"successModifyBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_DOWNLOAD_BYTES] = new StructBase.FieldInfo("totalDownloadloadBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_DOWNLOAD_BYTES] = new StructBase.FieldInfo(
"totalDownloadloadBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_DOWNLOAD_BYTES] = new StructBase.FieldInfo("successDownloadloadBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_DOWNLOAD_BYTES] = new StructBase.FieldInfo(
"successDownloadloadBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_SYNC_IN_BYTES] = new StructBase.FieldInfo("totalSyncInBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_SYNC_IN_BYTES] = new StructBase.FieldInfo(
"totalSyncInBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_SYNC_IN_BYTES] = new StructBase.FieldInfo("successSyncInBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_SYNC_IN_BYTES] = new StructBase.FieldInfo(
"successSyncInBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_SYNC_OUT_BYTES] = new StructBase.FieldInfo("totalSyncOutBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_SYNC_OUT_BYTES] = new StructBase.FieldInfo(
"totalSyncOutBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_SYNC_OUT_BYTES] = new StructBase.FieldInfo("successSyncOutBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_SYNC_OUT_BYTES] = new StructBase.FieldInfo(
"successSyncOutBytes", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_FILE_OPEN_COUNT] = new StructBase.FieldInfo("totalFileOpenCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_FILE_OPEN_COUNT] = new StructBase.FieldInfo(
"totalFileOpenCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_FILE_OPEN_COUNT] = new StructBase.FieldInfo("successFileOpenCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_FILE_OPEN_COUNT] = new StructBase.FieldInfo(
"successFileOpenCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_FILE_READ_COUNT] = new StructBase.FieldInfo("totalFileReadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_FILE_READ_COUNT] = new StructBase.FieldInfo(
"totalFileReadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_FILE_READ_COUNT] = new StructBase.FieldInfo("successFileReadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_FILE_READ_COUNT] = new StructBase.FieldInfo(
"successFileReadCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_FILE_WRITE_COUNT] = new StructBase.FieldInfo("totalFileWriteCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_TOTAL_FILE_WRITE_COUNT] = new StructBase.FieldInfo(
"totalFileWriteCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_FILE_WRITE_COUNT] = new StructBase.FieldInfo("successFileWriteCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_SUCCESS_FILE_WRITE_COUNT] = new StructBase.FieldInfo(
"successFileWriteCount", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_LAST_SOURCE_UPDATE] = new StructBase.FieldInfo("lastSourceUpdate", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_LAST_SOURCE_UPDATE] = new StructBase.FieldInfo(
"lastSourceUpdate", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_LAST_SYNC_UPDATE] = new StructBase.FieldInfo("lastSyncUpdate", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_LAST_SYNC_UPDATE] = new StructBase.FieldInfo(
"lastSyncUpdate", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_LAST_SYNCED_TIMESTAMP] = new StructBase.FieldInfo("lastSyncedTimestamp", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_LAST_SYNCED_TIMESTAMP] = new StructBase.FieldInfo(
"lastSyncedTimestamp", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_LAST_HEART_BEAT_TIME] = new StructBase.FieldInfo("lastHeartBeatTime", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_LAST_HEART_BEAT_TIME] = new StructBase.FieldInfo(
"lastHeartBeatTime", offset, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;
fieldsArray[FIELD_INDEX_IF_TRUNK_FILE] = new StructBase.FieldInfo("ifTrunkServer", offset, 1);
offset += 1;
fieldsArray[FIELD_INDEX_IF_TRUNK_FILE] = new StructBase.FieldInfo(
"ifTrunkServer", offset, 1);
offset += 1;
fieldsTotalSize = offset;
return offset;
}
protected byte status;
protected byte readWriteMode;
protected String id;
protected String ipAddr;
protected String srcIpAddr;
protected String domainName; //http domain name
protected String srcId;
protected String version;
protected long totalMB; //total disk storage in MB
protected long freeMB; //free disk storage in MB
protected long totalMB; //total disk space in MB
protected long freeMB; //free disk space in MB
protected long reservedMB; //reserved disk space in MB
protected int uploadPriority; //upload priority
protected Date joinTime; //storage join timestamp (create timestamp)
protected Date upTime; //storage service started timestamp
protected int storePathCount; //store base path count of each storage server
protected int subdirCountPerPath;
protected int storagePort;
protected int storageHttpPort; //storage http server port
protected int currentWritePath; //current write path index
protected int connectionAllocCount;
protected int connectionCurrentCount;
@@ -340,15 +402,6 @@ public class StructStorageStat extends StructBase {
protected Date lastHeartBeatTime;
protected boolean ifTrunkServer;
/**
* get fields total size
*
* @return fields total size
*/
public static int getFieldsTotalSize() {
return fieldsTotalSize;
}
/**
* get storage status
*
@@ -358,6 +411,15 @@ public class StructStorageStat extends StructBase {
return this.status;
}
/**
* get the read write mode
*
* @return the read write mode
*/
public byte getReadWriteMode() {
return this.readWriteMode;
}
/**
* get storage server id
*
@@ -377,21 +439,12 @@ public class StructStorageStat extends StructBase {
}
/**
* get source storage ip address
* get source storage id
*
* @return source storage ip address
* @return source storage id
*/
public String getSrcIpAddr() {
return this.srcIpAddr;
}
/**
* get the domain name of the storage server
*
* @return the domain name of the storage server
*/
public String getDomainName() {
return this.domainName;
public String getSrcId() {
return this.srcId;
}
/**
@@ -421,6 +474,15 @@ public class StructStorageStat extends StructBase {
return this.freeMB;
}
/**
* get reserved disk space in MB
*
* @return reserved disk space in MB
*/
public long getReservedMB() {
return this.reservedMB;
}
/**
* get storage server upload priority
*
@@ -475,15 +537,6 @@ public class StructStorageStat extends StructBase {
return this.storagePort;
}
/**
* get storage server HTTP port
*
* @return storage server HTTP port
*/
public int getStorageHttpPort() {
return this.storageHttpPort;
}
/**
* get current write path index
*
@@ -913,22 +966,22 @@ public class StructStorageStat extends StructBase {
* @param bs byte array
* @param offset start offset
*/
public void setFields(byte[] bs, int offset) {
protected void setFields(StructBase.FieldInfo[] fieldsArray, byte[] bs, int offset) {
this.status = byteValue(bs, offset, fieldsArray[FIELD_INDEX_STATUS]);
this.readWriteMode = byteValue(bs, offset, fieldsArray[FIELD_INDEX_RW_MODE]);
this.id = stringValue(bs, offset, fieldsArray[FIELD_INDEX_ID]);
this.ipAddr = stringValue(bs, offset, fieldsArray[FIELD_INDEX_IP_ADDR]);
this.srcIpAddr = stringValue(bs, offset, fieldsArray[FIELD_INDEX_SRC_IP_ADDR]);
this.domainName = stringValue(bs, offset, fieldsArray[FIELD_INDEX_DOMAIN_NAME]);
this.srcId = stringValue(bs, offset, fieldsArray[FIELD_INDEX_SRC_ID]);
this.version = stringValue(bs, offset, fieldsArray[FIELD_INDEX_VERSION]);
this.totalMB = longValue(bs, offset, fieldsArray[FIELD_INDEX_TOTAL_MB]);
this.freeMB = longValue(bs, offset, fieldsArray[FIELD_INDEX_FREE_MB]);
this.reservedMB = longValue(bs, offset, fieldsArray[FIELD_INDEX_RESERVED_MB]);
this.uploadPriority = intValue(bs, offset, fieldsArray[FIELD_INDEX_UPLOAD_PRIORITY]);
this.joinTime = dateValue(bs, offset, fieldsArray[FIELD_INDEX_JOIN_TIME]);
this.upTime = dateValue(bs, offset, fieldsArray[FIELD_INDEX_UP_TIME]);
this.storePathCount = intValue(bs, offset, fieldsArray[FIELD_INDEX_STORE_PATH_COUNT]);
this.subdirCountPerPath = intValue(bs, offset, fieldsArray[FIELD_INDEX_SUBDIR_COUNT_PER_PATH]);
this.storagePort = intValue(bs, offset, fieldsArray[FIELD_INDEX_STORAGE_PORT]);
this.storageHttpPort = intValue(bs, offset, fieldsArray[FIELD_INDEX_STORAGE_HTTP_PORT]);
this.currentWritePath = intValue(bs, offset, fieldsArray[FIELD_INDEX_CURRENT_WRITE_PATH]);
this.connectionAllocCount = int32Value(bs, offset, fieldsArray[FIELD_INDEX_CONNECTION_ALLOC_COUNT]);
@@ -979,4 +1032,7 @@ public class StructStorageStat extends StructBase {
this.lastHeartBeatTime = dateValue(bs, offset, fieldsArray[FIELD_INDEX_LAST_HEART_BEAT_TIME]);
this.ifTrunkServer = booleanValue(bs, offset, fieldsArray[FIELD_INDEX_IF_TRUNK_FILE]);
}
public void setFields(byte[] bs, int offset) {
}
}
File diff suppressed because it is too large Load Diff
@@ -10,7 +10,6 @@ package org.csource.fastdfs;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
/**
* Tracker server group
@@ -19,88 +18,83 @@ import java.net.Socket;
* @version Version 1.17
*/
public class TrackerGroup {
public int tracker_server_index;
public InetSocketAddress[] tracker_servers;
protected Integer lock;
public int tracker_server_index;
public InetSocketAddress[] tracker_servers;
protected Integer lock;
/**
* Constructor
*
* @param tracker_servers tracker servers
*/
public TrackerGroup(InetSocketAddress[] tracker_servers) {
this.tracker_servers = tracker_servers;
this.lock = new Integer(0);
this.tracker_server_index = 0;
}
/**
* return connected tracker server
*
* @return connected tracker server, null for fail
*/
public TrackerServer getConnection(int serverIndex) throws IOException {
Socket sock = new Socket();
sock.setReuseAddress(true);
sock.setSoTimeout(ClientGlobal.g_network_timeout);
sock.connect(this.tracker_servers[serverIndex], ClientGlobal.g_connect_timeout);
return new TrackerServer(sock, this.tracker_servers[serverIndex]);
}
/**
* return connected tracker server
*
* @return connected tracker server, null for fail
*/
public TrackerServer getConnection() throws IOException {
int current_index;
synchronized (this.lock) {
this.tracker_server_index++;
if (this.tracker_server_index >= this.tracker_servers.length) {
/**
* Constructor
*
* @param tracker_servers tracker servers
*/
public TrackerGroup(InetSocketAddress[] tracker_servers) {
this.tracker_servers = tracker_servers;
this.lock = new Integer(0);
this.tracker_server_index = 0;
}
current_index = this.tracker_server_index;
}
try {
return this.getConnection(current_index);
} catch (IOException ex) {
System.err.println("connect to server " + this.tracker_servers[current_index].getAddress().getHostAddress() + ":" + this.tracker_servers[current_index].getPort() + " fail");
ex.printStackTrace(System.err);
/**
* return connected tracker server
*
* @return connected tracker server, null for fail
*/
public TrackerServer getTrackerServer(int serverIndex) throws IOException {
return new TrackerServer(this.tracker_servers[serverIndex], serverIndex);
}
for (int i = 0; i < this.tracker_servers.length; i++) {
if (i == current_index) {
continue;
}
try {
TrackerServer trackerServer = this.getConnection(i);
/**
* return connected tracker server
*
* @return connected tracker server, null for fail
*/
public TrackerServer getTrackerServer() throws IOException {
int current_index;
synchronized (this.lock) {
if (this.tracker_server_index == current_index) {
this.tracker_server_index = i;
}
this.tracker_server_index++;
if (this.tracker_server_index >= this.tracker_servers.length) {
this.tracker_server_index = 0;
}
current_index = this.tracker_server_index;
}
return trackerServer;
} catch (IOException ex) {
System.err.println("connect to server " + this.tracker_servers[i].getAddress().getHostAddress() + ":" + this.tracker_servers[i].getPort() + " fail");
ex.printStackTrace(System.err);
}
try {
return this.getTrackerServer(current_index);
} catch (IOException ex) {
System.err.println("connect to server " + this.tracker_servers[current_index].getAddress().getHostAddress() + ":" + this.tracker_servers[current_index].getPort() + " fail");
ex.printStackTrace(System.err);
}
for (int i = 0; i < this.tracker_servers.length; i++) {
if (i == current_index) {
continue;
}
try {
TrackerServer trackerServer = this.getTrackerServer(i);
synchronized (this.lock) {
if (this.tracker_server_index == current_index) {
this.tracker_server_index = i;
}
}
return trackerServer;
} catch (IOException ex) {
System.err.println("connect to server " + this.tracker_servers[i].getAddress().getHostAddress() + ":" + this.tracker_servers[i].getPort() + " fail");
ex.printStackTrace(System.err);
}
}
return null;
}
return null;
}
public Object clone() {
InetSocketAddress[] trackerServers = new InetSocketAddress[this.tracker_servers.length];
for (int i = 0; i < trackerServers.length; i++) {
trackerServers[i] = new InetSocketAddress(this.tracker_servers[i].getAddress().getHostAddress(), this.tracker_servers[i].getPort());
}
public Object clone() {
InetSocketAddress[] trackerServers = new InetSocketAddress[this.tracker_servers.length];
for (int i = 0; i < trackerServers.length; i++) {
trackerServers[i] = new InetSocketAddress(this.tracker_servers[i].getAddress().getHostAddress(), this.tracker_servers[i].getPort());
return new TrackerGroup(trackerServers);
}
return new TrackerGroup(trackerServers);
}
}
@@ -8,11 +8,13 @@
package org.csource.fastdfs;
import org.csource.common.MyException;
import org.csource.fastdfs.pool.Connection;
import org.csource.fastdfs.pool.ConnectionPool;
import org.csource.fastdfs.pool.ConnectionFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
/**
* Tracker Server Info
@@ -21,93 +23,48 @@ import java.net.Socket;
* @version Version 1.11
*/
public class TrackerServer {
protected Socket sock;
protected InetSocketAddress inetSockAddr;
protected InetSocketAddress inetSockAddr;
/**
* Constructor
*
* @param sock Socket of server
* @param inetSockAddr the server info
*/
public TrackerServer(Socket sock, InetSocketAddress inetSockAddr) {
this.sock = sock;
this.inetSockAddr = inetSockAddr;
}
protected int index;
/**
* get the connected socket
*
* @return the socket
*/
public Socket getSocket() throws IOException {
if (this.sock == null) {
this.sock = ClientGlobal.getSocket(this.inetSockAddr);
public TrackerServer(InetSocketAddress inetSockAddr) throws IOException {
this.inetSockAddr = inetSockAddr;
}
return this.sock;
}
/**
* get the server info
*
* @return the server info
*/
public InetSocketAddress getInetSocketAddress() {
return this.inetSockAddr;
}
public OutputStream getOutputStream() throws IOException {
return this.sock.getOutputStream();
}
public InputStream getInputStream() throws IOException {
return this.sock.getInputStream();
}
public void close() throws IOException {
if (this.sock != null) {
try {
ProtoCommon.closeSocket(this.sock);
} finally {
this.sock = null;
}
public TrackerServer(InetSocketAddress inetSockAddr, int index) {
this.inetSockAddr = inetSockAddr;
this.index = index;
}
}
protected void finalize() throws Throwable {
this.close();
}
public boolean isConnected(){
boolean isConnected = false;
if (sock != null) {
if (sock.isConnected()) {
isConnected = true;
}
protected Connection getConnection(InetSocketAddress sockAddr) throws MyException, IOException {
Connection connection;
if (ClientGlobal.g_connection_pool_enabled) {
connection = ConnectionPool.getConnection(sockAddr);
} else {
connection = ConnectionFactory.create(sockAddr);
}
return connection;
}
return isConnected;
}
public boolean isAvaliable() {
if (isConnected()) {
if (sock.getPort() == 0) {
return false;
}
if (sock.getInetAddress() == null) {
return false;
}
if (sock.getRemoteSocketAddress() == null) {
return false;
}
if (sock.isInputShutdown()) {
return false;
}
if (sock.isOutputShutdown()) {
return false;
}
return true;
public Connection getConnection() throws MyException, IOException {
return this.getConnection(this.inetSockAddr);
}
/**
* get the server info
*
* @return the server info
*/
public InetSocketAddress getInetSocketAddress() {
return this.inetSockAddr;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
return false;
}
}
@@ -0,0 +1,144 @@
package org.csource.fastdfs.pool;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.ProtoCommon;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
public class Connection {
private Socket sock;
private InetSocketAddress inetSockAddr;
private Long lastAccessTime = System.currentTimeMillis();
private boolean needActiveTest = false;
public Connection(Socket sock, InetSocketAddress inetSockAddr) {
this.sock = sock;
this.inetSockAddr = inetSockAddr;
}
/**
* get the server info
*
* @return the server info
*/
public InetSocketAddress getInetSocketAddress() {
return this.inetSockAddr;
}
public OutputStream getOutputStream() throws IOException {
return this.sock.getOutputStream();
}
public InputStream getInputStream() throws IOException {
return this.sock.getInputStream();
}
public Long getLastAccessTime() {
return lastAccessTime;
}
public void setLastAccessTime(Long lastAccessTime) {
this.lastAccessTime = lastAccessTime;
}
/**
*
* @throws IOException
*/
public void close() throws IOException {
//if connection enabled get from connection pool
if (ClientGlobal.g_connection_pool_enabled) {
ConnectionPool.closeConnection(this);
} else {
this.closeDirectly();
}
}
public void release() throws IOException {
if (ClientGlobal.g_connection_pool_enabled) {
ConnectionPool.releaseConnection(this);
} else {
this.closeDirectly();
}
}
/**
* force close socket,
*/
public void closeDirectly() throws IOException {
if (this.sock != null) {
try {
ProtoCommon.closeSocket(this.sock);
} finally {
this.sock = null;
}
}
}
public boolean activeTest() throws IOException {
if (this.sock == null) {
return false;
}
return ProtoCommon.activeTest(this.sock);
}
public boolean isConnected() {
boolean isConnected = false;
if (sock != null) {
if (sock.isConnected()) {
isConnected = true;
}
}
return isConnected;
}
public boolean isAvaliable() {
if (isConnected()) {
if (sock.getPort() == 0) {
return false;
}
if (sock.getInetAddress() == null) {
return false;
}
if (sock.getRemoteSocketAddress() == null) {
return false;
}
if (sock.isInputShutdown()) {
return false;
}
if (sock.isOutputShutdown()) {
return false;
}
return true;
}
return false;
}
public boolean isClosed() {
return this.sock == null;
}
public boolean isNeedActiveTest() {
return needActiveTest;
}
public void setNeedActiveTest(boolean needActiveTest) {
this.needActiveTest = needActiveTest;
}
@Override
public String toString() {
return "Connection{" +
"sock=" + sock +
", inetSockAddr=" + inetSockAddr +
", lastAccessTime=" + lastAccessTime +
", needActiveTest=" + needActiveTest +
'}';
}
}
@@ -0,0 +1,30 @@
package org.csource.fastdfs.pool;
import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
public class ConnectionFactory {
/**
* create from InetSocketAddress
*
* @param socketAddress
* @return
* @throws IOException
*/
public static Connection create(InetSocketAddress socketAddress) throws MyException {
try {
Socket sock = new Socket();
sock.setReuseAddress(true);
sock.setSoTimeout(ClientGlobal.g_network_timeout);
sock.connect(socketAddress, ClientGlobal.g_connect_timeout);
return new Connection(sock, socketAddress);
} catch (Exception e) {
throw new MyException("connect to server " + socketAddress.getAddress().getHostAddress()
+ ":" + socketAddress.getPort() + " fail, emsg: " + e.getMessage());
}
}
}
@@ -0,0 +1,155 @@
package org.csource.fastdfs.pool;
import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
public class ConnectionManager {
private InetSocketAddress inetSocketAddress;
/**
* total create connection pool
*/
private AtomicInteger totalCount = new AtomicInteger();
/**
* lock
*/
private ReentrantLock lock = new ReentrantLock(true);
private Condition condition = lock.newCondition();
/**
* free connections
*/
private LinkedList<Connection> freeConnections = new LinkedList<Connection>();
private ConnectionManager() {
}
public ConnectionManager(InetSocketAddress socketAddress) {
this.inetSocketAddress = socketAddress;
}
public Connection getConnection() throws MyException {
lock.lock();
try {
Connection connection = null;
while (true) {
connection = freeConnections.poll();
if (connection != null) {
if (!connection.isAvaliable() || (System.currentTimeMillis() - connection.getLastAccessTime()) >
ClientGlobal.g_connection_pool_max_idle_time)
{
closeConnection(connection);
continue;
}
if (connection.isNeedActiveTest()) {
boolean isActive = false;
try {
isActive = connection.activeTest();
} catch (IOException e) {
System.err.println("send to server " + inetSocketAddress.getAddress().getHostAddress()
+ ":" + inetSocketAddress.getPort() + " active test error, emsg: " + e.getMessage());
isActive = false;
}
if (!isActive) {
closeConnection(connection);
continue;
} else {
connection.setNeedActiveTest(false);
}
}
} else if (ClientGlobal.g_connection_pool_max_count_per_entry == 0 ||
totalCount.get() < ClientGlobal.g_connection_pool_max_count_per_entry)
{
connection = ConnectionFactory.create(this.inetSocketAddress);
totalCount.incrementAndGet();
} else {
try {
if (condition.await(ClientGlobal.g_connection_pool_max_wait_time_in_ms, TimeUnit.MILLISECONDS)) {
//wait single success
continue;
}
throw new MyException("connections reach max_count_per_entry: "
+ ClientGlobal.g_connection_pool_max_count_per_entry + ", "
+ "await connection for server " + inetSocketAddress.getAddress().getHostAddress()
+ ":" + inetSocketAddress.getPort() + " timeout, wait_time > "
+ ClientGlobal.g_connection_pool_max_wait_time_in_ms + " ms");
} catch (InterruptedException e) {
e.printStackTrace();
throw new MyException("connection full, await connection for server "
+ inetSocketAddress.getAddress().getHostAddress()
+ ":" + inetSocketAddress.getPort() + " fail, emsg: " + e.getMessage());
}
}
return connection;
}
} finally {
lock.unlock();
}
}
public void releaseConnection(Connection connection) {
if (connection == null) {
return;
}
lock.lock();
try {
connection.setLastAccessTime(System.currentTimeMillis());
freeConnections.add(connection);
condition.signal();
} finally {
lock.unlock();
}
}
public void closeConnection(Connection connection) {
if (connection == null) {
return;
}
try {
if (!connection.isClosed()) {
totalCount.decrementAndGet();
connection.closeDirectly();
}
} catch (IOException e) {
e.printStackTrace();
System.err.println("close socket[" + inetSocketAddress.getAddress().getHostAddress()
+ ":" + inetSocketAddress.getPort() + "] error, emsg: " + e.getMessage());
}
}
public void setActiveTestFlag() {
lock.lock();
try {
for (Connection freeConnection : freeConnections) {
freeConnection.setNeedActiveTest(true);
}
} finally {
lock.unlock();
}
}
@Override
public String toString() {
return "ConnectionManager{" +
"ip:port='" + inetSocketAddress.getAddress().getHostAddress() + ":" + inetSocketAddress.getPort() +
", totalCount=" + totalCount +
", freeCount=" + freeConnections.size() +
", freeConnections =" + freeConnections +
'}';
}
}
@@ -0,0 +1,80 @@
package org.csource.fastdfs.pool;
import org.csource.common.MyException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ConnectionPool {
/**
* key is ip:port, value is ConnectionManager
*/
private final static ConcurrentHashMap<String, ConnectionManager> CP = new ConcurrentHashMap<String, ConnectionManager>();
public static Connection getConnection(InetSocketAddress socketAddress) throws MyException {
if (socketAddress == null) {
return null;
}
String key = getKey(socketAddress);
ConnectionManager connectionManager;
connectionManager = CP.get(key);
if (connectionManager == null) {
synchronized (ConnectionPool.class) {
connectionManager = CP.get(key);
if (connectionManager == null) {
connectionManager = new ConnectionManager(socketAddress);
CP.put(key, connectionManager);
}
}
}
return connectionManager.getConnection();
}
public static void releaseConnection(Connection connection) throws IOException {
if (connection == null) {
return;
}
String key = getKey(connection.getInetSocketAddress());
ConnectionManager connectionManager = CP.get(key);
if (connectionManager != null) {
connectionManager.releaseConnection(connection);
} else {
connection.closeDirectly();
}
}
public static void closeConnection(Connection connection) throws IOException {
if (connection == null) {
return;
}
String key = getKey(connection.getInetSocketAddress());
ConnectionManager connectionManager = CP.get(key);
if (connectionManager != null) {
connectionManager.closeConnection(connection);
connectionManager.setActiveTestFlag();
} else {
connection.closeDirectly();
}
}
private static String getKey(InetSocketAddress socketAddress) {
if (socketAddress == null) {
return null;
}
return String.format("%s-%s", socketAddress.getAddress().getHostAddress(), socketAddress.getPort());
}
@Override
public String toString() {
if (!CP.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (Map.Entry<String, ConnectionManager> managerEntry : CP.entrySet()) {
builder.append("key:[" + managerEntry.getKey() + " ]-------- entry:" + managerEntry.getValue() + "\n");
}
return builder.toString();
}
return null;
}
}
@@ -9,5 +9,34 @@ fastdfs.http_anti_steal_token = false
fastdfs.http_secret_key = FastDFS1234567890
fastdfs.http_tracker_http_port = 80
fastdfs.tracker_servers = 10.0.11.201:22122,10.0.11.202:22122,10.0.11.203:22122
#tracker_server
# IPv4:
# for example: 192.168.2.100:22122,122.244.141.46:22122
#
# IPv6:
# for example: [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e]:22122
#
fastdfs.tracker_servers = 185.245.40.70:22122
# connect which ip address first for multi IPs of a storage server, value list:
## tracker: connect to the ip address return by tracker server first
## last-connected: connect to the ip address last connected first
# default value is tracker
fastdfs.connect_first_by = tracker
## Whether to open the connection pool, if not, create a new connection every time
fastdfs.connection_pool.enabled = true
## max_count_per_entry: max connection count per host:port , 0 is not limit
fastdfs.connection_pool.max_count_per_entry = 500
## connections whose the idle time exceeds this time will be closed, unit: second, default value is 3600
fastdfs.connection_pool.max_idle_time = 3600
## Maximum waiting time when the maximum number of connections is reached, unit: millisecond, default value is 1000
fastdfs.connection_pool.max_wait_time_in_ms = 1000
## set to false when FastDFS server version <= V6.10
fastdfs.fetch_storage_ids.have_allow_empty_field = true
@@ -5,5 +5,28 @@ http.tracker_http_port = 8080
http.anti_steal_token = no
http.secret_key = FastDFS1234567890
#tracker_server
# IPv4:
# for example: 192.168.2.100,122.244.141.46:22122
#
# IPv6:
# for example: [2409:8a20:42d:2f40:587a:4c47:72c0:ad8e]:22122
#
tracker_server = 10.0.11.243:22122
tracker_server = 10.0.11.244:22122
# connect which ip address first for multi IPs of a storage server, value list:
## tracker: connect to the ip address return by tracker server first
## last-connected: connect to the ip address last connected first
# default value is tracker
connect_first_by = tracker
connection_pool.enabled = true
connection_pool.max_count_per_entry = 500
connection_pool.max_idle_time = 3600
connection_pool.max_wait_time_in_ms = 1000
# set to false when FastDFS server version <= V6.10
fetch_storage_ids.have_allow_empty_field = true
@@ -21,6 +21,9 @@ public class ClientGlobalTests {
ClientGlobal.initByProperties(props);
System.out.println("ClientGlobal.configInfo(): " + ClientGlobal.configInfo());
String trackerServer = "www.baidu.com:22122";
ClientGlobal.initByTrackers(trackerServer);
System.out.println("Host >>> ClientGlobal.configInfo() : " + ClientGlobal.configInfo());
}
}
@@ -31,7 +31,7 @@ public class FdfsTest {
LOGGER.info("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
LOGGER.info("charset=" + ClientGlobal.g_charset);
TrackerClient tracker = new TrackerClient();
trackerServer = tracker.getConnection();
trackerServer = tracker.getTrackerServer();
StorageServer storageServer = null;
storageClient = new StorageClient(trackerServer, storageServer);
}
@@ -87,9 +87,9 @@ public class FdfsTest {
@Test
public void download() throws Exception {
String[] uploadresult = {"group1", "M00/00/00/wKgBZV0phl2ASV1nAACk1tFxwrM3814331"};
String[] uploadresult = {"group1", "M00/00/00/J2fL12PVypeAWiGcAAM_gDeWVyw5817085"};
byte[] result = storageClient.download_file(uploadresult[0], uploadresult[1]);
String local_filename = "build.PNG";
String local_filename = "commitment.d2f57e10.jpg";
writeByteToFile(result, local_filename);
File file = new File(local_filename);
Assert.assertTrue(file.isFile());
@@ -98,17 +98,17 @@ public class FdfsTest {
@Test
public void testUploadDownload() throws Exception {
NameValuePair[] metaList = new NameValuePair[1];
String local_filename = "build.PNG";
String local_filename = "commitment.d2f57e10 (2).jpg";
metaList[0] = new NameValuePair("fileName", local_filename);
File file = new File("C:/Users/chengdu/Desktop/build.PNG");
File file = new File("/Users/iyw/Downloads/commitment.d2f57e10 (2).jpg");
InputStream inputStream = new FileInputStream(file);
int length = inputStream.available();
byte[] bytes = new byte[length];
inputStream.read(bytes);
String[] result = storageClient.upload_file(bytes, null, metaList);
Assert.assertTrue(storageClient.isConnected());
//Assert.assertTrue(storageClient.isConnected());
// pool testOnborrow isAvaliable
Assert.assertTrue(storageClient.isAvaliable());
// Assert.assertTrue(storageClient.isAvaliable());
LOGGER.info("result {}", Arrays.asList(result));
byte[] resultbytes = storageClient.download_file(result[0], result[1]);
writeByteToFile(resultbytes, local_filename);
+39 -14
View File
@@ -8,20 +8,34 @@
package org.csource.fastdfs;
import org.csource.fastdfs.*;
import java.text.SimpleDateFormat;
/**
* load test class
*
* @author Happy Fish / YuQing
* @version Version 1.20
* @version Version 1.34
*/
public class Monitor {
private Monitor() {
}
public static String getReadWriteModeCaption(byte readWriteMode) {
switch (readWriteMode) {
case ProtoCommon.FDFS_RW_MODE_NONE:
return "none (disabled)";
case ProtoCommon.FDFS_RW_MODE_READONLY:
return "readonly";
case ProtoCommon.FDFS_RW_MODE_WRITEONLY:
return "writeonly";
case ProtoCommon.FDFS_RW_MODE_BOTH:
return "both (normal)";
default:
return "unkown";
}
}
/**
* entry point
*
@@ -48,7 +62,7 @@ public class Monitor {
System.out.println("delete storage errno: " + tracker.getErrorCode());
*/
TrackerServer trackerServer = tracker.getConnection();
TrackerServer trackerServer = tracker.getTrackerServer();
if (trackerServer == null) {
return;
}
@@ -66,16 +80,23 @@ public class Monitor {
count = 0;
for (StructGroupStat groupStat : groupStats) {
long available_mb;
available_mb = groupStat.getFreeMB() - groupStat.getReservedMB();
if (available_mb < 0) {
available_mb = 0;
}
count++;
System.out.println("Group " + count + ":");
System.out.println("group name = " + groupStat.getGroupName());
System.out.println("disk total space = " + groupStat.getTotalMB() + "MB");
System.out.println("disk free space = " + groupStat.getFreeMB() + " MB");
System.out.println("disk reserved space = " + groupStat.getReservedMB() + " MB");
System.out.println("disk availale space = " + available_mb + " MB");
System.out.println("trunk free space = " + groupStat.getTrunkFreeMB() + " MB");
System.out.println("storage server count = " + groupStat.getStorageCount());
System.out.println("active server count = " + groupStat.getActiveCount());
System.out.println("readable server count = " + groupStat.getReadableServerCount());
System.out.println("writable server count = " + groupStat.getWritableServerCount());
System.out.println("storage server port = " + groupStat.getStoragePort());
System.out.println("storage HTTP port = " + groupStat.getStorageHttpPort());
System.out.println("store path count = " + groupStat.getStorePathCount());
System.out.println("subdir count per path = " + groupStat.getSubdirCountPerPath());
System.out.println("current write server index = " + groupStat.getCurrentWriteServer());
@@ -92,23 +113,29 @@ public class Monitor {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int stroageCount = 0;
for (StructStorageStat storageStat : storageStats) {
available_mb = storageStat.getFreeMB() - storageStat.getReservedMB();
if (available_mb < 0) {
available_mb = 0;
}
stroageCount++;
System.out.println("\tStorage " + stroageCount + ":");
System.out.println("\t\tstorage id = " + storageStat.getId());
System.out.println("\t\tip_addr = " + storageStat.getIpAddr() + " " + ProtoCommon.getStorageStatusCaption(storageStat.getStatus()));
System.out.println("\t\thttp domain = " + storageStat.getDomainName());
System.out.println("\t\tip_addr = " + storageStat.getIpAddr() + " " +
ProtoCommon.getStorageStatusCaption(storageStat.getStatus()));
System.out.println("\t\tread write mode = " + getReadWriteModeCaption(storageStat.getReadWriteMode()));
System.out.println("\t\tversion = " + storageStat.getVersion());
System.out.println("\t\tjoin time = " + df.format(storageStat.getJoinTime()));
System.out.println("\t\tup time = " + (storageStat.getUpTime().getTime() == 0 ? "" : df.format(storageStat.getUpTime())));
System.out.println("\t\ttotal storage = " + storageStat.getTotalMB() + "MB");
System.out.println("\t\tfree storage = " + storageStat.getFreeMB() + "MB");
System.out.println("\t\tdisk total space = " + storageStat.getTotalMB() + "MB");
System.out.println("\t\tdisk free space = " + storageStat.getFreeMB() + "MB");
System.out.println("\t\tdisk reserved space = " + storageStat.getReservedMB() + " MB");
System.out.println("\t\tdisk availale space = " + available_mb + " MB");
System.out.println("\t\tupload priority = " + storageStat.getUploadPriority());
System.out.println("\t\tstore_path_count = " + storageStat.getStorePathCount());
System.out.println("\t\tsubdir_count_per_path = " + storageStat.getSubdirCountPerPath());
System.out.println("\t\tstorage_port = " + storageStat.getStoragePort());
System.out.println("\t\tstorage_http_port = " + storageStat.getStorageHttpPort());
System.out.println("\t\tcurrent_write_path = " + storageStat.getCurrentWritePath());
System.out.println("\t\tsource ip_addr = " + storageStat.getSrcIpAddr());
System.out.println("\t\tsource ip_id = " + storageStat.getSrcId());
System.out.println("\t\tif_trunk_server = " + storageStat.isTrunkServer());
System.out.println("\t\tconntion.alloc_count = " + storageStat.getConnectionAllocCount());
System.out.println("\t\tconntion.current_count = " + storageStat.getConnectionCurrentCount());
@@ -157,8 +184,6 @@ public class Monitor {
System.out.println("\t\tlast_synced_timestamp = " + df.format(storageStat.getLastSyncedTimestamp()) + getSyncedDelayString(storageStats, storageStat));
}
}
trackerServer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
+1 -4
View File
@@ -9,7 +9,6 @@
package org.csource.fastdfs;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
/**
* client test
@@ -46,7 +45,7 @@ public class Test {
System.out.println("charset=" + ClientGlobal.g_charset);
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
TrackerServer trackerServer = tracker.getTrackerServer();
StorageServer storageServer = null;
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
@@ -60,8 +59,6 @@ public class Test {
byte[] result = client.download_file1(fileId);
System.out.println(i + ", download result is: " + result.length);
}
trackerServer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
+3 -4
View File
@@ -1,7 +1,6 @@
package org.csource.fastdfs;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import java.net.InetSocketAddress;
@@ -36,12 +35,12 @@ public class Test1 {
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
System.out.println("charset=" + ClientGlobal.g_charset);
TrackerGroup tg = new TrackerGroup(new InetSocketAddress[]{new InetSocketAddress("47.95.221.159", 22122)});
TrackerGroup tg = new TrackerGroup(new InetSocketAddress[]{new InetSocketAddress("192.168.3.202", 22122)});
TrackerClient tc = new TrackerClient(tg);
TrackerServer ts = tc.getConnection();
TrackerServer ts = tc.getTrackerServer();
if (ts == null) {
System.out.println("getConnection return null");
System.out.println("getTrackerServer return null");
return;
}
@@ -9,7 +9,6 @@
package org.csource.fastdfs;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import java.io.File;
import java.net.InetSocketAddress;
@@ -53,7 +52,7 @@ public class TestAppender {
String remote_filename;
ServerInfo[] servers;
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
TrackerServer trackerServer = tracker.getTrackerServer();
StorageServer storageServer = null;
@@ -298,14 +297,10 @@ public class TestAppender {
return;
}
/* for test only */
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
storageServer.close();
System.out.println("active test to storage server: " + storageServer.getConnection().activeTest());
/* for test only */
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
trackerServer.close();
System.out.println("active test to tracker server: " + trackerServer.getConnection().activeTest());
} catch (Exception ex) {
ex.printStackTrace();
}
@@ -9,7 +9,6 @@
package org.csource.fastdfs;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import java.io.File;
import java.net.InetSocketAddress;
@@ -21,39 +20,39 @@ import java.net.InetSocketAddress;
* @version Version 1.20
*/
public class TestAppender1 {
private TestAppender1() {
}
/**
* entry point
*
* @param args comand arguments
* <ul><li>args[0]: config filename</li></ul>
* <ul><li>args[1]: local filename to upload</li></ul>
*/
public static void main(String args[]) {
if (args.length < 2) {
System.out.println("Error: Must have 2 parameters, one is config filename, "
+ "the other is the local filename to upload");
return;
private TestAppender1() {
}
System.out.println("java.version=" + System.getProperty("java.version"));
/**
* entry point
*
* @param args comand arguments
* <ul><li>args[0]: config filename</li></ul>
* <ul><li>args[1]: local filename to upload</li></ul>
*/
public static void main(String args[]) {
if (args.length < 2) {
System.out.println("Error: Must have 2 parameters, one is config filename, "
+ "the other is the local filename to upload");
return;
}
String conf_filename = args[0];
String local_filename = args[1];
System.out.println("java.version=" + System.getProperty("java.version"));
try {
ClientGlobal.init(conf_filename);
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
System.out.println("charset=" + ClientGlobal.g_charset);
String conf_filename = args[0];
String local_filename = args[1];
long startTime;
ServerInfo[] servers;
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
try {
ClientGlobal.init(conf_filename);
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
System.out.println("charset=" + ClientGlobal.g_charset);
StorageServer storageServer = null;
long startTime;
ServerInfo[] servers;
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getTrackerServer();
StorageServer storageServer = null;
/*
storageServer = tracker.getStoreStorage(trackerServer);
@@ -64,229 +63,226 @@ public class TestAppender1 {
}
*/
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
byte[] file_buff;
NameValuePair[] meta_list;
String group_name;
String appender_file_id;
String file_ext_name;
int errno;
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
byte[] file_buff;
NameValuePair[] meta_list;
String group_name;
String appender_file_id;
String file_ext_name;
int errno;
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "800");
meta_list[1] = new NameValuePair("heigth", "600");
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
meta_list[3] = new NameValuePair("author", "Mike");
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "800");
meta_list[1] = new NameValuePair("heigth", "600");
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
meta_list[3] = new NameValuePair("author", "Mike");
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
System.out.println("file length: " + file_buff.length);
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
System.out.println("file length: " + file_buff.length);
group_name = null;
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
if (storageServers == null) {
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("store storage servers count: " + storageServers.length);
for (int k = 0; k < storageServers.length; k++) {
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
}
System.err.println("");
}
group_name = null;
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
if (storageServers == null) {
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("store storage servers count: " + storageServers.length);
for (int k = 0; k < storageServers.length; k++) {
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
}
System.err.println("");
}
startTime = System.currentTimeMillis();
appender_file_id = client.upload_appender_file1(file_buff, "txt", meta_list);
System.out.println("upload_appender_file1 time used: " + (System.currentTimeMillis() - startTime) + " ms");
startTime = System.currentTimeMillis();
appender_file_id = client.upload_appender_file1(file_buff, "txt", meta_list);
System.out.println("upload_appender_file1 time used: " + (System.currentTimeMillis() - startTime) + " ms");
/*
group_name = "";
appender_file_id = client.upload_appender_file1(group_name, file_buff, "txt", meta_list);
*/
if (appender_file_id == null) {
System.err.println("upload file fail, error code: " + client.getErrorCode());
return;
} else {
System.err.println(client.get_file_info1(appender_file_id));
if (appender_file_id == null) {
System.err.println("upload file fail, error code: " + client.getErrorCode());
return;
} else {
System.err.println(client.get_file_info1(appender_file_id));
servers = tracker.getFetchStorages1(trackerServer, appender_file_id);
if (servers == null) {
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("storage servers count: " + servers.length);
for (int k = 0; k < servers.length; k++) {
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
}
System.err.println("");
servers = tracker.getFetchStorages1(trackerServer, appender_file_id);
if (servers == null) {
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("storage servers count: " + servers.length);
for (int k = 0; k < servers.length; k++) {
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
}
System.err.println("");
}
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "1024");
meta_list[1] = new NameValuePair("heigth", "768");
meta_list[2] = new NameValuePair("bgcolor", "#000000");
meta_list[3] = new NameValuePair("title", "Untitle");
startTime = System.currentTimeMillis();
errno = client.set_metadata1(appender_file_id, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE);
System.out.println("set_metadata time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println("set_metadata success");
} else {
System.err.println("set_metadata fail, error no: " + errno);
}
meta_list = client.get_metadata1(appender_file_id);
if (meta_list != null) {
for (int i = 0; i < meta_list.length; i++) {
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
}
}
startTime = System.currentTimeMillis();
file_buff = client.download_file1(appender_file_id);
System.out.println("download_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (file_buff != null) {
System.out.println("file length:" + file_buff.length);
System.out.println((new String(file_buff)));
}
file_buff = "this is a slave buff".getBytes(ClientGlobal.g_charset);
file_ext_name = "txt";
startTime = System.currentTimeMillis();
errno = client.append_file1(appender_file_id, file_buff);
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("append file fail, error no: " + errno);
}
startTime = System.currentTimeMillis();
String new_file_id = client.regenerate_appender_filename1(appender_file_id);
System.out.println("regenerate_appender_filename time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
appender_file_id = new_file_id;
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("regenerate_appender_filename fail, error no: " + errno);
}
startTime = System.currentTimeMillis();
errno = client.delete_file1(appender_file_id);
System.out.println("delete_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println("Delete file success");
} else {
System.err.println("Delete file fail, error no: " + errno);
}
}
appender_file_id = client.upload_appender_file1(local_filename, null, meta_list);
if (appender_file_id != null) {
int ts;
String token;
String file_url;
InetSocketAddress inetSockAddr;
inetSockAddr = trackerServer.getInetSocketAddress();
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
if (ClientGlobal.g_tracker_http_port != 80) {
file_url += ":" + ClientGlobal.g_tracker_http_port;
}
file_url += "/" + appender_file_id;
if (ClientGlobal.g_anti_steal_token) {
ts = (int) (System.currentTimeMillis() / 1000);
token = ProtoCommon.getToken(appender_file_id, ts, ClientGlobal.g_secret_key);
file_url += "?token=" + token + "&ts=" + ts;
}
System.err.println(client.get_file_info1(appender_file_id));
System.err.println("file url: " + file_url);
errno = client.download_file1(appender_file_id, 0, 0, "c:\\" + appender_file_id.replaceAll("/", "_"));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
errno = client.download_file1(appender_file_id, 0, 0, new DownloadFileWriter("c:\\" + appender_file_id.replaceAll("/", "-")));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
file_ext_name = null;
startTime = System.currentTimeMillis();
errno = client.append_file1(appender_file_id, local_filename);
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("append file fail, error no: " + errno);
}
}
File f;
f = new File(local_filename);
int nPos = local_filename.lastIndexOf('.');
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
file_ext_name = local_filename.substring(nPos + 1);
} else {
file_ext_name = null;
}
appender_file_id = client.upload_appender_file1(null, f.length(),
new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
if (appender_file_id != null) {
System.out.println(client.get_file_info1(appender_file_id));
startTime = System.currentTimeMillis();
errno = client.append_file1(appender_file_id, f.length(), new UploadLocalFileSender(local_filename));
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("append file fail, error no: " + errno);
}
startTime = System.currentTimeMillis();
errno = client.modify_file1(appender_file_id, 0, f.length(), new UploadLocalFileSender(local_filename));
System.out.println("modify_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("modify file fail, error no: " + errno);
}
startTime = System.currentTimeMillis();
errno = client.truncate_file1(appender_file_id, 0);
System.out.println("truncate_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("truncate file fail, error no: " + errno);
}
} else {
System.err.println("Upload file fail, error no: " + errno);
}
storageServer = tracker.getFetchStorage1(trackerServer, appender_file_id);
if (storageServer == null) {
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
return;
}
/* for test only */
System.out.println("active test to storage server: " + storageServer.getConnection().activeTest());
/* for test only */
System.out.println("active test to tracker server: " + trackerServer.getConnection().activeTest());
} catch (Exception ex) {
ex.printStackTrace();
}
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "1024");
meta_list[1] = new NameValuePair("heigth", "768");
meta_list[2] = new NameValuePair("bgcolor", "#000000");
meta_list[3] = new NameValuePair("title", "Untitle");
startTime = System.currentTimeMillis();
errno = client.set_metadata1(appender_file_id, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE);
System.out.println("set_metadata time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println("set_metadata success");
} else {
System.err.println("set_metadata fail, error no: " + errno);
}
meta_list = client.get_metadata1(appender_file_id);
if (meta_list != null) {
for (int i = 0; i < meta_list.length; i++) {
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
}
}
startTime = System.currentTimeMillis();
file_buff = client.download_file1(appender_file_id);
System.out.println("download_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (file_buff != null) {
System.out.println("file length:" + file_buff.length);
System.out.println((new String(file_buff)));
}
file_buff = "this is a slave buff".getBytes(ClientGlobal.g_charset);
file_ext_name = "txt";
startTime = System.currentTimeMillis();
errno = client.append_file1(appender_file_id, file_buff);
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("append file fail, error no: " + errno);
}
startTime = System.currentTimeMillis();
String new_file_id = client.regenerate_appender_filename1(appender_file_id);
System.out.println("regenerate_appender_filename time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
appender_file_id = new_file_id;
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("regenerate_appender_filename fail, error no: " + errno);
}
startTime = System.currentTimeMillis();
errno = client.delete_file1(appender_file_id);
System.out.println("delete_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println("Delete file success");
} else {
System.err.println("Delete file fail, error no: " + errno);
}
}
appender_file_id = client.upload_appender_file1(local_filename, null, meta_list);
if (appender_file_id != null) {
int ts;
String token;
String file_url;
InetSocketAddress inetSockAddr;
inetSockAddr = trackerServer.getInetSocketAddress();
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
if (ClientGlobal.g_tracker_http_port != 80) {
file_url += ":" + ClientGlobal.g_tracker_http_port;
}
file_url += "/" + appender_file_id;
if (ClientGlobal.g_anti_steal_token) {
ts = (int) (System.currentTimeMillis() / 1000);
token = ProtoCommon.getToken(appender_file_id, ts, ClientGlobal.g_secret_key);
file_url += "?token=" + token + "&ts=" + ts;
}
System.err.println(client.get_file_info1(appender_file_id));
System.err.println("file url: " + file_url);
errno = client.download_file1(appender_file_id, 0, 0, "c:\\" + appender_file_id.replaceAll("/", "_"));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
errno = client.download_file1(appender_file_id, 0, 0, new DownloadFileWriter("c:\\" + appender_file_id.replaceAll("/", "-")));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
file_ext_name = null;
startTime = System.currentTimeMillis();
errno = client.append_file1(appender_file_id, local_filename);
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("append file fail, error no: " + errno);
}
}
File f;
f = new File(local_filename);
int nPos = local_filename.lastIndexOf('.');
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
file_ext_name = local_filename.substring(nPos + 1);
} else {
file_ext_name = null;
}
appender_file_id = client.upload_appender_file1(null, f.length(),
new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
if (appender_file_id != null) {
System.out.println(client.get_file_info1(appender_file_id));
startTime = System.currentTimeMillis();
errno = client.append_file1(appender_file_id, f.length(), new UploadLocalFileSender(local_filename));
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("append file fail, error no: " + errno);
}
startTime = System.currentTimeMillis();
errno = client.modify_file1(appender_file_id, 0, f.length(), new UploadLocalFileSender(local_filename));
System.out.println("modify_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("modify file fail, error no: " + errno);
}
startTime = System.currentTimeMillis();
errno = client.truncate_file1(appender_file_id, 0);
System.out.println("truncate_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println(client.get_file_info1(appender_file_id));
} else {
System.err.println("truncate file fail, error no: " + errno);
}
} else {
System.err.println("Upload file fail, error no: " + errno);
}
storageServer = tracker.getFetchStorage1(trackerServer, appender_file_id);
if (storageServer == null) {
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
return;
}
/* for test only */
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
storageServer.close();
/* for test only */
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
trackerServer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
+249 -253
View File
@@ -9,7 +9,6 @@
package org.csource.fastdfs;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import java.io.File;
import java.net.InetSocketAddress;
@@ -21,41 +20,41 @@ import java.net.InetSocketAddress;
* @version Version 1.18
*/
public class TestClient {
private TestClient() {
}
/**
* entry point
*
* @param args comand arguments
* <ul><li>args[0]: config filename</li></ul>
* <ul><li>args[1]: local filename to upload</li></ul>
*/
public static void main(String args[]) {
if (args.length < 2) {
System.out.println("Error: Must have 2 parameters, one is config filename, "
+ "the other is the local filename to upload");
return;
private TestClient() {
}
System.out.println("java.version=" + System.getProperty("java.version"));
/**
* entry point
*
* @param args comand arguments
* <ul><li>args[0]: config filename</li></ul>
* <ul><li>args[1]: local filename to upload</li></ul>
*/
public static void main(String args[]) {
if (args.length < 2) {
System.out.println("Error: Must have 2 parameters, one is config filename, "
+ "the other is the local filename to upload");
return;
}
String conf_filename = args[0];
String local_filename = args[1];
System.out.println("java.version=" + System.getProperty("java.version"));
try {
ClientGlobal.init(conf_filename);
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
System.out.println("charset=" + ClientGlobal.g_charset);
String conf_filename = args[0];
String local_filename = args[1];
long startTime;
String group_name;
String remote_filename;
ServerInfo[] servers;
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
try {
ClientGlobal.init(conf_filename);
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
System.out.println("charset=" + ClientGlobal.g_charset);
StorageServer storageServer = null;
long startTime;
String group_name;
String remote_filename;
ServerInfo[] servers;
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getTrackerServer();
StorageServer storageServer = null;
/*
storageServer = tracker.getStoreStorage(trackerServer);
@@ -66,239 +65,236 @@ public class TestClient {
}
*/
StorageClient client = new StorageClient(trackerServer, storageServer);
byte[] file_buff;
NameValuePair[] meta_list;
String[] results;
String master_filename;
String prefix_name;
String file_ext_name;
String generated_slave_filename;
int errno;
StorageClient client = new StorageClient(trackerServer, storageServer);
byte[] file_buff;
NameValuePair[] meta_list;
String[] results;
String master_filename;
String prefix_name;
String file_ext_name;
String generated_slave_filename;
int errno;
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "800");
meta_list[1] = new NameValuePair("heigth", "600");
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
meta_list[3] = new NameValuePair("author", "Mike");
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "800");
meta_list[1] = new NameValuePair("heigth", "600");
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
meta_list[3] = new NameValuePair("author", "Mike");
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
System.out.println("file length: " + file_buff.length);
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
System.out.println("file length: " + file_buff.length);
group_name = null;
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
if (storageServers == null) {
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("store storage servers count: " + storageServers.length);
for (int k = 0; k < storageServers.length; k++) {
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
}
System.err.println("");
}
group_name = null;
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
if (storageServers == null) {
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("store storage servers count: " + storageServers.length);
for (int k = 0; k < storageServers.length; k++) {
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
}
System.err.println("");
}
startTime = System.currentTimeMillis();
results = client.upload_file(file_buff, "txt", meta_list);
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
startTime = System.currentTimeMillis();
results = client.upload_file(file_buff, "txt", meta_list);
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
/*
group_name = "";
results = client.upload_file(group_name, file_buff, "txt", meta_list);
*/
if (results == null) {
System.err.println("upload file fail, error code: " + client.getErrorCode());
return;
} else {
group_name = results[0];
remote_filename = results[1];
System.err.println("group_name: " + group_name + ", remote_filename: " + remote_filename);
System.err.println(client.get_file_info(group_name, remote_filename));
if (results == null) {
System.err.println("upload file fail, error code: " + client.getErrorCode());
return;
} else {
group_name = results[0];
remote_filename = results[1];
System.err.println("group_name: " + group_name + ", remote_filename: " + remote_filename);
System.err.println(client.get_file_info(group_name, remote_filename));
servers = tracker.getFetchStorages(trackerServer, group_name, remote_filename);
if (servers == null) {
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("storage servers count: " + servers.length);
for (int k = 0; k < servers.length; k++) {
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
}
System.err.println("");
servers = tracker.getFetchStorages(trackerServer, group_name, remote_filename);
if (servers == null) {
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("storage servers count: " + servers.length);
for (int k = 0; k < servers.length; k++) {
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
}
System.err.println("");
}
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "1024");
meta_list[1] = new NameValuePair("heigth", "768");
meta_list[2] = new NameValuePair("bgcolor", "#000000");
meta_list[3] = new NameValuePair("title", "Untitle");
startTime = System.currentTimeMillis();
errno = client.set_metadata(group_name, remote_filename, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE);
System.out.println("set_metadata time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println("set_metadata success");
} else {
System.err.println("set_metadata fail, error no: " + errno);
}
meta_list = client.get_metadata(group_name, remote_filename);
if (meta_list != null) {
for (int i = 0; i < meta_list.length; i++) {
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
}
}
//Thread.sleep(30000);
startTime = System.currentTimeMillis();
file_buff = client.download_file(group_name, remote_filename);
System.out.println("download_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (file_buff != null) {
System.out.println("file length:" + file_buff.length);
System.out.println((new String(file_buff)));
}
file_buff = "this is a slave buff".getBytes(ClientGlobal.g_charset);
master_filename = remote_filename;
prefix_name = "-part1";
file_ext_name = "txt";
startTime = System.currentTimeMillis();
results = client.upload_file(group_name, master_filename, prefix_name, file_buff, file_ext_name, meta_list);
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (results != null) {
System.err.println("slave file group_name: " + results[0] + ", remote_filename: " + results[1]);
generated_slave_filename = ProtoCommon.genSlaveFilename(master_filename, prefix_name, file_ext_name);
if (!generated_slave_filename.equals(results[1])) {
System.err.println("generated slave file: " + generated_slave_filename + "\n != returned slave file: " + results[1]);
}
System.err.println(client.get_file_info(results[0], results[1]));
}
startTime = System.currentTimeMillis();
errno = client.delete_file(group_name, remote_filename);
System.out.println("delete_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println("Delete file success");
} else {
System.err.println("Delete file fail, error no: " + errno);
}
}
results = client.upload_file(local_filename, null, meta_list);
if (results != null) {
String file_id;
int ts;
String token;
String file_url;
InetSocketAddress inetSockAddr;
group_name = results[0];
remote_filename = results[1];
file_id = group_name + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remote_filename;
inetSockAddr = trackerServer.getInetSocketAddress();
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
if (ClientGlobal.g_tracker_http_port != 80) {
file_url += ":" + ClientGlobal.g_tracker_http_port;
}
file_url += "/" + file_id;
if (ClientGlobal.g_anti_steal_token) {
ts = (int) (System.currentTimeMillis() / 1000);
token = ProtoCommon.getToken(file_id, ts, ClientGlobal.g_secret_key);
file_url += "?token=" + token + "&ts=" + ts;
}
System.err.println("group_name: " + group_name + ", remote_filename: " + remote_filename);
System.err.println(client.get_file_info(group_name, remote_filename));
System.err.println("file url: " + file_url);
errno = client.download_file(group_name, remote_filename, 0, 0, "c:\\" + remote_filename.replaceAll("/", "_"));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
errno = client.download_file(group_name, remote_filename, 0, 0, new DownloadFileWriter("c:\\" + remote_filename.replaceAll("/", "-")));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
master_filename = remote_filename;
prefix_name = "-part2";
file_ext_name = null;
startTime = System.currentTimeMillis();
results = client.upload_file(group_name, master_filename, prefix_name, local_filename, null, meta_list);
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (results != null) {
System.err.println("slave file group_name: " + results[0] + ", remote_filename: " + results[1]);
generated_slave_filename = ProtoCommon.genSlaveFilename(master_filename, prefix_name, file_ext_name);
if (!generated_slave_filename.equals(results[1])) {
System.err.println("generated slave file: " + generated_slave_filename + "\n != returned slave file: " + results[1]);
}
System.err.println(client.get_file_info(results[0], results[1]));
}
}
File f;
f = new File(local_filename);
int nPos = local_filename.lastIndexOf('.');
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
file_ext_name = local_filename.substring(nPos + 1);
} else {
file_ext_name = null;
}
results = client.upload_file(null, f.length(),
new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
if (results != null) {
group_name = results[0];
remote_filename = results[1];
System.out.println("group name: " + group_name + ", remote filename: " + remote_filename);
System.out.println(client.get_file_info(group_name, remote_filename));
master_filename = remote_filename;
prefix_name = "-part3";
startTime = System.currentTimeMillis();
results = client.upload_file(group_name, master_filename, prefix_name, f.length(), new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (results != null) {
System.err.println("slave file group_name: " + results[0] + ", remote_filename: " + results[1]);
generated_slave_filename = ProtoCommon.genSlaveFilename(master_filename, prefix_name, file_ext_name);
if (!generated_slave_filename.equals(results[1])) {
System.err.println("generated slave file: " + generated_slave_filename + "\n != returned slave file: " + results[1]);
}
System.err.println(client.get_file_info(results[0], results[1]));
}
} else {
System.err.println("Upload file fail, error no: " + errno);
}
storageServer = tracker.getFetchStorage(trackerServer, group_name, remote_filename);
if (storageServer == null) {
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
return;
}
/* for test only */
System.out.println("active test to storage server: " + storageServer.getConnection().activeTest());
/* for test only */
System.out.println("active test to tracker server: " + trackerServer.getConnection().activeTest());
} catch (Exception ex) {
ex.printStackTrace();
}
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "1024");
meta_list[1] = new NameValuePair("heigth", "768");
meta_list[2] = new NameValuePair("bgcolor", "#000000");
meta_list[3] = new NameValuePair("title", "Untitle");
startTime = System.currentTimeMillis();
errno = client.set_metadata(group_name, remote_filename, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE);
System.out.println("set_metadata time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println("set_metadata success");
} else {
System.err.println("set_metadata fail, error no: " + errno);
}
meta_list = client.get_metadata(group_name, remote_filename);
if (meta_list != null) {
for (int i = 0; i < meta_list.length; i++) {
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
}
}
//Thread.sleep(30000);
startTime = System.currentTimeMillis();
file_buff = client.download_file(group_name, remote_filename);
System.out.println("download_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (file_buff != null) {
System.out.println("file length:" + file_buff.length);
System.out.println((new String(file_buff)));
}
file_buff = "this is a slave buff".getBytes(ClientGlobal.g_charset);
master_filename = remote_filename;
prefix_name = "-part1";
file_ext_name = "txt";
startTime = System.currentTimeMillis();
results = client.upload_file(group_name, master_filename, prefix_name, file_buff, file_ext_name, meta_list);
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (results != null) {
System.err.println("slave file group_name: " + results[0] + ", remote_filename: " + results[1]);
generated_slave_filename = ProtoCommon.genSlaveFilename(master_filename, prefix_name, file_ext_name);
if (!generated_slave_filename.equals(results[1])) {
System.err.println("generated slave file: " + generated_slave_filename + "\n != returned slave file: " + results[1]);
}
System.err.println(client.get_file_info(results[0], results[1]));
}
startTime = System.currentTimeMillis();
errno = client.delete_file(group_name, remote_filename);
System.out.println("delete_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (errno == 0) {
System.err.println("Delete file success");
} else {
System.err.println("Delete file fail, error no: " + errno);
}
}
results = client.upload_file(local_filename, null, meta_list);
if (results != null) {
String file_id;
int ts;
String token;
String file_url;
InetSocketAddress inetSockAddr;
group_name = results[0];
remote_filename = results[1];
file_id = group_name + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remote_filename;
inetSockAddr = trackerServer.getInetSocketAddress();
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
if (ClientGlobal.g_tracker_http_port != 80) {
file_url += ":" + ClientGlobal.g_tracker_http_port;
}
file_url += "/" + file_id;
if (ClientGlobal.g_anti_steal_token) {
ts = (int) (System.currentTimeMillis() / 1000);
token = ProtoCommon.getToken(file_id, ts, ClientGlobal.g_secret_key);
file_url += "?token=" + token + "&ts=" + ts;
}
System.err.println("group_name: " + group_name + ", remote_filename: " + remote_filename);
System.err.println(client.get_file_info(group_name, remote_filename));
System.err.println("file url: " + file_url);
errno = client.download_file(group_name, remote_filename, 0, 0, "c:\\" + remote_filename.replaceAll("/", "_"));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
errno = client.download_file(group_name, remote_filename, 0, 0, new DownloadFileWriter("c:\\" + remote_filename.replaceAll("/", "-")));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
master_filename = remote_filename;
prefix_name = "-part2";
file_ext_name = null;
startTime = System.currentTimeMillis();
results = client.upload_file(group_name, master_filename, prefix_name, local_filename, null, meta_list);
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (results != null) {
System.err.println("slave file group_name: " + results[0] + ", remote_filename: " + results[1]);
generated_slave_filename = ProtoCommon.genSlaveFilename(master_filename, prefix_name, file_ext_name);
if (!generated_slave_filename.equals(results[1])) {
System.err.println("generated slave file: " + generated_slave_filename + "\n != returned slave file: " + results[1]);
}
System.err.println(client.get_file_info(results[0], results[1]));
}
}
File f;
f = new File(local_filename);
int nPos = local_filename.lastIndexOf('.');
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
file_ext_name = local_filename.substring(nPos + 1);
} else {
file_ext_name = null;
}
results = client.upload_file(null, f.length(),
new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
if (results != null) {
group_name = results[0];
remote_filename = results[1];
System.out.println("group name: " + group_name + ", remote filename: " + remote_filename);
System.out.println(client.get_file_info(group_name, remote_filename));
master_filename = remote_filename;
prefix_name = "-part3";
startTime = System.currentTimeMillis();
results = client.upload_file(group_name, master_filename, prefix_name, f.length(), new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
if (results != null) {
System.err.println("slave file group_name: " + results[0] + ", remote_filename: " + results[1]);
generated_slave_filename = ProtoCommon.genSlaveFilename(master_filename, prefix_name, file_ext_name);
if (!generated_slave_filename.equals(results[1])) {
System.err.println("generated slave file: " + generated_slave_filename + "\n != returned slave file: " + results[1]);
}
System.err.println(client.get_file_info(results[0], results[1]));
}
} else {
System.err.println("Upload file fail, error no: " + errno);
}
storageServer = tracker.getFetchStorage(trackerServer, group_name, remote_filename);
if (storageServer == null) {
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
return;
}
/* for test only */
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
storageServer.close();
/* for test only */
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
trackerServer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
+214 -217
View File
@@ -9,7 +9,6 @@
package org.csource.fastdfs;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import java.io.File;
import java.net.InetSocketAddress;
@@ -21,40 +20,40 @@ import java.net.InetSocketAddress;
* @version Version 1.16
*/
public class TestClient1 {
private TestClient1() {
}
/**
* entry point
*
* @param args comand arguments
* <ul><li>args[0]: config filename</li></ul>
* <ul><li>args[1]: local filename to upload</li></ul>
*/
public static void main(String args[]) {
if (args.length < 2) {
System.out.println("Error: Must have 2 parameters, one is config filename, "
+ "the other is the local filename to upload");
return;
private TestClient1() {
}
System.out.println("java.version=" + System.getProperty("java.version"));
/**
* entry point
*
* @param args comand arguments
* <ul><li>args[0]: config filename</li></ul>
* <ul><li>args[1]: local filename to upload</li></ul>
*/
public static void main(String args[]) {
if (args.length < 2) {
System.out.println("Error: Must have 2 parameters, one is config filename, "
+ "the other is the local filename to upload");
return;
}
String conf_filename = args[0];
String local_filename = args[1];
String group_name;
System.out.println("java.version=" + System.getProperty("java.version"));
try {
ClientGlobal.init(conf_filename);
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
System.out.println("charset=" + ClientGlobal.g_charset);
String conf_filename = args[0];
String local_filename = args[1];
String group_name;
String file_id;
try {
ClientGlobal.init(conf_filename);
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
System.out.println("charset=" + ClientGlobal.g_charset);
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
String file_id;
StorageServer storageServer = null;
TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getTrackerServer();
StorageServer storageServer = null;
/*
storageServer = tracker.getStoreStorage(trackerServer);
if (storageServer == null)
@@ -63,204 +62,202 @@ public class TestClient1 {
return;
}
*/
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
byte[] file_buff;
NameValuePair[] meta_list;
String master_file_id;
String prefix_name;
String file_ext_name;
String slave_file_id;
String generated_slave_file_id;
int errno;
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
byte[] file_buff;
NameValuePair[] meta_list;
String master_file_id;
String prefix_name;
String file_ext_name;
String slave_file_id;
String generated_slave_file_id;
int errno;
group_name = "group1";
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
if (storageServers == null) {
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("store storage servers count: " + storageServers.length);
for (int k = 0; k < storageServers.length; k++) {
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
}
System.err.println("");
}
group_name = "group1";
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
if (storageServers == null) {
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("store storage servers count: " + storageServers.length);
for (int k = 0; k < storageServers.length; k++) {
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
}
System.err.println("");
}
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "800");
meta_list[1] = new NameValuePair("heigth", "600");
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
meta_list[3] = new NameValuePair("author", "Mike");
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "800");
meta_list[1] = new NameValuePair("heigth", "600");
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
meta_list[3] = new NameValuePair("author", "Mike");
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
System.out.println("file length: " + file_buff.length);
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
System.out.println("file length: " + file_buff.length);
file_id = client.upload_file1(file_buff, "txt", meta_list);
file_id = client.upload_file1(file_buff, "txt", meta_list);
/*
group_name = "group1";
file_id = client.upload_file1(group_name, file_buff, "txt", meta_list);
*/
if (file_id == null) {
System.err.println("upload file fail, error code: " + client.getErrorCode());
return;
} else {
System.err.println("file_id: " + file_id);
System.err.println(client.get_file_info1(file_id));
if (file_id == null) {
System.err.println("upload file fail, error code: " + client.getErrorCode());
return;
} else {
System.err.println("file_id: " + file_id);
System.err.println(client.get_file_info1(file_id));
ServerInfo[] servers = tracker.getFetchStorages1(trackerServer, file_id);
if (servers == null) {
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("storage servers count: " + servers.length);
for (int k = 0; k < servers.length; k++) {
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
}
System.err.println("");
ServerInfo[] servers = tracker.getFetchStorages1(trackerServer, file_id);
if (servers == null) {
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
} else {
System.err.println("storage servers count: " + servers.length);
for (int k = 0; k < servers.length; k++) {
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
}
System.err.println("");
}
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "1024");
meta_list[1] = new NameValuePair("heigth", "768");
meta_list[2] = new NameValuePair("bgcolor", "#000000");
meta_list[3] = new NameValuePair("title", "Untitle");
if ((errno = client.set_metadata1(file_id, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE)) == 0) {
System.err.println("set_metadata success");
} else {
System.err.println("set_metadata fail, error no: " + errno);
}
meta_list = client.get_metadata1(file_id);
if (meta_list != null) {
for (int i = 0; i < meta_list.length; i++) {
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
}
}
//Thread.sleep(30000);
file_buff = client.download_file1(file_id);
if (file_buff != null) {
System.out.println("file length:" + file_buff.length);
System.out.println((new String(file_buff)));
}
master_file_id = file_id;
prefix_name = "-part1";
file_ext_name = "txt";
file_buff = "this is a slave buff.".getBytes(ClientGlobal.g_charset);
slave_file_id = client.upload_file1(master_file_id, prefix_name, file_buff, file_ext_name, meta_list);
if (slave_file_id != null) {
System.err.println("slave file_id: " + slave_file_id);
System.err.println(client.get_file_info1(slave_file_id));
generated_slave_file_id = ProtoCommon.genSlaveFilename(master_file_id, prefix_name, file_ext_name);
if (!generated_slave_file_id.equals(slave_file_id)) {
System.err.println("generated slave file: " + generated_slave_file_id + "\n != returned slave file: " + slave_file_id);
}
}
//Thread.sleep(10000);
if ((errno = client.delete_file1(file_id)) == 0) {
System.err.println("Delete file success");
} else {
System.err.println("Delete file fail, error no: " + errno);
}
}
if ((file_id = client.upload_file1(local_filename, null, meta_list)) != null) {
int ts;
String token;
String file_url;
InetSocketAddress inetSockAddr;
System.err.println("file_id: " + file_id);
System.err.println(client.get_file_info1(file_id));
inetSockAddr = trackerServer.getInetSocketAddress();
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
if (ClientGlobal.g_tracker_http_port != 80) {
file_url += ":" + ClientGlobal.g_tracker_http_port;
}
file_url += "/" + file_id;
if (ClientGlobal.g_anti_steal_token) {
ts = (int) (System.currentTimeMillis() / 1000);
token = ProtoCommon.getToken(file_id, ts, ClientGlobal.g_secret_key);
file_url += "?token=" + token + "&ts=" + ts;
}
System.err.println("file url: " + file_url);
errno = client.download_file1(file_id, 0, 100, "c:\\" + file_id.replaceAll("/", "_"));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
errno = client.download_file1(file_id, new DownloadFileWriter("c:\\" + file_id.replaceAll("/", "-")));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
master_file_id = file_id;
prefix_name = "-part2";
file_ext_name = null;
slave_file_id = client.upload_file1(master_file_id, prefix_name, local_filename, file_ext_name, meta_list);
if (slave_file_id != null) {
System.err.println("slave file_id: " + slave_file_id);
System.err.println(client.get_file_info1(slave_file_id));
generated_slave_file_id = ProtoCommon.genSlaveFilename(master_file_id, prefix_name, file_ext_name);
if (!generated_slave_file_id.equals(slave_file_id)) {
System.err.println("generated slave file: " + generated_slave_file_id + "\n != returned slave file: " + slave_file_id);
}
}
}
File f;
f = new File(local_filename);
int nPos = local_filename.lastIndexOf('.');
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
file_ext_name = local_filename.substring(nPos + 1);
} else {
file_ext_name = null;
}
file_id = client.upload_file1(null, f.length(), new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
if (file_id != null) {
System.out.println("file id: " + file_id);
System.out.println(client.get_file_info1(file_id));
master_file_id = file_id;
prefix_name = "-part3";
slave_file_id = client.upload_file1(master_file_id, prefix_name, f.length(), new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
if (slave_file_id != null) {
System.err.println("slave file_id: " + slave_file_id);
generated_slave_file_id = ProtoCommon.genSlaveFilename(master_file_id, prefix_name, file_ext_name);
if (!generated_slave_file_id.equals(slave_file_id)) {
System.err.println("generated slave file: " + generated_slave_file_id + "\n != returned slave file: " + slave_file_id);
}
}
} else {
System.err.println("Upload file fail, error no: " + errno);
}
storageServer = tracker.getFetchStorage1(trackerServer, file_id);
if (storageServer == null) {
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
return;
}
/* for test only */
System.out.println("active test to storage server: " + storageServer.getConnection().activeTest());
/* for test only */
System.out.println("active test to tracker server: " + trackerServer.getConnection().activeTest());
} catch (Exception ex) {
ex.printStackTrace();
}
meta_list = new NameValuePair[4];
meta_list[0] = new NameValuePair("width", "1024");
meta_list[1] = new NameValuePair("heigth", "768");
meta_list[2] = new NameValuePair("bgcolor", "#000000");
meta_list[3] = new NameValuePair("title", "Untitle");
if ((errno = client.set_metadata1(file_id, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE)) == 0) {
System.err.println("set_metadata success");
} else {
System.err.println("set_metadata fail, error no: " + errno);
}
meta_list = client.get_metadata1(file_id);
if (meta_list != null) {
for (int i = 0; i < meta_list.length; i++) {
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
}
}
//Thread.sleep(30000);
file_buff = client.download_file1(file_id);
if (file_buff != null) {
System.out.println("file length:" + file_buff.length);
System.out.println((new String(file_buff)));
}
master_file_id = file_id;
prefix_name = "-part1";
file_ext_name = "txt";
file_buff = "this is a slave buff.".getBytes(ClientGlobal.g_charset);
slave_file_id = client.upload_file1(master_file_id, prefix_name, file_buff, file_ext_name, meta_list);
if (slave_file_id != null) {
System.err.println("slave file_id: " + slave_file_id);
System.err.println(client.get_file_info1(slave_file_id));
generated_slave_file_id = ProtoCommon.genSlaveFilename(master_file_id, prefix_name, file_ext_name);
if (!generated_slave_file_id.equals(slave_file_id)) {
System.err.println("generated slave file: " + generated_slave_file_id + "\n != returned slave file: " + slave_file_id);
}
}
//Thread.sleep(10000);
if ((errno = client.delete_file1(file_id)) == 0) {
System.err.println("Delete file success");
} else {
System.err.println("Delete file fail, error no: " + errno);
}
}
if ((file_id = client.upload_file1(local_filename, null, meta_list)) != null) {
int ts;
String token;
String file_url;
InetSocketAddress inetSockAddr;
System.err.println("file_id: " + file_id);
System.err.println(client.get_file_info1(file_id));
inetSockAddr = trackerServer.getInetSocketAddress();
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
if (ClientGlobal.g_tracker_http_port != 80) {
file_url += ":" + ClientGlobal.g_tracker_http_port;
}
file_url += "/" + file_id;
if (ClientGlobal.g_anti_steal_token) {
ts = (int) (System.currentTimeMillis() / 1000);
token = ProtoCommon.getToken(file_id, ts, ClientGlobal.g_secret_key);
file_url += "?token=" + token + "&ts=" + ts;
}
System.err.println("file url: " + file_url);
errno = client.download_file1(file_id, 0, 100, "c:\\" + file_id.replaceAll("/", "_"));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
errno = client.download_file1(file_id, new DownloadFileWriter("c:\\" + file_id.replaceAll("/", "-")));
if (errno == 0) {
System.err.println("Download file success");
} else {
System.err.println("Download file fail, error no: " + errno);
}
master_file_id = file_id;
prefix_name = "-part2";
file_ext_name = null;
slave_file_id = client.upload_file1(master_file_id, prefix_name, local_filename, file_ext_name, meta_list);
if (slave_file_id != null) {
System.err.println("slave file_id: " + slave_file_id);
System.err.println(client.get_file_info1(slave_file_id));
generated_slave_file_id = ProtoCommon.genSlaveFilename(master_file_id, prefix_name, file_ext_name);
if (!generated_slave_file_id.equals(slave_file_id)) {
System.err.println("generated slave file: " + generated_slave_file_id + "\n != returned slave file: " + slave_file_id);
}
}
}
File f;
f = new File(local_filename);
int nPos = local_filename.lastIndexOf('.');
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
file_ext_name = local_filename.substring(nPos + 1);
} else {
file_ext_name = null;
}
file_id = client.upload_file1(null, f.length(), new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
if (file_id != null) {
System.out.println("file id: " + file_id);
System.out.println(client.get_file_info1(file_id));
master_file_id = file_id;
prefix_name = "-part3";
slave_file_id = client.upload_file1(master_file_id, prefix_name, f.length(), new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
if (slave_file_id != null) {
System.err.println("slave file_id: " + slave_file_id);
generated_slave_file_id = ProtoCommon.genSlaveFilename(master_file_id, prefix_name, file_ext_name);
if (!generated_slave_file_id.equals(slave_file_id)) {
System.err.println("generated slave file: " + generated_slave_file_id + "\n != returned slave file: " + slave_file_id);
}
}
} else {
System.err.println("Upload file fail, error no: " + errno);
}
storageServer = tracker.getFetchStorage1(trackerServer, file_id);
if (storageServer == null) {
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
return;
}
/* for test only */
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
storageServer.close();
/* for test only */
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
trackerServer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
@@ -8,8 +8,6 @@
package org.csource.fastdfs;
import org.csource.fastdfs.*;
/**
* load test class
*
@@ -88,7 +86,7 @@ public class TestLoad {
public Uploader() throws Exception {
this.tracker = new TrackerClient();
this.trackerServer = tracker.getConnection();
this.trackerServer = tracker.getTrackerServer();
}
public int uploadFile() throws Exception {
@@ -129,7 +127,7 @@ public class TestLoad {
public Downloader() throws Exception {
this.tracker = new TrackerClient();
this.trackerServer = tracker.getConnection();
this.trackerServer = tracker.getTrackerServer();
this.callback = new DownloadFileDiscard();
}
+1 -1
View File
@@ -6,4 +6,4 @@ http.anti_steal_token = no
http.secret_key = FastDFS1234567890
tracker_server = 10.0.11.245:22122
tracker_server = 10.0.11.246:22122
tracker_server = 10.0.11.246:22122