Compare commits
16 Commits
9cc79ed75d
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| d6a7a0eebf | |||
| 6c396d2893 | |||
| 883b03e550 | |||
| a4bd80de4a | |||
| 9a6410a3cf | |||
|
|
45d9a89e25 | ||
|
|
42132c694c | ||
|
|
1b263e6436 | ||
|
|
41655defd8 | ||
|
|
a1df79c50e | ||
|
|
2b4693643a | ||
|
|
4de15ae592 | ||
|
|
0087216c0a | ||
|
|
77946b2382 | ||
|
|
0b2ec3aa10 | ||
|
|
8d966af4a4 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -12,6 +12,8 @@ target
|
||||
*.iws
|
||||
*.log
|
||||
.idea
|
||||
|
||||
*.conf
|
||||
*.PNG
|
||||
|
||||
.vscode/
|
||||
*.class
|
||||
|
||||
5
HISTORY
5
HISTORY
@@ -1,3 +1,8 @@
|
||||
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.
|
||||
|
||||
@@ -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.29-SNAPSHOT</version>
|
||||
<version>1.30-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
6
pom.xml
6
pom.xml
@@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>org.csource</groupId>
|
||||
<artifactId>fastdfs-client-java</artifactId>
|
||||
<version>1.29-SNAPSHOT</version>
|
||||
<version>1.30-SNAPSHOT</version>
|
||||
<name>fastdfs-client-java</name>
|
||||
<description>fastdfs client for java</description>
|
||||
<packaging>jar</packaging>
|
||||
@@ -14,8 +14,8 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<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>
|
||||
<jdk.version>1.8</jdk.version>
|
||||
<slf4j.version>1.7.36</slf4j.version>
|
||||
</properties>
|
||||
|
||||
<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();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package org.csource.common;
|
||||
*/
|
||||
public class MyException extends Exception {
|
||||
public MyException(String s, Exception e) {
|
||||
super(s, e);
|
||||
}
|
||||
|
||||
public MyException(String message) {
|
||||
|
||||
@@ -48,7 +48,6 @@ public class ClientGlobal {
|
||||
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 int DEFAULT_CONNECT_TIMEOUT = 5; //second
|
||||
public static final int DEFAULT_NETWORK_TIMEOUT = 30; //second
|
||||
public static final String DEFAULT_CHARSET = "UTF-8";
|
||||
@@ -180,7 +179,6 @@ public class ClientGlobal {
|
||||
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;
|
||||
}
|
||||
@@ -221,7 +219,7 @@ 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);
|
||||
|
||||
@@ -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!");
|
||||
|
||||
@@ -73,15 +73,18 @@ public class StorageClient {
|
||||
* upload file to storage server (by file name)
|
||||
*
|
||||
* @param local_filename local filename to upload
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract
|
||||
* ext name from the local filename
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file </li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(String local_filename, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final String group_name = null;
|
||||
return this.upload_file(group_name, local_filename, file_ext_name, meta_list);
|
||||
}
|
||||
@@ -91,15 +94,18 @@ public class StorageClient {
|
||||
*
|
||||
* @param group_name the group name to upload file to, can be empty
|
||||
* @param local_filename local filename to upload
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract
|
||||
* ext name from the local filename
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file </li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
protected String[] upload_file(String group_name, String local_filename, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final byte cmd = ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_FILE;
|
||||
return this.upload_file(cmd, group_name, local_filename, file_ext_name, meta_list);
|
||||
}
|
||||
@@ -110,15 +116,18 @@ public class StorageClient {
|
||||
* @param cmd the command
|
||||
* @param group_name the group name to upload file to, can be empty
|
||||
* @param local_filename local filename to upload
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract
|
||||
* ext name from the local filename
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file </li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
protected String[] upload_file(byte cmd, String group_name, String local_filename, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
File f = new File(local_filename);
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
|
||||
@@ -146,12 +155,14 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(byte[] file_buff, int offset, int length, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final String group_name = null;
|
||||
return this.upload_file(group_name, file_buff, offset, length, file_ext_name, meta_list);
|
||||
}
|
||||
@@ -166,12 +177,14 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(String group_name, byte[] file_buff, int offset, int length,
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_FILE, group_name, null, null, file_ext_name,
|
||||
length, new UploadBuff(file_buff, offset, length), meta_list);
|
||||
}
|
||||
@@ -183,12 +196,14 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(byte[] file_buff, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final String group_name = null;
|
||||
return this.upload_file(group_name, file_buff, 0, file_buff.length, file_ext_name, meta_list);
|
||||
}
|
||||
@@ -201,12 +216,14 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(String group_name, byte[] file_buff,
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_FILE, group_name, null, null, file_ext_name,
|
||||
file_buff.length, new UploadBuff(file_buff, 0, file_buff.length), meta_list);
|
||||
}
|
||||
@@ -220,12 +237,14 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(String group_name, long file_size, UploadCallback callback,
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final String master_filename = null;
|
||||
final String prefix_name = null;
|
||||
|
||||
@@ -240,15 +259,18 @@ public class StorageClient {
|
||||
* @param master_filename the master file name to generate the slave file
|
||||
* @param prefix_name the prefix name to generate the slave file
|
||||
* @param local_filename local filename to upload
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract
|
||||
* ext name from the local filename
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file </li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(String group_name, String master_filename, String prefix_name,
|
||||
String local_filename, String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
String local_filename, String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
if ((group_name == null || group_name.length() == 0) ||
|
||||
(master_filename == null || master_filename.length() == 0) ||
|
||||
(prefix_name == null)) {
|
||||
@@ -266,8 +288,8 @@ public class StorageClient {
|
||||
}
|
||||
|
||||
try {
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, group_name, master_filename, prefix_name,
|
||||
file_ext_name, f.length(), new UploadStream(fis, f.length()), meta_list);
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, group_name, master_filename,
|
||||
prefix_name, file_ext_name, f.length(), new UploadStream(fis, f.length()), meta_list);
|
||||
} finally {
|
||||
fis.close();
|
||||
}
|
||||
@@ -283,20 +305,23 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(String group_name, String master_filename, String prefix_name,
|
||||
byte[] file_buff, String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
byte[] file_buff, String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
if ((group_name == null || group_name.length() == 0) ||
|
||||
(master_filename == null || master_filename.length() == 0) ||
|
||||
(prefix_name == null)) {
|
||||
throw new MyException("invalid arguement");
|
||||
}
|
||||
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, group_name, master_filename, prefix_name,
|
||||
file_ext_name, file_buff.length, new UploadBuff(file_buff, 0, file_buff.length), meta_list);
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, group_name, master_filename,
|
||||
prefix_name, file_ext_name, file_buff.length, new UploadBuff(file_buff, 0, file_buff.length),
|
||||
meta_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,21 +336,23 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(String group_name, String master_filename, String prefix_name,
|
||||
byte[] file_buff, int offset, int length, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
byte[] file_buff, int offset, int length, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
if ((group_name == null || group_name.length() == 0) ||
|
||||
(master_filename == null || master_filename.length() == 0) ||
|
||||
(prefix_name == null)) {
|
||||
throw new MyException("invalid arguement");
|
||||
}
|
||||
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, group_name, master_filename, prefix_name,
|
||||
file_ext_name, length, new UploadBuff(file_buff, offset, length), meta_list);
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, group_name, master_filename,
|
||||
prefix_name, file_ext_name, length, new UploadBuff(file_buff, offset, length), meta_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,30 +366,35 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_file(String group_name, String master_filename,
|
||||
String prefix_name, long file_size, UploadCallback callback,
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, group_name, master_filename, prefix_name,
|
||||
file_ext_name, file_size, callback, meta_list);
|
||||
String prefix_name, long file_size, UploadCallback callback,
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, group_name, master_filename,
|
||||
prefix_name, file_ext_name, file_size, callback, meta_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* upload appender file to storage server (by file name)
|
||||
*
|
||||
* @param local_filename local filename to upload
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract
|
||||
* ext name from the local filename
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file </li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_appender_file(String local_filename, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final String group_name = null;
|
||||
return this.upload_appender_file(group_name, local_filename, file_ext_name, meta_list);
|
||||
}
|
||||
@@ -372,15 +404,18 @@ public class StorageClient {
|
||||
*
|
||||
* @param group_name the group name to upload file to, can be empty
|
||||
* @param local_filename local filename to upload
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename
|
||||
* @param file_ext_name file ext name, do not include dot(.), null to extract
|
||||
* ext name from the local filename
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file </li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
protected String[] upload_appender_file(String group_name, String local_filename, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final byte cmd = ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE;
|
||||
return this.upload_file(cmd, group_name, local_filename, file_ext_name, meta_list);
|
||||
}
|
||||
@@ -394,12 +429,14 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_appender_file(byte[] file_buff, int offset, int length, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final String group_name = null;
|
||||
return this.upload_appender_file(group_name, file_buff, offset, length, file_ext_name, meta_list);
|
||||
}
|
||||
@@ -414,14 +451,16 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_appender_file(String group_name, byte[] file_buff, int offset, int length,
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE, group_name, null, null, file_ext_name,
|
||||
length, new UploadBuff(file_buff, offset, length), meta_list);
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE, group_name, null, null,
|
||||
file_ext_name, length, new UploadBuff(file_buff, offset, length), meta_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,12 +470,14 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_appender_file(byte[] file_buff, String file_ext_name,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final String group_name = null;
|
||||
return this.upload_appender_file(group_name, file_buff, 0, file_buff.length, file_ext_name, meta_list);
|
||||
}
|
||||
@@ -449,14 +490,16 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_appender_file(String group_name, byte[] file_buff,
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE, group_name, null, null, file_ext_name,
|
||||
file_buff.length, new UploadBuff(file_buff, 0, file_buff.length), meta_list);
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE, group_name, null, null,
|
||||
file_ext_name, file_buff.length, new UploadBuff(file_buff, 0, file_buff.length), meta_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -468,16 +511,19 @@ public class StorageClient {
|
||||
* @param file_ext_name file ext name, do not include dot(.)
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li>results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li>results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] upload_appender_file(String group_name, long file_size, UploadCallback callback,
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException {
|
||||
final String master_filename = null;
|
||||
final String prefix_name = null;
|
||||
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE, group_name, master_filename, prefix_name,
|
||||
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_APPENDER_FILE, group_name, master_filename,
|
||||
prefix_name,
|
||||
file_ext_name, file_size, callback, meta_list);
|
||||
}
|
||||
|
||||
@@ -489,7 +535,8 @@ public class StorageClient {
|
||||
* @param local_filename local filename to append
|
||||
* @return 0 for success, != 0 for error (error no)
|
||||
*/
|
||||
public int append_file(String group_name, String appender_filename, String local_filename) throws IOException, MyException {
|
||||
public int append_file(String group_name, String appender_filename, String local_filename)
|
||||
throws IOException, MyException {
|
||||
File f = new File(local_filename);
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
|
||||
@@ -508,8 +555,10 @@ public class StorageClient {
|
||||
* @param file_buff file content/buff
|
||||
* @return 0 for success, != 0 for error (error no)
|
||||
*/
|
||||
public int append_file(String group_name, String appender_filename, byte[] file_buff) throws IOException, MyException {
|
||||
return this.do_append_file(group_name, appender_filename, file_buff.length, new UploadBuff(file_buff, 0, file_buff.length));
|
||||
public int append_file(String group_name, String appender_filename, byte[] file_buff)
|
||||
throws IOException, MyException {
|
||||
return this.do_append_file(group_name, appender_filename, file_buff.length,
|
||||
new UploadBuff(file_buff, 0, file_buff.length));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -523,7 +572,7 @@ public class StorageClient {
|
||||
* @return 0 for success, != 0 for error (error no)
|
||||
*/
|
||||
public int append_file(String group_name, String appender_filename,
|
||||
byte[] file_buff, int offset, int length) throws IOException, MyException {
|
||||
byte[] file_buff, int offset, int length) throws IOException, MyException {
|
||||
return this.do_append_file(group_name, appender_filename, length, new UploadBuff(file_buff, offset, length));
|
||||
}
|
||||
|
||||
@@ -537,7 +586,7 @@ public class StorageClient {
|
||||
* @return 0 for success, != 0 for error (error no)
|
||||
*/
|
||||
public int append_file(String group_name, String appender_filename,
|
||||
long file_size, UploadCallback callback) throws IOException, MyException {
|
||||
long file_size, UploadCallback callback) throws IOException, MyException {
|
||||
return this.do_append_file(group_name, appender_filename, file_size, callback);
|
||||
}
|
||||
|
||||
@@ -551,7 +600,7 @@ public class StorageClient {
|
||||
* @return 0 for success, != 0 for error (error no)
|
||||
*/
|
||||
public int modify_file(String group_name, String appender_filename,
|
||||
long file_offset, String local_filename) throws IOException, MyException {
|
||||
long file_offset, String local_filename) throws IOException, MyException {
|
||||
File f = new File(local_filename);
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
|
||||
@@ -573,7 +622,7 @@ public class StorageClient {
|
||||
* @return 0 for success, != 0 for error (error no)
|
||||
*/
|
||||
public int modify_file(String group_name, String appender_filename,
|
||||
long file_offset, byte[] file_buff) throws IOException, MyException {
|
||||
long file_offset, byte[] file_buff) throws IOException, MyException {
|
||||
return this.do_modify_file(group_name, appender_filename, file_offset,
|
||||
file_buff.length, new UploadBuff(file_buff, 0, file_buff.length));
|
||||
}
|
||||
@@ -590,7 +639,7 @@ public class StorageClient {
|
||||
* @return 0 for success, != 0 for error (error no)
|
||||
*/
|
||||
public int modify_file(String group_name, String appender_filename,
|
||||
long file_offset, byte[] file_buff, int buffer_offset, int buffer_length) throws IOException, MyException {
|
||||
long file_offset, byte[] file_buff, int buffer_offset, int buffer_length) throws IOException, MyException {
|
||||
return this.do_modify_file(group_name, appender_filename, file_offset,
|
||||
buffer_length, new UploadBuff(file_buff, buffer_offset, buffer_length));
|
||||
}
|
||||
@@ -606,7 +655,7 @@ public class StorageClient {
|
||||
* @return 0 for success, != 0 for error (error no)
|
||||
*/
|
||||
public int modify_file(String group_name, String appender_filename,
|
||||
long file_offset, long modify_size, UploadCallback callback) throws IOException, MyException {
|
||||
long file_offset, long modify_size, UploadCallback callback) throws IOException, MyException {
|
||||
return this.do_modify_file(group_name, appender_filename, file_offset,
|
||||
modify_size, callback);
|
||||
}
|
||||
@@ -617,11 +666,14 @@ public class StorageClient {
|
||||
* @param group_name the group name of appender file
|
||||
* @param appender_filename the appender filename
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li> results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li> results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
public String[] regenerate_appender_filename(String group_name, String appender_filename) throws IOException, MyException {
|
||||
public String[] regenerate_appender_filename(String group_name, String appender_filename)
|
||||
throws IOException, MyException {
|
||||
byte[] header;
|
||||
boolean bNewStorageServer;
|
||||
Connection connection = null;
|
||||
@@ -700,13 +752,15 @@ public class StorageClient {
|
||||
* @param callback the write data callback object
|
||||
* @param meta_list meta info array
|
||||
* @return 2 elements string array if success:<br>
|
||||
* <ul><li> results[0]: the group name to store the file</li></ul>
|
||||
* <ul><li> results[1]: the new created filename</li></ul>
|
||||
* return null if fail
|
||||
* <ul>
|
||||
* <li>results[0]: the group name to store the file</li>
|
||||
* <li>results[1]: the new created filename</li>
|
||||
* </ul>
|
||||
* return null if fail
|
||||
*/
|
||||
protected String[] do_upload_file(byte cmd, String group_name, String master_filename,
|
||||
String prefix_name, String file_ext_name, long file_size, UploadCallback callback,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
String prefix_name, String file_ext_name, long file_size, UploadCallback callback,
|
||||
NameValuePair[] meta_list) throws IOException, MyException {
|
||||
byte[] header;
|
||||
byte[] ext_name_bs;
|
||||
String new_group_name;
|
||||
@@ -731,7 +785,6 @@ public class StorageClient {
|
||||
|
||||
try {
|
||||
connection = this.storageServer.getConnection();
|
||||
|
||||
ext_name_bs = new byte[ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN];
|
||||
Arrays.fill(ext_name_bs, (byte) 0);
|
||||
if (file_ext_name != null && file_ext_name.length() > 0) {
|
||||
@@ -747,8 +800,8 @@ public class StorageClient {
|
||||
masterFilenameBytes = master_filename.getBytes(ClientGlobal.g_charset);
|
||||
|
||||
sizeBytes = new byte[2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE];
|
||||
body_len = sizeBytes.length + ProtoCommon.FDFS_FILE_PREFIX_MAX_LEN + ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN
|
||||
+ masterFilenameBytes.length + file_size;
|
||||
body_len = sizeBytes.length + ProtoCommon.FDFS_FILE_PREFIX_MAX_LEN
|
||||
+ ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + masterFilenameBytes.length + file_size;
|
||||
|
||||
hexLenBytes = ProtoCommon.long2buff(master_filename.length());
|
||||
System.arraycopy(hexLenBytes, 0, sizeBytes, 0, hexLenBytes.length);
|
||||
@@ -862,7 +915,7 @@ public class StorageClient {
|
||||
* @return return true for success, false for fail
|
||||
*/
|
||||
protected int do_append_file(String group_name, String appender_filename,
|
||||
long file_size, UploadCallback callback) throws IOException, MyException {
|
||||
long file_size, UploadCallback callback) throws IOException, MyException {
|
||||
byte[] header;
|
||||
boolean bNewStorageServer;
|
||||
Connection connection = null;
|
||||
@@ -955,7 +1008,7 @@ public class StorageClient {
|
||||
* @return return true for success, false for fail
|
||||
*/
|
||||
protected int do_modify_file(String group_name, String appender_filename,
|
||||
long file_offset, long modify_size, UploadCallback callback) throws IOException, MyException {
|
||||
long file_offset, long modify_size, UploadCallback callback) throws IOException, MyException {
|
||||
byte[] header;
|
||||
boolean bNewStorageServer;
|
||||
Connection connection = null;
|
||||
@@ -1081,7 +1134,7 @@ public class StorageClient {
|
||||
* @return 0 for success, none zero for fail (error code)
|
||||
*/
|
||||
public int truncate_file(String group_name, String appender_filename,
|
||||
long truncated_file_size) throws IOException, MyException {
|
||||
long truncated_file_size) throws IOException, MyException {
|
||||
byte[] header;
|
||||
boolean bNewStorageServer;
|
||||
Connection connection = null;
|
||||
@@ -1164,7 +1217,8 @@ public class StorageClient {
|
||||
* @param download_bytes download bytes, 0 for remain bytes from offset
|
||||
* @return file content/buff, return null if fail
|
||||
*/
|
||||
public byte[] download_file(String group_name, String remote_filename, long file_offset, long download_bytes) throws IOException, MyException {
|
||||
public byte[] download_file(String group_name, String remote_filename, long file_offset, long download_bytes)
|
||||
throws IOException, MyException {
|
||||
boolean bNewStorageServer = this.newReadableStorageConnection(group_name, remote_filename);
|
||||
Connection connection = this.storageServer.getConnection();
|
||||
|
||||
@@ -1204,7 +1258,7 @@ public class StorageClient {
|
||||
* @return 0 success, return none zero errno if fail
|
||||
*/
|
||||
public int download_file(String group_name, String remote_filename,
|
||||
String local_filename) throws IOException, MyException {
|
||||
String local_filename) throws IOException, MyException {
|
||||
final long file_offset = 0;
|
||||
final long download_bytes = 0;
|
||||
return this.download_file(group_name, remote_filename,
|
||||
@@ -1222,8 +1276,8 @@ public class StorageClient {
|
||||
* @return 0 success, return none zero errno if fail
|
||||
*/
|
||||
public int download_file(String group_name, String remote_filename,
|
||||
long file_offset, long download_bytes,
|
||||
String local_filename) throws IOException, MyException {
|
||||
long file_offset, long download_bytes,
|
||||
String local_filename) throws IOException, MyException {
|
||||
boolean bNewStorageServer = this.newReadableStorageConnection(group_name, remote_filename);
|
||||
Connection connection = this.storageServer.getConnection();
|
||||
try {
|
||||
@@ -1244,17 +1298,18 @@ public class StorageClient {
|
||||
long remainBytes = header.body_len;
|
||||
int bytes;
|
||||
|
||||
//System.out.println("expect_body_len=" + header.body_len);
|
||||
// System.out.println("expect_body_len=" + header.body_len);
|
||||
|
||||
while (remainBytes > 0) {
|
||||
if ((bytes = in.read(buff, 0, remainBytes > buff.length ? buff.length : (int) remainBytes)) < 0) {
|
||||
throw new IOException("recv package size " + (header.body_len - remainBytes) + " != " + header.body_len);
|
||||
throw new IOException(
|
||||
"recv package size " + (header.body_len - remainBytes) + " != " + header.body_len);
|
||||
}
|
||||
|
||||
out.write(buff, 0, bytes);
|
||||
remainBytes -= bytes;
|
||||
|
||||
//System.out.println("totalBytes=" + (header.body_len - remainBytes));
|
||||
// System.out.println("totalBytes=" + (header.body_len - remainBytes));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1293,7 +1348,7 @@ public class StorageClient {
|
||||
* @return 0 success, return none zero errno if fail
|
||||
*/
|
||||
public int download_file(String group_name, String remote_filename,
|
||||
DownloadCallback callback) throws IOException, MyException {
|
||||
DownloadCallback callback) throws IOException, MyException {
|
||||
final long file_offset = 0;
|
||||
final long download_bytes = 0;
|
||||
return this.download_file(group_name, remote_filename,
|
||||
@@ -1311,8 +1366,8 @@ public class StorageClient {
|
||||
* @return 0 success, return none zero errno if fail
|
||||
*/
|
||||
public int download_file(String group_name, String remote_filename,
|
||||
long file_offset, long download_bytes,
|
||||
DownloadCallback callback) throws IOException, MyException {
|
||||
long file_offset, long download_bytes,
|
||||
DownloadCallback callback) throws IOException, MyException {
|
||||
int result;
|
||||
boolean bNewStorageServer = this.newReadableStorageConnection(group_name, remote_filename);
|
||||
Connection connection = this.storageServer.getConnection();
|
||||
@@ -1332,7 +1387,7 @@ public class StorageClient {
|
||||
long remainBytes = header.body_len;
|
||||
int bytes;
|
||||
|
||||
//System.out.println("expect_body_len=" + header.body_len);
|
||||
// System.out.println("expect_body_len=" + header.body_len);
|
||||
|
||||
while (remainBytes > 0) {
|
||||
if ((bytes = in.read(buff, 0, remainBytes > buff.length ? buff.length : (int) remainBytes)) < 0) {
|
||||
@@ -1345,7 +1400,7 @@ public class StorageClient {
|
||||
}
|
||||
|
||||
remainBytes -= bytes;
|
||||
//System.out.println("totalBytes=" + (header.body_len - remainBytes));
|
||||
// System.out.println("totalBytes=" + (header.body_len - remainBytes));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1407,14 +1462,18 @@ public class StorageClient {
|
||||
* @param remote_filename filename on storage server
|
||||
* @param meta_list meta item array
|
||||
* @param op_flag flag, can be one of following values: <br>
|
||||
* <ul><li> ProtoCommon.STORAGE_SET_METADATA_FLAG_OVERWRITE: overwrite all old
|
||||
* metadata items</li></ul>
|
||||
* <ul><li> ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE: merge, insert when
|
||||
* the metadata item not exist, otherwise update it</li></ul>
|
||||
* <ul>
|
||||
* <li>ProtoCommon.STORAGE_SET_METADATA_FLAG_OVERWRITE:
|
||||
* overwrite all old
|
||||
* metadata items</li>
|
||||
* <li>ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE:
|
||||
* merge, insert when
|
||||
* the metadata item not exist, otherwise update it</li>
|
||||
* </ul>
|
||||
* @return 0 for success, !=0 fail (error code)
|
||||
*/
|
||||
public int set_metadata(String group_name, String remote_filename,
|
||||
NameValuePair[] meta_list, byte op_flag) throws IOException, MyException {
|
||||
NameValuePair[] meta_list, byte op_flag) throws IOException, MyException {
|
||||
boolean bNewStorageServer = this.newUpdatableStorageConnection(group_name, remote_filename);
|
||||
Connection connection = this.storageServer.getConnection();
|
||||
try {
|
||||
@@ -1455,7 +1514,7 @@ public class StorageClient {
|
||||
|
||||
header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_SET_METADATA,
|
||||
2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + 1 + groupBytes.length
|
||||
+ filenameBytes.length + meta_buff.length, (byte) 0);
|
||||
+ filenameBytes.length + meta_buff.length, (byte) 0);
|
||||
OutputStream out = connection.getOutputStream();
|
||||
byte[] wholePkg = new byte[header.length + sizeBytes.length + 1 + groupBytes.length + filenameBytes.length];
|
||||
System.arraycopy(header, 0, wholePkg, 0, header.length);
|
||||
@@ -1517,7 +1576,7 @@ public class StorageClient {
|
||||
}
|
||||
|
||||
if (file_type == FileInfo.FILE_TYPE_SLAVE ||
|
||||
file_type == FileInfo.FILE_TYPE_APPENDER) { //slave file or appender file
|
||||
file_type == FileInfo.FILE_TYPE_APPENDER) { // slave file or appender file
|
||||
FileInfo fi = this.query_file_info(group_name, remote_filename);
|
||||
if (fi == null) {
|
||||
return null;
|
||||
@@ -1529,7 +1588,7 @@ public class StorageClient {
|
||||
|
||||
int create_timestamp = ProtoCommon.buff2int(buff, 4);
|
||||
if ((file_size >> 63) != 0) {
|
||||
file_size &= 0xFFFFFFFFL; //low 32 bits is file size
|
||||
file_size &= 0xFFFFFFFFL; // low 32 bits is file size
|
||||
}
|
||||
int crc32 = ProtoCommon.buff2int(buff, 4 * 4);
|
||||
|
||||
@@ -1619,7 +1678,7 @@ public class StorageClient {
|
||||
TrackerClient tracker = new TrackerClient();
|
||||
this.storageServer = tracker.getStoreStorage(this.trackerServer, group_name);
|
||||
if (this.storageServer == null) {
|
||||
throw new MyException("getStoreStorage fail, errno code: " + tracker.getErrorCode());
|
||||
throw new MyException("getStoreStorage fail, error code: " + tracker.getErrorCode());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1632,7 +1691,8 @@ public class StorageClient {
|
||||
* @param remote_filename filename on storage server
|
||||
* @return true if create a new connection
|
||||
*/
|
||||
protected boolean newReadableStorageConnection(String group_name, String remote_filename) throws IOException, MyException {
|
||||
protected boolean newReadableStorageConnection(String group_name, String remote_filename)
|
||||
throws IOException, MyException {
|
||||
if (this.storageServer != null) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -1652,7 +1712,8 @@ public class StorageClient {
|
||||
* @param remote_filename filename on storage server
|
||||
* @return true if create a new connection
|
||||
*/
|
||||
protected boolean newUpdatableStorageConnection(String group_name, String remote_filename) throws IOException, MyException {
|
||||
protected boolean newUpdatableStorageConnection(String group_name, String remote_filename)
|
||||
throws IOException, MyException {
|
||||
if (this.storageServer != null) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -1672,7 +1733,8 @@ public class StorageClient {
|
||||
* @param group_name the group name of storage server
|
||||
* @param remote_filename filename on storage server
|
||||
*/
|
||||
protected void send_package(byte cmd, String group_name, String remote_filename, Connection connection) throws IOException {
|
||||
protected void send_package(byte cmd, String group_name, String remote_filename, Connection connection)
|
||||
throws IOException {
|
||||
byte[] header;
|
||||
byte[] groupBytes;
|
||||
byte[] filenameBytes;
|
||||
@@ -1793,7 +1855,8 @@ public class StorageClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* send file content callback function, be called only once when the file uploaded
|
||||
* send file content callback function, be called only once when the file
|
||||
* uploaded
|
||||
*
|
||||
* @param out output stream for writing file content
|
||||
* @return 0 success, return none zero(errno) if fail
|
||||
|
||||
@@ -71,6 +71,71 @@ public class TrackerClient {
|
||||
return this.getStoreStorage(trackerServer, groupName);
|
||||
}
|
||||
|
||||
public Connection getConnection(TrackerServer trackerServer) throws IOException, MyException {
|
||||
Connection connection = null;
|
||||
int length = this.tracker_group.tracker_servers.length;
|
||||
boolean failOver = length > 1 && trackerServer == null;
|
||||
try {
|
||||
if (trackerServer == null) {
|
||||
trackerServer = getTrackerServer();
|
||||
if (trackerServer == null) {
|
||||
throw new MyException("tracker server is empty!");
|
||||
}
|
||||
}
|
||||
connection = trackerServer.getConnection();
|
||||
} catch (IOException e) {
|
||||
if (failOver) {
|
||||
System.err.println("trackerServer get connection error, emsg:" + e.getMessage());
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
} catch (MyException e) {
|
||||
if (failOver) {
|
||||
System.err.println("trackerServer get connection error, emsg:" + e.getMessage());
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (connection != null || !failOver) {
|
||||
return connection;
|
||||
}
|
||||
//do fail over
|
||||
int currentIndex = 0;
|
||||
if (trackerServer != null) {
|
||||
currentIndex = trackerServer.getIndex();
|
||||
}
|
||||
int failOverCount = 0;
|
||||
while (failOverCount < length - 1) {
|
||||
failOverCount++;
|
||||
currentIndex++;
|
||||
if (currentIndex >= length) {
|
||||
currentIndex = 0;
|
||||
}
|
||||
try {
|
||||
trackerServer = this.tracker_group.getTrackerServer(currentIndex);
|
||||
if (trackerServer == null) {
|
||||
throw new MyException("tracker server is empty!");
|
||||
}
|
||||
return trackerServer.getConnection();
|
||||
} catch (IOException e) {
|
||||
System.err.println("fail over trackerServer get connection error, failOverCount:" + failOverCount + "," + e.getMessage());
|
||||
if (failOverCount == length - 1) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
} catch (MyException e) {
|
||||
System.err.println("fail over trackerServer get connection error, failOverCount:" + failOverCount + ", " + e.getMessage());
|
||||
if (failOverCount == length - 1) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* query storage server to upload file
|
||||
*
|
||||
@@ -85,12 +150,7 @@ public class TrackerClient {
|
||||
byte cmd;
|
||||
int out_len;
|
||||
byte store_path;
|
||||
Connection connection;
|
||||
|
||||
if (trackerServer == null) {
|
||||
trackerServer = getTrackerServer();
|
||||
}
|
||||
connection = trackerServer.getConnection();
|
||||
Connection connection = getConnection(trackerServer);
|
||||
OutputStream out = connection.getOutputStream();
|
||||
|
||||
try {
|
||||
@@ -170,16 +230,7 @@ public class TrackerClient {
|
||||
int port;
|
||||
byte cmd;
|
||||
int out_len;
|
||||
Connection connection;
|
||||
|
||||
if (trackerServer == null) {
|
||||
trackerServer = getTrackerServer();
|
||||
if (trackerServer == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
connection = trackerServer.getConnection();
|
||||
Connection connection = getConnection(trackerServer);
|
||||
OutputStream out = connection.getOutputStream();
|
||||
|
||||
try {
|
||||
@@ -343,15 +394,7 @@ public class TrackerClient {
|
||||
int len;
|
||||
String ip_addr;
|
||||
int port;
|
||||
Connection connection;
|
||||
|
||||
if (trackerServer == null) {
|
||||
trackerServer = getTrackerServer();
|
||||
if (trackerServer == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
connection = trackerServer.getConnection();
|
||||
Connection connection = getConnection(trackerServer);
|
||||
OutputStream out = connection.getOutputStream();
|
||||
|
||||
try {
|
||||
@@ -473,16 +516,7 @@ public class TrackerClient {
|
||||
byte cmd;
|
||||
int out_len;
|
||||
byte store_path;
|
||||
Connection connection;
|
||||
|
||||
if (trackerServer == null) {
|
||||
trackerServer = getTrackerServer();
|
||||
if (trackerServer == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
connection = trackerServer.getConnection();
|
||||
Connection connection = getConnection(trackerServer);
|
||||
OutputStream out = connection.getOutputStream();
|
||||
|
||||
try {
|
||||
@@ -548,15 +582,7 @@ public class TrackerClient {
|
||||
byte[] bGroupName;
|
||||
byte[] bs;
|
||||
int len;
|
||||
Connection connection;
|
||||
|
||||
if (trackerServer == null) {
|
||||
trackerServer = getTrackerServer();
|
||||
if (trackerServer == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
connection = trackerServer.getConnection();
|
||||
Connection connection = getConnection(trackerServer);
|
||||
OutputStream out = connection.getOutputStream();
|
||||
|
||||
try {
|
||||
|
||||
@@ -18,84 +18,83 @@ import java.net.InetSocketAddress;
|
||||
* @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 getTrackerServer(int serverIndex) throws IOException {
|
||||
return new TrackerServer(this.tracker_servers[serverIndex]);
|
||||
}
|
||||
|
||||
/**
|
||||
* return connected tracker server
|
||||
*
|
||||
* @return connected tracker server, null for fail
|
||||
*/
|
||||
public TrackerServer getTrackerServer() 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.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);
|
||||
/**
|
||||
* 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.getTrackerServer(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,18 @@ import java.net.InetSocketAddress;
|
||||
public class TrackerServer {
|
||||
protected InetSocketAddress inetSockAddr;
|
||||
|
||||
protected int index;
|
||||
|
||||
|
||||
public TrackerServer(InetSocketAddress inetSockAddr) throws IOException {
|
||||
this.inetSockAddr = inetSockAddr;
|
||||
}
|
||||
|
||||
public TrackerServer(InetSocketAddress inetSockAddr, int index) {
|
||||
this.inetSockAddr = inetSockAddr;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public Connection getConnection() throws MyException, IOException {
|
||||
Connection connection;
|
||||
if (ClientGlobal.g_connection_pool_enabled) {
|
||||
@@ -48,4 +55,11 @@ public class TrackerServer {
|
||||
return this.inetSockAddr;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user