feature:add connection pool v2
This commit is contained in:
parent
1336b2b07f
commit
32167310dd
@ -19,5 +19,5 @@ fastdfs.connection_pool.max_count_per_entry = 100
|
|||||||
|
|
||||||
## connections whose the idle time exceeds this time will be closed, unit: second,default value is 60
|
## connections whose the idle time exceeds this time will be closed, unit: second,default value is 60
|
||||||
fastdfs.connection_pool.max_idle_time = 60
|
fastdfs.connection_pool.max_idle_time = 60
|
||||||
## Maximum waiting time when the maximum number of connections is reached, unit: second, default value is 5
|
## Maximum waiting time when the maximum number of connections is reached, unit: Millisecond, default value is 5000
|
||||||
fastdfs.connection_pool.max_wait_time = 5
|
fastdfs.connection_pool.max_wait_time_in_ms = 5000
|
||||||
|
@ -9,7 +9,7 @@ tracker_server = 10.0.11.247:22122
|
|||||||
tracker_server = 10.0.11.248:22122
|
tracker_server = 10.0.11.248:22122
|
||||||
tracker_server = 10.0.11.249:22122
|
tracker_server = 10.0.11.249:22122
|
||||||
|
|
||||||
connection_pool.enabled = false
|
connection_pool.enabled = true
|
||||||
connection_pool.max_count_per_entry = 100
|
connection_pool.max_count_per_entry = 100
|
||||||
connection_pool.max_idle_time = 60
|
connection_pool.max_idle_time = 60
|
||||||
connection_pool.max_wait_time = 5
|
connection_pool.max_wait_time_in_ms = 5000
|
||||||
|
@ -46,7 +46,7 @@ public class ClientGlobal {
|
|||||||
public static final String PROP_KEY_CONNECTION_POOL_ENABLED = "fastdfs.connection_pool.enabled";
|
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_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_IDLE_TIME = "fastdfs.connection_pool.max_idle_time";
|
||||||
public static final String PROP_KEY_CONNECTION_POOL_MAX_WAIT_TIME = "fastdfs.connection_pool.max_wait_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_CONNECT_TIMEOUT = 5; //second
|
||||||
@ -56,10 +56,10 @@ public class ClientGlobal {
|
|||||||
public static final String DEFAULT_HTTP_SECRET_KEY = "FastDFS1234567890";
|
public static final String DEFAULT_HTTP_SECRET_KEY = "FastDFS1234567890";
|
||||||
public static final int DEFAULT_HTTP_TRACKER_HTTP_PORT = 80;
|
public static final int DEFAULT_HTTP_TRACKER_HTTP_PORT = 80;
|
||||||
|
|
||||||
public static final boolean DEFAULT_CONNECTION_POOL_ENABLED = true;
|
public static final boolean DEFAULT_CONNECTION_POOL_ENABLED = false;
|
||||||
public static final int DEFAULT_CONNECTION_POOL_MAX_COUNT_PER_ENTRY = 100;
|
public static final int DEFAULT_CONNECTION_POOL_MAX_COUNT_PER_ENTRY = 100;
|
||||||
public static final int DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME = 60 ;//second
|
public static final int DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME = 60 ;//second
|
||||||
public static final int DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME = 5 ;//second
|
public static final int DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS = 5000 ;//millisecond
|
||||||
|
|
||||||
public static int g_connect_timeout = DEFAULT_CONNECT_TIMEOUT * 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 int g_network_timeout = DEFAULT_NETWORK_TIMEOUT * 1000; //millisecond
|
||||||
@ -71,7 +71,7 @@ public class ClientGlobal {
|
|||||||
public static boolean g_connection_pool_enabled = DEFAULT_CONNECTION_POOL_ENABLED;
|
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_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_idle_time = DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME * 1000; //millisecond
|
||||||
public static int g_connection_pool_max_wait_time = DEFAULT_CONNECTION_POOL_MAX_WAIT_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 TrackerGroup g_tracker_group;
|
public static TrackerGroup g_tracker_group;
|
||||||
|
|
||||||
@ -135,11 +135,10 @@ public class ClientGlobal {
|
|||||||
g_connection_pool_max_idle_time = DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME;
|
g_connection_pool_max_idle_time = DEFAULT_CONNECTION_POOL_MAX_IDLE_TIME;
|
||||||
}
|
}
|
||||||
g_connection_pool_max_idle_time *= 1000;
|
g_connection_pool_max_idle_time *= 1000;
|
||||||
g_connection_pool_max_wait_time = iniReader.getIntValue("connection_pool.max_wait_time", DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME);
|
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 < 0) {
|
if (g_connection_pool_max_wait_time_in_ms < 0) {
|
||||||
g_connection_pool_max_wait_time = DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME;
|
g_connection_pool_max_wait_time_in_ms = DEFAULT_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS;
|
||||||
}
|
}
|
||||||
g_connection_pool_max_wait_time *= 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,7 +179,7 @@ public class ClientGlobal {
|
|||||||
String poolEnabled = props.getProperty(PROP_KEY_CONNECTION_POOL_ENABLED);
|
String poolEnabled = props.getProperty(PROP_KEY_CONNECTION_POOL_ENABLED);
|
||||||
String poolMaxCountPerEntry = props.getProperty(PROP_KEY_CONNECTION_POOL_MAX_COUNT_PER_ENTRY);
|
String poolMaxCountPerEntry = props.getProperty(PROP_KEY_CONNECTION_POOL_MAX_COUNT_PER_ENTRY);
|
||||||
String poolMaxIdleTime = props.getProperty(PROP_KEY_CONNECTION_POOL_MAX_IDLE_TIME);
|
String poolMaxIdleTime = props.getProperty(PROP_KEY_CONNECTION_POOL_MAX_IDLE_TIME);
|
||||||
String poolMaxWaitTime = props.getProperty(PROP_KEY_CONNECTION_POOL_MAX_WAIT_TIME);
|
String poolMaxWaitTimeInMS = props.getProperty(PROP_KEY_CONNECTION_POOL_MAX_WAIT_TIME_IN_MS);
|
||||||
|
|
||||||
if (connectTimeoutInSecondsConf != null && connectTimeoutInSecondsConf.trim().length() != 0) {
|
if (connectTimeoutInSecondsConf != null && connectTimeoutInSecondsConf.trim().length() != 0) {
|
||||||
g_connect_timeout = Integer.parseInt(connectTimeoutInSecondsConf.trim()) * 1000;
|
g_connect_timeout = Integer.parseInt(connectTimeoutInSecondsConf.trim()) * 1000;
|
||||||
@ -209,8 +208,8 @@ public class ClientGlobal {
|
|||||||
if (poolMaxIdleTime != null && poolMaxIdleTime.trim().length() != 0) {
|
if (poolMaxIdleTime != null && poolMaxIdleTime.trim().length() != 0) {
|
||||||
g_connection_pool_max_idle_time = Integer.parseInt(poolMaxIdleTime) * 1000;
|
g_connection_pool_max_idle_time = Integer.parseInt(poolMaxIdleTime) * 1000;
|
||||||
}
|
}
|
||||||
if (poolMaxWaitTime != null && poolMaxWaitTime.trim().length() != 0) {
|
if (poolMaxWaitTimeInMS != null && poolMaxWaitTimeInMS.trim().length() != 0) {
|
||||||
g_connection_pool_max_wait_time = Integer.parseInt(poolMaxWaitTime) * 1000;
|
g_connection_pool_max_wait_time_in_ms = Integer.parseInt(poolMaxWaitTimeInMS) * 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,8 +339,8 @@ public class ClientGlobal {
|
|||||||
return g_connection_pool_max_idle_time;
|
return g_connection_pool_max_idle_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getG_connection_pool_max_wait_time() {
|
public static int getG_connection_pool_max_wait_time_in_ms() {
|
||||||
return g_connection_pool_max_wait_time;
|
return g_connection_pool_max_wait_time_in_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String configInfo() {
|
public static String configInfo() {
|
||||||
@ -363,7 +362,7 @@ public class ClientGlobal {
|
|||||||
+ "\n g_connection_pool_enabled = " + g_connection_pool_enabled
|
+ "\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_count_per_entry = " + g_connection_pool_max_count_per_entry
|
||||||
+ "\n g_connection_pool_max_idle_time = " + g_connection_pool_max_idle_time
|
+ "\n g_connection_pool_max_idle_time = " + g_connection_pool_max_idle_time
|
||||||
+ "\n g_connection_pool_max_wait_time = " + g_connection_pool_max_wait_time
|
+ "\n g_connection_pool_max_wait_time_in_ms = " + g_connection_pool_max_wait_time_in_ms
|
||||||
+ "\n trackerServers = " + trackerServers
|
+ "\n trackerServers = " + trackerServers
|
||||||
+ "\n}";
|
+ "\n}";
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ package org.csource.fastdfs;
|
|||||||
import org.csource.common.Base64;
|
import org.csource.common.Base64;
|
||||||
import org.csource.common.MyException;
|
import org.csource.common.MyException;
|
||||||
import org.csource.common.NameValuePair;
|
import org.csource.common.NameValuePair;
|
||||||
|
import org.csource.fastdfs.pool.Connection;
|
||||||
|
import org.omg.CORBA.CODESET_INCOMPATIBLE;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@ -623,8 +625,8 @@ public class StorageClient {
|
|||||||
*/
|
*/
|
||||||
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;
|
byte[] header;
|
||||||
boolean bNewConnection;
|
boolean bNewStorageServer;
|
||||||
Socket storageSocket;
|
Connection connection = null;
|
||||||
byte[] hexLenBytes;
|
byte[] hexLenBytes;
|
||||||
byte[] appenderFilenameBytes;
|
byte[] appenderFilenameBytes;
|
||||||
int offset;
|
int offset;
|
||||||
@ -636,10 +638,10 @@ public class StorageClient {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
bNewConnection = this.newUpdatableStorageConnection(group_name, appender_filename);
|
bNewStorageServer = this.newUpdatableStorageConnection(group_name, appender_filename);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
storageSocket = this.storageServer.getSocket();
|
connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
appenderFilenameBytes = appender_filename.getBytes(ClientGlobal.g_charset);
|
appenderFilenameBytes = appender_filename.getBytes(ClientGlobal.g_charset);
|
||||||
body_len = appenderFilenameBytes.length;
|
body_len = appenderFilenameBytes.length;
|
||||||
@ -652,10 +654,10 @@ public class StorageClient {
|
|||||||
System.arraycopy(appenderFilenameBytes, 0, wholePkg, offset, appenderFilenameBytes.length);
|
System.arraycopy(appenderFilenameBytes, 0, wholePkg, offset, appenderFilenameBytes.length);
|
||||||
offset += appenderFilenameBytes.length;
|
offset += appenderFilenameBytes.length;
|
||||||
|
|
||||||
OutputStream out = storageSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
out.write(wholePkg);
|
out.write(wholePkg);
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
if (pkgInfo.errno != 0) {
|
if (pkgInfo.errno != 0) {
|
||||||
@ -675,27 +677,16 @@ public class StorageClient {
|
|||||||
|
|
||||||
return results;
|
return results;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,8 +713,8 @@ public class StorageClient {
|
|||||||
byte[] ext_name_bs;
|
byte[] ext_name_bs;
|
||||||
String new_group_name;
|
String new_group_name;
|
||||||
String remote_filename;
|
String remote_filename;
|
||||||
boolean bNewConnection;
|
boolean bNewStorageServer;
|
||||||
Socket storageSocket;
|
Connection connection = null;
|
||||||
byte[] sizeBytes;
|
byte[] sizeBytes;
|
||||||
byte[] hexLenBytes;
|
byte[] hexLenBytes;
|
||||||
byte[] masterFilenameBytes;
|
byte[] masterFilenameBytes;
|
||||||
@ -735,13 +726,13 @@ public class StorageClient {
|
|||||||
(master_filename != null && master_filename.length() > 0) &&
|
(master_filename != null && master_filename.length() > 0) &&
|
||||||
(prefix_name != null));
|
(prefix_name != null));
|
||||||
if (bUploadSlave) {
|
if (bUploadSlave) {
|
||||||
bNewConnection = this.newUpdatableStorageConnection(group_name, master_filename);
|
bNewStorageServer = this.newUpdatableStorageConnection(group_name, master_filename);
|
||||||
} else {
|
} else {
|
||||||
bNewConnection = this.newWritableStorageConnection(group_name);
|
bNewStorageServer = this.newWritableStorageConnection(group_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
storageSocket = this.storageServer.getSocket();
|
connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
ext_name_bs = new byte[ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN];
|
ext_name_bs = new byte[ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN];
|
||||||
Arrays.fill(ext_name_bs, (byte) 0);
|
Arrays.fill(ext_name_bs, (byte) 0);
|
||||||
@ -776,7 +767,7 @@ public class StorageClient {
|
|||||||
hexLenBytes = ProtoCommon.long2buff(file_size);
|
hexLenBytes = ProtoCommon.long2buff(file_size);
|
||||||
System.arraycopy(hexLenBytes, 0, sizeBytes, offset, hexLenBytes.length);
|
System.arraycopy(hexLenBytes, 0, sizeBytes, offset, hexLenBytes.length);
|
||||||
|
|
||||||
OutputStream out = storageSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
header = ProtoCommon.packHeader(cmd, body_len, (byte) 0);
|
header = ProtoCommon.packHeader(cmd, body_len, (byte) 0);
|
||||||
byte[] wholePkg = new byte[(int) (header.length + body_len - file_size)];
|
byte[] wholePkg = new byte[(int) (header.length + body_len - file_size)];
|
||||||
System.arraycopy(header, 0, wholePkg, 0, header.length);
|
System.arraycopy(header, 0, wholePkg, 0, header.length);
|
||||||
@ -812,7 +803,7 @@ public class StorageClient {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
if (pkgInfo.errno != 0) {
|
if (pkgInfo.errno != 0) {
|
||||||
@ -847,30 +838,19 @@ public class StorageClient {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,8 +866,8 @@ public class StorageClient {
|
|||||||
protected int do_append_file(String group_name, String appender_filename,
|
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;
|
byte[] header;
|
||||||
boolean bNewConnection;
|
boolean bNewStorageServer;
|
||||||
Socket storageSocket;
|
Connection connection = null;
|
||||||
byte[] hexLenBytes;
|
byte[] hexLenBytes;
|
||||||
byte[] appenderFilenameBytes;
|
byte[] appenderFilenameBytes;
|
||||||
int offset;
|
int offset;
|
||||||
@ -899,10 +879,10 @@ public class StorageClient {
|
|||||||
return this.errno;
|
return this.errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
bNewConnection = this.newUpdatableStorageConnection(group_name, appender_filename);
|
bNewStorageServer = this.newUpdatableStorageConnection(group_name, appender_filename);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
storageSocket = this.storageServer.getSocket();
|
connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
appenderFilenameBytes = appender_filename.getBytes(ClientGlobal.g_charset);
|
appenderFilenameBytes = appender_filename.getBytes(ClientGlobal.g_charset);
|
||||||
body_len = 2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + appenderFilenameBytes.length + file_size;
|
body_len = 2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + appenderFilenameBytes.length + file_size;
|
||||||
@ -920,7 +900,7 @@ public class StorageClient {
|
|||||||
System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length);
|
System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length);
|
||||||
offset += hexLenBytes.length;
|
offset += hexLenBytes.length;
|
||||||
|
|
||||||
OutputStream out = storageSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
|
|
||||||
System.arraycopy(appenderFilenameBytes, 0, wholePkg, offset, appenderFilenameBytes.length);
|
System.arraycopy(appenderFilenameBytes, 0, wholePkg, offset, appenderFilenameBytes.length);
|
||||||
offset += appenderFilenameBytes.length;
|
offset += appenderFilenameBytes.length;
|
||||||
@ -930,7 +910,7 @@ public class StorageClient {
|
|||||||
return this.errno;
|
return this.errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
if (pkgInfo.errno != 0) {
|
if (pkgInfo.errno != 0) {
|
||||||
@ -939,29 +919,32 @@ public class StorageClient {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
|
}
|
||||||
|
throw ex;
|
||||||
|
} finally {
|
||||||
|
doFinally(connection, bNewStorageServer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw ex;
|
private void doFinally(Connection connection, boolean bNewStorageServer) {
|
||||||
} finally {
|
|
||||||
if (bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
if (connection != null) {
|
||||||
|
this.storageServer.releaseConnection(connection);
|
||||||
|
}
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
|
if (bNewStorageServer) {
|
||||||
this.storageServer = null;
|
this.storageServer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* modify appender file to storage server
|
* modify appender file to storage server
|
||||||
@ -976,8 +959,8 @@ public class StorageClient {
|
|||||||
protected int do_modify_file(String group_name, String appender_filename,
|
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;
|
byte[] header;
|
||||||
boolean bNewConnection;
|
boolean bNewStorageServer;
|
||||||
Socket storageSocket;
|
Connection connection = null;
|
||||||
byte[] hexLenBytes;
|
byte[] hexLenBytes;
|
||||||
byte[] appenderFilenameBytes;
|
byte[] appenderFilenameBytes;
|
||||||
int offset;
|
int offset;
|
||||||
@ -989,10 +972,10 @@ public class StorageClient {
|
|||||||
return this.errno;
|
return this.errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
bNewConnection = this.newUpdatableStorageConnection(group_name, appender_filename);
|
bNewStorageServer = this.newUpdatableStorageConnection(group_name, appender_filename);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
storageSocket = this.storageServer.getSocket();
|
connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
appenderFilenameBytes = appender_filename.getBytes(ClientGlobal.g_charset);
|
appenderFilenameBytes = appender_filename.getBytes(ClientGlobal.g_charset);
|
||||||
body_len = 3 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + appenderFilenameBytes.length + modify_size;
|
body_len = 3 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + appenderFilenameBytes.length + modify_size;
|
||||||
@ -1014,7 +997,7 @@ public class StorageClient {
|
|||||||
System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length);
|
System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length);
|
||||||
offset += hexLenBytes.length;
|
offset += hexLenBytes.length;
|
||||||
|
|
||||||
OutputStream out = storageSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
|
|
||||||
System.arraycopy(appenderFilenameBytes, 0, wholePkg, offset, appenderFilenameBytes.length);
|
System.arraycopy(appenderFilenameBytes, 0, wholePkg, offset, appenderFilenameBytes.length);
|
||||||
offset += appenderFilenameBytes.length;
|
offset += appenderFilenameBytes.length;
|
||||||
@ -1024,7 +1007,7 @@ public class StorageClient {
|
|||||||
return this.errno;
|
return this.errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
if (pkgInfo.errno != 0) {
|
if (pkgInfo.errno != 0) {
|
||||||
@ -1033,27 +1016,17 @@ public class StorageClient {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1065,38 +1038,27 @@ public class StorageClient {
|
|||||||
* @return 0 for success, none zero for fail (error code)
|
* @return 0 for success, none zero for fail (error code)
|
||||||
*/
|
*/
|
||||||
public int delete_file(String group_name, String remote_filename) throws IOException, MyException {
|
public int delete_file(String group_name, String remote_filename) throws IOException, MyException {
|
||||||
boolean bNewConnection = this.newUpdatableStorageConnection(group_name, remote_filename);
|
boolean bNewStorageServer = this.newUpdatableStorageConnection(group_name, remote_filename);
|
||||||
Socket storageSocket = this.storageServer.getSocket();
|
Connection connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.send_package(ProtoCommon.STORAGE_PROTO_CMD_DELETE_FILE, group_name, remote_filename);
|
this.send_package(ProtoCommon.STORAGE_PROTO_CMD_DELETE_FILE, group_name, remote_filename, connection);
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
||||||
|
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
return pkgInfo.errno;
|
return pkgInfo.errno;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1123,8 +1085,8 @@ public class StorageClient {
|
|||||||
public int truncate_file(String group_name, String appender_filename,
|
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;
|
byte[] header;
|
||||||
boolean bNewConnection;
|
boolean bNewStorageServer;
|
||||||
Socket storageSocket;
|
Connection connection = null;
|
||||||
byte[] hexLenBytes;
|
byte[] hexLenBytes;
|
||||||
byte[] appenderFilenameBytes;
|
byte[] appenderFilenameBytes;
|
||||||
int offset;
|
int offset;
|
||||||
@ -1136,10 +1098,10 @@ public class StorageClient {
|
|||||||
return this.errno;
|
return this.errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
bNewConnection = this.newUpdatableStorageConnection(group_name, appender_filename);
|
bNewStorageServer = this.newUpdatableStorageConnection(group_name, appender_filename);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
storageSocket = this.storageServer.getSocket();
|
connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
appenderFilenameBytes = appender_filename.getBytes(ClientGlobal.g_charset);
|
appenderFilenameBytes = appender_filename.getBytes(ClientGlobal.g_charset);
|
||||||
body_len = 2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + appenderFilenameBytes.length;
|
body_len = 2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + appenderFilenameBytes.length;
|
||||||
@ -1157,38 +1119,27 @@ public class StorageClient {
|
|||||||
System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length);
|
System.arraycopy(hexLenBytes, 0, wholePkg, offset, hexLenBytes.length);
|
||||||
offset += hexLenBytes.length;
|
offset += hexLenBytes.length;
|
||||||
|
|
||||||
OutputStream out = storageSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
|
|
||||||
System.arraycopy(appenderFilenameBytes, 0, wholePkg, offset, appenderFilenameBytes.length);
|
System.arraycopy(appenderFilenameBytes, 0, wholePkg, offset, appenderFilenameBytes.length);
|
||||||
offset += appenderFilenameBytes.length;
|
offset += appenderFilenameBytes.length;
|
||||||
|
|
||||||
out.write(wholePkg);
|
out.write(wholePkg);
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
return pkgInfo.errno;
|
return pkgInfo.errno;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1216,14 +1167,14 @@ public class StorageClient {
|
|||||||
* @return file content/buff, return null if fail
|
* @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 bNewConnection = this.newReadableStorageConnection(group_name, remote_filename);
|
boolean bNewStorageServer = this.newReadableStorageConnection(group_name, remote_filename);
|
||||||
Socket storageSocket = this.storageServer.getSocket();
|
Connection connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo;
|
ProtoCommon.RecvPackageInfo pkgInfo;
|
||||||
|
|
||||||
this.send_download_package(group_name, remote_filename, file_offset, download_bytes);
|
this.send_download_package(group_name, remote_filename, file_offset, download_bytes, connection);
|
||||||
pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
||||||
|
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
@ -1233,27 +1184,16 @@ public class StorageClient {
|
|||||||
|
|
||||||
return pkgInfo.body;
|
return pkgInfo.body;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1286,16 +1226,16 @@ public class StorageClient {
|
|||||||
public int download_file(String group_name, String remote_filename,
|
public int download_file(String group_name, String remote_filename,
|
||||||
long file_offset, long download_bytes,
|
long file_offset, long download_bytes,
|
||||||
String local_filename) throws IOException, MyException {
|
String local_filename) throws IOException, MyException {
|
||||||
boolean bNewConnection = this.newReadableStorageConnection(group_name, remote_filename);
|
boolean bNewStorageServer = this.newReadableStorageConnection(group_name, remote_filename);
|
||||||
Socket storageSocket = this.storageServer.getSocket();
|
Connection connection = this.storageServer.getConnection();
|
||||||
try {
|
try {
|
||||||
ProtoCommon.RecvHeaderInfo header;
|
ProtoCommon.RecvHeaderInfo header;
|
||||||
FileOutputStream out = new FileOutputStream(local_filename);
|
FileOutputStream out = new FileOutputStream(local_filename);
|
||||||
try {
|
try {
|
||||||
this.errno = 0;
|
this.errno = 0;
|
||||||
this.send_download_package(group_name, remote_filename, file_offset, download_bytes);
|
this.send_download_package(group_name, remote_filename, file_offset, download_bytes, connection);
|
||||||
|
|
||||||
InputStream in = storageSocket.getInputStream();
|
InputStream in = connection.getInputStream();
|
||||||
header = ProtoCommon.recvHeader(in, ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
header = ProtoCommon.recvHeader(in, ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
||||||
this.errno = header.errno;
|
this.errno = header.errno;
|
||||||
if (header.errno != 0) {
|
if (header.errno != 0) {
|
||||||
@ -1333,27 +1273,16 @@ public class StorageClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1387,14 +1316,14 @@ public class StorageClient {
|
|||||||
long file_offset, long download_bytes,
|
long file_offset, long download_bytes,
|
||||||
DownloadCallback callback) throws IOException, MyException {
|
DownloadCallback callback) throws IOException, MyException {
|
||||||
int result;
|
int result;
|
||||||
boolean bNewConnection = this.newReadableStorageConnection(group_name, remote_filename);
|
boolean bNewStorageServer = this.newReadableStorageConnection(group_name, remote_filename);
|
||||||
Socket storageSocket = this.storageServer.getSocket();
|
Connection connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProtoCommon.RecvHeaderInfo header;
|
ProtoCommon.RecvHeaderInfo header;
|
||||||
this.send_download_package(group_name, remote_filename, file_offset, download_bytes);
|
this.send_download_package(group_name, remote_filename, file_offset, download_bytes, connection);
|
||||||
|
|
||||||
InputStream in = storageSocket.getInputStream();
|
InputStream in = connection.getInputStream();
|
||||||
header = ProtoCommon.recvHeader(in, ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
header = ProtoCommon.recvHeader(in, ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
||||||
this.errno = header.errno;
|
this.errno = header.errno;
|
||||||
if (header.errno != 0) {
|
if (header.errno != 0) {
|
||||||
@ -1423,27 +1352,16 @@ public class StorageClient {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1455,14 +1373,13 @@ public class StorageClient {
|
|||||||
* @return meta info array, return null if fail
|
* @return meta info array, return null if fail
|
||||||
*/
|
*/
|
||||||
public NameValuePair[] get_metadata(String group_name, String remote_filename) throws IOException, MyException {
|
public NameValuePair[] get_metadata(String group_name, String remote_filename) throws IOException, MyException {
|
||||||
boolean bNewConnection = this.newUpdatableStorageConnection(group_name, remote_filename);
|
boolean bNewStorageServer = this.newUpdatableStorageConnection(group_name, remote_filename);
|
||||||
Socket storageSocket = this.storageServer.getSocket();
|
Connection connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo;
|
ProtoCommon.RecvPackageInfo pkgInfo;
|
||||||
|
|
||||||
this.send_package(ProtoCommon.STORAGE_PROTO_CMD_GET_METADATA, group_name, remote_filename);
|
this.send_package(ProtoCommon.STORAGE_PROTO_CMD_GET_METADATA, group_name, remote_filename, connection);
|
||||||
pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
ProtoCommon.STORAGE_PROTO_CMD_RESP, -1);
|
||||||
|
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
@ -1472,27 +1389,16 @@ public class StorageClient {
|
|||||||
|
|
||||||
return ProtoCommon.split_metadata(new String(pkgInfo.body, ClientGlobal.g_charset));
|
return ProtoCommon.split_metadata(new String(pkgInfo.body, ClientGlobal.g_charset));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1511,9 +1417,8 @@ public class StorageClient {
|
|||||||
*/
|
*/
|
||||||
public int set_metadata(String group_name, String remote_filename,
|
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 bNewConnection = this.newUpdatableStorageConnection(group_name, remote_filename);
|
boolean bNewStorageServer = this.newUpdatableStorageConnection(group_name, remote_filename);
|
||||||
Socket storageSocket = this.storageServer.getSocket();
|
Connection connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
byte[] groupBytes;
|
byte[] groupBytes;
|
||||||
@ -1553,7 +1458,7 @@ public class StorageClient {
|
|||||||
header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_SET_METADATA,
|
header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_SET_METADATA,
|
||||||
2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + 1 + groupBytes.length
|
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 = storageSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
byte[] wholePkg = new byte[header.length + sizeBytes.length + 1 + groupBytes.length + filenameBytes.length];
|
byte[] wholePkg = new byte[header.length + sizeBytes.length + 1 + groupBytes.length + filenameBytes.length];
|
||||||
System.arraycopy(header, 0, wholePkg, 0, header.length);
|
System.arraycopy(header, 0, wholePkg, 0, header.length);
|
||||||
System.arraycopy(sizeBytes, 0, wholePkg, header.length, sizeBytes.length);
|
System.arraycopy(sizeBytes, 0, wholePkg, header.length, sizeBytes.length);
|
||||||
@ -1565,33 +1470,22 @@ public class StorageClient {
|
|||||||
out.write(meta_buff);
|
out.write(meta_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
ProtoCommon.STORAGE_PROTO_CMD_RESP, 0);
|
||||||
|
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
return pkgInfo.errno;
|
return pkgInfo.errno;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1614,23 +1508,18 @@ public class StorageClient {
|
|||||||
|
|
||||||
short file_type;
|
short file_type;
|
||||||
long file_size = ProtoCommon.buff2long(buff, 4 * 2);
|
long file_size = ProtoCommon.buff2long(buff, 4 * 2);
|
||||||
if (((file_size & ProtoCommon.APPENDER_FILE_SIZE) != 0))
|
if (((file_size & ProtoCommon.APPENDER_FILE_SIZE) != 0)) {
|
||||||
{
|
|
||||||
file_type = FileInfo.FILE_TYPE_APPENDER;
|
file_type = FileInfo.FILE_TYPE_APPENDER;
|
||||||
}
|
} else if ((remote_filename.length() > ProtoCommon.TRUNK_LOGIC_FILENAME_LENGTH) ||
|
||||||
else if ((remote_filename.length() > ProtoCommon.TRUNK_LOGIC_FILENAME_LENGTH) ||
|
|
||||||
((remote_filename.length() > ProtoCommon.NORMAL_LOGIC_FILENAME_LENGTH) &&
|
((remote_filename.length() > ProtoCommon.NORMAL_LOGIC_FILENAME_LENGTH) &&
|
||||||
((file_size & ProtoCommon.TRUNK_FILE_MARK_SIZE) == 0)))
|
((file_size & ProtoCommon.TRUNK_FILE_MARK_SIZE) == 0))) {
|
||||||
{
|
|
||||||
file_type = FileInfo.FILE_TYPE_SLAVE;
|
file_type = FileInfo.FILE_TYPE_SLAVE;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
file_type = FileInfo.FILE_TYPE_NORMAL;
|
file_type = FileInfo.FILE_TYPE_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_type == FileInfo.FILE_TYPE_SLAVE ||
|
if (file_type == FileInfo.FILE_TYPE_SLAVE ||
|
||||||
file_type == FileInfo.FILE_TYPE_APPENDER)
|
file_type == FileInfo.FILE_TYPE_APPENDER) { //slave file or appender file
|
||||||
{ //slave file or appender file
|
|
||||||
FileInfo fi = this.query_file_info(group_name, remote_filename);
|
FileInfo fi = this.query_file_info(group_name, remote_filename);
|
||||||
if (fi == null) {
|
if (fi == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -1658,9 +1547,8 @@ public class StorageClient {
|
|||||||
* @return FileInfo object for success, return null for fail
|
* @return FileInfo object for success, return null for fail
|
||||||
*/
|
*/
|
||||||
public FileInfo query_file_info(String group_name, String remote_filename) throws IOException, MyException {
|
public FileInfo query_file_info(String group_name, String remote_filename) throws IOException, MyException {
|
||||||
boolean bNewConnection = this.newUpdatableStorageConnection(group_name, remote_filename);
|
boolean bNewStorageServer = this.newUpdatableStorageConnection(group_name, remote_filename);
|
||||||
Socket storageSocket = this.storageServer.getSocket();
|
Connection connection = this.storageServer.getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
byte[] groupBytes;
|
byte[] groupBytes;
|
||||||
@ -1683,14 +1571,14 @@ public class StorageClient {
|
|||||||
|
|
||||||
header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_QUERY_FILE_INFO,
|
header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_QUERY_FILE_INFO,
|
||||||
+groupBytes.length + filenameBytes.length, (byte) 0);
|
+groupBytes.length + filenameBytes.length, (byte) 0);
|
||||||
OutputStream out = storageSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
byte[] wholePkg = new byte[header.length + groupBytes.length + filenameBytes.length];
|
byte[] wholePkg = new byte[header.length + groupBytes.length + filenameBytes.length];
|
||||||
System.arraycopy(header, 0, wholePkg, 0, header.length);
|
System.arraycopy(header, 0, wholePkg, 0, header.length);
|
||||||
System.arraycopy(groupBytes, 0, wholePkg, header.length, groupBytes.length);
|
System.arraycopy(groupBytes, 0, wholePkg, header.length, groupBytes.length);
|
||||||
System.arraycopy(filenameBytes, 0, wholePkg, header.length + groupBytes.length, filenameBytes.length);
|
System.arraycopy(filenameBytes, 0, wholePkg, header.length + groupBytes.length, filenameBytes.length);
|
||||||
out.write(wholePkg);
|
out.write(wholePkg);
|
||||||
|
|
||||||
pkgInfo = ProtoCommon.recvPackage(storageSocket.getInputStream(),
|
pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.STORAGE_PROTO_CMD_RESP,
|
ProtoCommon.STORAGE_PROTO_CMD_RESP,
|
||||||
3 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE +
|
3 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE +
|
||||||
ProtoCommon.FDFS_IPADDR_SIZE);
|
ProtoCommon.FDFS_IPADDR_SIZE);
|
||||||
@ -1707,27 +1595,16 @@ public class StorageClient {
|
|||||||
return new FileInfo(true, FileInfo.FILE_TYPE_NORMAL, file_size,
|
return new FileInfo(true, FileInfo.FILE_TYPE_NORMAL, file_size,
|
||||||
create_timestamp, crc32, source_ip_addr);
|
create_timestamp, crc32, source_ip_addr);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
this.storageServer.close();
|
this.storageServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
this.storageServer = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
doFinally(connection, bNewStorageServer);
|
||||||
try {
|
|
||||||
this.storageServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
this.storageServer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1797,7 +1674,7 @@ public class StorageClient {
|
|||||||
* @param group_name the group name of storage server
|
* @param group_name the group name of storage server
|
||||||
* @param remote_filename filename on storage server
|
* @param remote_filename filename on storage server
|
||||||
*/
|
*/
|
||||||
protected void send_package(byte cmd, String group_name, String remote_filename) throws IOException {
|
protected void send_package(byte cmd, String group_name, String remote_filename, Connection connection) throws IOException {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
byte[] groupBytes;
|
byte[] groupBytes;
|
||||||
byte[] filenameBytes;
|
byte[] filenameBytes;
|
||||||
@ -1821,7 +1698,7 @@ public class StorageClient {
|
|||||||
System.arraycopy(header, 0, wholePkg, 0, header.length);
|
System.arraycopy(header, 0, wholePkg, 0, header.length);
|
||||||
System.arraycopy(groupBytes, 0, wholePkg, header.length, groupBytes.length);
|
System.arraycopy(groupBytes, 0, wholePkg, header.length, groupBytes.length);
|
||||||
System.arraycopy(filenameBytes, 0, wholePkg, header.length + groupBytes.length, filenameBytes.length);
|
System.arraycopy(filenameBytes, 0, wholePkg, header.length + groupBytes.length, filenameBytes.length);
|
||||||
this.storageServer.getSocket().getOutputStream().write(wholePkg);
|
connection.getOutputStream().write(wholePkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1832,7 +1709,7 @@ public class StorageClient {
|
|||||||
* @param file_offset the start offset of the file
|
* @param file_offset the start offset of the file
|
||||||
* @param download_bytes download bytes
|
* @param download_bytes download bytes
|
||||||
*/
|
*/
|
||||||
protected void send_download_package(String group_name, String remote_filename, long file_offset, long download_bytes) throws IOException {
|
protected void send_download_package(String group_name, String remote_filename, long file_offset, long download_bytes, Connection connection) throws IOException {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
byte[] bsOffset;
|
byte[] bsOffset;
|
||||||
byte[] bsDownBytes;
|
byte[] bsDownBytes;
|
||||||
@ -1863,19 +1740,19 @@ public class StorageClient {
|
|||||||
System.arraycopy(bsDownBytes, 0, wholePkg, header.length + bsOffset.length, bsDownBytes.length);
|
System.arraycopy(bsDownBytes, 0, wholePkg, header.length + bsOffset.length, bsDownBytes.length);
|
||||||
System.arraycopy(groupBytes, 0, wholePkg, header.length + bsOffset.length + bsDownBytes.length, groupBytes.length);
|
System.arraycopy(groupBytes, 0, wholePkg, header.length + bsOffset.length + bsDownBytes.length, groupBytes.length);
|
||||||
System.arraycopy(filenameBytes, 0, wholePkg, header.length + bsOffset.length + bsDownBytes.length + groupBytes.length, filenameBytes.length);
|
System.arraycopy(filenameBytes, 0, wholePkg, header.length + bsOffset.length + bsDownBytes.length + groupBytes.length, filenameBytes.length);
|
||||||
this.storageServer.getSocket().getOutputStream().write(wholePkg);
|
connection.getOutputStream().write(wholePkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConnected(){
|
public boolean isConnected() {
|
||||||
return trackerServer.isConnected();
|
return trackerServer != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAvaliable(){
|
public boolean isAvaliable() {
|
||||||
return trackerServer.isAvaliable();
|
return trackerServer != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
trackerServer.close();
|
trackerServer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrackerServer getTrackerServer() {
|
public TrackerServer getTrackerServer() {
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
|
import org.csource.common.MyException;
|
||||||
|
import org.csource.fastdfs.pool.Connection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@ -54,8 +57,8 @@ public class TrackerClient {
|
|||||||
*
|
*
|
||||||
* @return tracker server Socket object, return null if fail
|
* @return tracker server Socket object, return null if fail
|
||||||
*/
|
*/
|
||||||
public TrackerServer getConnection() throws IOException {
|
public TrackerServer getTrackerServer() throws IOException {
|
||||||
return this.tracker_group.getConnection();
|
return this.tracker_group.getTrackerServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,7 +67,7 @@ public class TrackerClient {
|
|||||||
* @param trackerServer the tracker server
|
* @param trackerServer the tracker server
|
||||||
* @return storage server Socket object, return null if fail
|
* @return storage server Socket object, return null if fail
|
||||||
*/
|
*/
|
||||||
public StorageServer getStoreStorage(TrackerServer trackerServer) throws IOException {
|
public StorageServer getStoreStorage(TrackerServer trackerServer) throws IOException, MyException {
|
||||||
final String groupName = null;
|
final String groupName = null;
|
||||||
return this.getStoreStorage(trackerServer, groupName);
|
return this.getStoreStorage(trackerServer, groupName);
|
||||||
}
|
}
|
||||||
@ -76,28 +79,20 @@ public class TrackerClient {
|
|||||||
* @param groupName the group name to upload file to, can be empty
|
* @param groupName the group name to upload file to, can be empty
|
||||||
* @return storage server object, return null if fail
|
* @return storage server object, return null if fail
|
||||||
*/
|
*/
|
||||||
public StorageServer getStoreStorage(TrackerServer trackerServer, String groupName) throws IOException {
|
public StorageServer getStoreStorage(TrackerServer trackerServer, String groupName) throws IOException, MyException {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
String ip_addr;
|
String ip_addr;
|
||||||
int port;
|
int port;
|
||||||
byte cmd;
|
byte cmd;
|
||||||
int out_len;
|
int out_len;
|
||||||
boolean bNewConnection;
|
|
||||||
byte store_path;
|
byte store_path;
|
||||||
Socket trackerSocket;
|
Connection connection;
|
||||||
|
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
trackerServer = getConnection();
|
trackerServer = getTrackerServer();
|
||||||
if (trackerServer == null) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
bNewConnection = true;
|
connection = trackerServer.getConnection();
|
||||||
} else {
|
OutputStream out = connection.getOutputStream();
|
||||||
bNewConnection = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
trackerSocket = trackerServer.getSocket();
|
|
||||||
OutputStream out = trackerSocket.getOutputStream();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (groupName == null || groupName.length() == 0) {
|
if (groupName == null || groupName.length() == 0) {
|
||||||
@ -128,7 +123,7 @@ public class TrackerClient {
|
|||||||
out.write(bGroupName);
|
out.write(bGroupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(trackerSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.TRACKER_PROTO_CMD_RESP,
|
ProtoCommon.TRACKER_PROTO_CMD_RESP,
|
||||||
ProtoCommon.TRACKER_QUERY_STORAGE_STORE_BODY_LEN);
|
ProtoCommon.TRACKER_QUERY_STORAGE_STORE_BODY_LEN);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
@ -144,19 +139,18 @@ public class TrackerClient {
|
|||||||
|
|
||||||
return new StorageServer(ip_addr, port, store_path);
|
return new StorageServer(ip_addr, port, store_path);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
if (connection != null) {
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.releaseConnection(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -171,27 +165,23 @@ public class TrackerClient {
|
|||||||
* @param groupName the group name to upload file to, can be empty
|
* @param groupName the group name to upload file to, can be empty
|
||||||
* @return storage servers, return null if fail
|
* @return storage servers, return null if fail
|
||||||
*/
|
*/
|
||||||
public StorageServer[] getStoreStorages(TrackerServer trackerServer, String groupName) throws IOException {
|
public StorageServer[] getStoreStorages(TrackerServer trackerServer, String groupName) throws IOException, MyException {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
String ip_addr;
|
String ip_addr;
|
||||||
int port;
|
int port;
|
||||||
byte cmd;
|
byte cmd;
|
||||||
int out_len;
|
int out_len;
|
||||||
boolean bNewConnection;
|
Connection connection;
|
||||||
Socket trackerSocket;
|
|
||||||
|
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
trackerServer = getConnection();
|
trackerServer = getTrackerServer();
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bNewConnection = true;
|
|
||||||
} else {
|
|
||||||
bNewConnection = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trackerSocket = trackerServer.getSocket();
|
connection = trackerServer.getConnection();
|
||||||
OutputStream out = trackerSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (groupName == null || groupName.length() == 0) {
|
if (groupName == null || groupName.length() == 0) {
|
||||||
@ -222,7 +212,7 @@ public class TrackerClient {
|
|||||||
out.write(bGroupName);
|
out.write(bGroupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(trackerSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.TRACKER_PROTO_CMD_RESP, -1);
|
ProtoCommon.TRACKER_PROTO_CMD_RESP, -1);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
if (pkgInfo.errno != 0) {
|
if (pkgInfo.errno != 0) {
|
||||||
@ -264,19 +254,18 @@ public class TrackerClient {
|
|||||||
|
|
||||||
return results;
|
return results;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
if (connection != null) {
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.releaseConnection(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -293,7 +282,7 @@ public class TrackerClient {
|
|||||||
* @return storage server Socket object, return null if fail
|
* @return storage server Socket object, return null if fail
|
||||||
*/
|
*/
|
||||||
public StorageServer getFetchStorage(TrackerServer trackerServer,
|
public StorageServer getFetchStorage(TrackerServer trackerServer,
|
||||||
String groupName, String filename) throws IOException {
|
String groupName, String filename) throws IOException, MyException {
|
||||||
ServerInfo[] servers = this.getStorages(trackerServer, ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_FETCH_ONE,
|
ServerInfo[] servers = this.getStorages(trackerServer, ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_FETCH_ONE,
|
||||||
groupName, filename);
|
groupName, filename);
|
||||||
if (servers == null) {
|
if (servers == null) {
|
||||||
@ -312,7 +301,7 @@ public class TrackerClient {
|
|||||||
* @return storage server Socket object, return null if fail
|
* @return storage server Socket object, return null if fail
|
||||||
*/
|
*/
|
||||||
public StorageServer getUpdateStorage(TrackerServer trackerServer,
|
public StorageServer getUpdateStorage(TrackerServer trackerServer,
|
||||||
String groupName, String filename) throws IOException {
|
String groupName, String filename) throws IOException, MyException {
|
||||||
ServerInfo[] servers = this.getStorages(trackerServer, ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_UPDATE,
|
ServerInfo[] servers = this.getStorages(trackerServer, ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_UPDATE,
|
||||||
groupName, filename);
|
groupName, filename);
|
||||||
if (servers == null) {
|
if (servers == null) {
|
||||||
@ -331,7 +320,7 @@ public class TrackerClient {
|
|||||||
* @return storage servers, return null if fail
|
* @return storage servers, return null if fail
|
||||||
*/
|
*/
|
||||||
public ServerInfo[] getFetchStorages(TrackerServer trackerServer,
|
public ServerInfo[] getFetchStorages(TrackerServer trackerServer,
|
||||||
String groupName, String filename) throws IOException {
|
String groupName, String filename) throws IOException, MyException {
|
||||||
return this.getStorages(trackerServer, ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_FETCH_ALL,
|
return this.getStorages(trackerServer, ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_FETCH_ALL,
|
||||||
groupName, filename);
|
groupName, filename);
|
||||||
}
|
}
|
||||||
@ -347,7 +336,7 @@ public class TrackerClient {
|
|||||||
* @return storage server Socket object, return null if fail
|
* @return storage server Socket object, return null if fail
|
||||||
*/
|
*/
|
||||||
protected ServerInfo[] getStorages(TrackerServer trackerServer,
|
protected ServerInfo[] getStorages(TrackerServer trackerServer,
|
||||||
byte cmd, String groupName, String filename) throws IOException {
|
byte cmd, String groupName, String filename) throws IOException, MyException {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
byte[] bFileName;
|
byte[] bFileName;
|
||||||
byte[] bGroupName;
|
byte[] bGroupName;
|
||||||
@ -355,20 +344,16 @@ public class TrackerClient {
|
|||||||
int len;
|
int len;
|
||||||
String ip_addr;
|
String ip_addr;
|
||||||
int port;
|
int port;
|
||||||
boolean bNewConnection;
|
Connection connection;
|
||||||
Socket trackerSocket;
|
|
||||||
|
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
trackerServer = getConnection();
|
trackerServer = getTrackerServer();
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bNewConnection = true;
|
|
||||||
} else {
|
|
||||||
bNewConnection = false;
|
|
||||||
}
|
}
|
||||||
trackerSocket = trackerServer.getSocket();
|
connection = trackerServer.getConnection();
|
||||||
OutputStream out = trackerSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bs = groupName.getBytes(ClientGlobal.g_charset);
|
bs = groupName.getBytes(ClientGlobal.g_charset);
|
||||||
@ -390,7 +375,7 @@ public class TrackerClient {
|
|||||||
System.arraycopy(bFileName, 0, wholePkg, header.length + bGroupName.length, bFileName.length);
|
System.arraycopy(bFileName, 0, wholePkg, header.length + bGroupName.length, bFileName.length);
|
||||||
out.write(wholePkg);
|
out.write(wholePkg);
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(trackerSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.TRACKER_PROTO_CMD_RESP, -1);
|
ProtoCommon.TRACKER_PROTO_CMD_RESP, -1);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
if (pkgInfo.errno != 0) {
|
if (pkgInfo.errno != 0) {
|
||||||
@ -422,19 +407,19 @@ public class TrackerClient {
|
|||||||
|
|
||||||
return servers;
|
return servers;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
}
|
} finally {
|
||||||
|
connection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
if (connection != null) {
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.releaseConnection(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -449,7 +434,7 @@ public class TrackerClient {
|
|||||||
* @param file_id the file id(including group name and filename)
|
* @param file_id the file id(including group name and filename)
|
||||||
* @return storage server Socket object, return null if fail
|
* @return storage server Socket object, return null if fail
|
||||||
*/
|
*/
|
||||||
public StorageServer getFetchStorage1(TrackerServer trackerServer, String file_id) throws IOException {
|
public StorageServer getFetchStorage1(TrackerServer trackerServer, String file_id) throws IOException, MyException {
|
||||||
String[] parts = new String[2];
|
String[] parts = new String[2];
|
||||||
this.errno = StorageClient1.split_file_id(file_id, parts);
|
this.errno = StorageClient1.split_file_id(file_id, parts);
|
||||||
if (this.errno != 0) {
|
if (this.errno != 0) {
|
||||||
@ -466,7 +451,7 @@ public class TrackerClient {
|
|||||||
* @param file_id the file id(including group name and filename)
|
* @param file_id the file id(including group name and filename)
|
||||||
* @return storage servers, return null if fail
|
* @return storage servers, return null if fail
|
||||||
*/
|
*/
|
||||||
public ServerInfo[] getFetchStorages1(TrackerServer trackerServer, String file_id) throws IOException {
|
public ServerInfo[] getFetchStorages1(TrackerServer trackerServer, String file_id) throws IOException, MyException {
|
||||||
String[] parts = new String[2];
|
String[] parts = new String[2];
|
||||||
this.errno = StorageClient1.split_file_id(file_id, parts);
|
this.errno = StorageClient1.split_file_id(file_id, parts);
|
||||||
if (this.errno != 0) {
|
if (this.errno != 0) {
|
||||||
@ -482,34 +467,30 @@ public class TrackerClient {
|
|||||||
* @param trackerServer the tracker server
|
* @param trackerServer the tracker server
|
||||||
* @return group stat array, return null if fail
|
* @return group stat array, return null if fail
|
||||||
*/
|
*/
|
||||||
public StructGroupStat[] listGroups(TrackerServer trackerServer) throws IOException {
|
public StructGroupStat[] listGroups(TrackerServer trackerServer) throws IOException, MyException {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
String ip_addr;
|
String ip_addr;
|
||||||
int port;
|
int port;
|
||||||
byte cmd;
|
byte cmd;
|
||||||
int out_len;
|
int out_len;
|
||||||
boolean bNewConnection;
|
|
||||||
byte store_path;
|
byte store_path;
|
||||||
Socket trackerSocket;
|
Connection connection;
|
||||||
|
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
trackerServer = getConnection();
|
trackerServer = getTrackerServer();
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bNewConnection = true;
|
|
||||||
} else {
|
|
||||||
bNewConnection = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trackerSocket = trackerServer.getSocket();
|
connection = trackerServer.getConnection();
|
||||||
OutputStream out = trackerSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
header = ProtoCommon.packHeader(ProtoCommon.TRACKER_PROTO_CMD_SERVER_LIST_GROUP, 0, (byte) 0);
|
header = ProtoCommon.packHeader(ProtoCommon.TRACKER_PROTO_CMD_SERVER_LIST_GROUP, 0, (byte) 0);
|
||||||
out.write(header);
|
out.write(header);
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(trackerSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.TRACKER_PROTO_CMD_RESP, -1);
|
ProtoCommon.TRACKER_PROTO_CMD_RESP, -1);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
if (pkgInfo.errno != 0) {
|
if (pkgInfo.errno != 0) {
|
||||||
@ -519,23 +500,22 @@ public class TrackerClient {
|
|||||||
ProtoStructDecoder<StructGroupStat> decoder = new ProtoStructDecoder<StructGroupStat>();
|
ProtoStructDecoder<StructGroupStat> decoder = new ProtoStructDecoder<StructGroupStat>();
|
||||||
return decoder.decode(pkgInfo.body, StructGroupStat.class, StructGroupStat.getFieldsTotalSize());
|
return decoder.decode(pkgInfo.body, StructGroupStat.class, StructGroupStat.getFieldsTotalSize());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
this.errno = ProtoCommon.ERR_NO_EINVAL;
|
this.errno = ProtoCommon.ERR_NO_EINVAL;
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
if (connection != null) {
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.releaseConnection(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -550,7 +530,7 @@ public class TrackerClient {
|
|||||||
* @param groupName the group name of storage server
|
* @param groupName the group name of storage server
|
||||||
* @return storage server stat array, return null if fail
|
* @return storage server stat array, return null if fail
|
||||||
*/
|
*/
|
||||||
public StructStorageStat[] listStorages(TrackerServer trackerServer, String groupName) throws IOException {
|
public StructStorageStat[] listStorages(TrackerServer trackerServer, String groupName) throws IOException, MyException {
|
||||||
final String storageIpAddr = null;
|
final String storageIpAddr = null;
|
||||||
return this.listStorages(trackerServer, groupName, storageIpAddr);
|
return this.listStorages(trackerServer, groupName, storageIpAddr);
|
||||||
}
|
}
|
||||||
@ -564,25 +544,21 @@ public class TrackerClient {
|
|||||||
* @return storage server stat array, return null if fail
|
* @return storage server stat array, return null if fail
|
||||||
*/
|
*/
|
||||||
public StructStorageStat[] listStorages(TrackerServer trackerServer,
|
public StructStorageStat[] listStorages(TrackerServer trackerServer,
|
||||||
String groupName, String storageIpAddr) throws IOException {
|
String groupName, String storageIpAddr) throws IOException, MyException {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
byte[] bGroupName;
|
byte[] bGroupName;
|
||||||
byte[] bs;
|
byte[] bs;
|
||||||
int len;
|
int len;
|
||||||
boolean bNewConnection;
|
Connection connection;
|
||||||
Socket trackerSocket;
|
|
||||||
|
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
trackerServer = getConnection();
|
trackerServer = getTrackerServer();
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bNewConnection = true;
|
|
||||||
} else {
|
|
||||||
bNewConnection = false;
|
|
||||||
}
|
}
|
||||||
trackerSocket = trackerServer.getSocket();
|
connection = trackerServer.getConnection();
|
||||||
OutputStream out = trackerSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bs = groupName.getBytes(ClientGlobal.g_charset);
|
bs = groupName.getBytes(ClientGlobal.g_charset);
|
||||||
@ -619,7 +595,7 @@ public class TrackerClient {
|
|||||||
}
|
}
|
||||||
out.write(wholePkg);
|
out.write(wholePkg);
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(trackerSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.TRACKER_PROTO_CMD_RESP, -1);
|
ProtoCommon.TRACKER_PROTO_CMD_RESP, -1);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
if (pkgInfo.errno != 0) {
|
if (pkgInfo.errno != 0) {
|
||||||
@ -629,13 +605,11 @@ public class TrackerClient {
|
|||||||
ProtoStructDecoder<StructStorageStat> decoder = new ProtoStructDecoder<StructStorageStat>();
|
ProtoStructDecoder<StructStorageStat> decoder = new ProtoStructDecoder<StructStorageStat>();
|
||||||
return decoder.decode(pkgInfo.body, StructStorageStat.class, StructStorageStat.getFieldsTotalSize());
|
return decoder.decode(pkgInfo.body, StructStorageStat.class, StructStorageStat.getFieldsTotalSize());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (!bNewConnection) {
|
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.close(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -643,9 +617,9 @@ public class TrackerClient {
|
|||||||
this.errno = ProtoCommon.ERR_NO_EINVAL;
|
this.errno = ProtoCommon.ERR_NO_EINVAL;
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
if (bNewConnection) {
|
if (connection != null) {
|
||||||
try {
|
try {
|
||||||
trackerServer.close();
|
trackerServer.releaseConnection(connection);
|
||||||
} catch (IOException ex1) {
|
} catch (IOException ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -662,16 +636,17 @@ public class TrackerClient {
|
|||||||
* @return true for success, false for fail
|
* @return true for success, false for fail
|
||||||
*/
|
*/
|
||||||
private boolean deleteStorage(TrackerServer trackerServer,
|
private boolean deleteStorage(TrackerServer trackerServer,
|
||||||
String groupName, String storageIpAddr) throws IOException {
|
String groupName, String storageIpAddr) throws IOException, MyException {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
byte[] bGroupName;
|
byte[] bGroupName;
|
||||||
byte[] bs;
|
byte[] bs;
|
||||||
int len;
|
int len;
|
||||||
Socket trackerSocket;
|
Connection connection;
|
||||||
|
|
||||||
trackerSocket = trackerServer.getSocket();
|
connection = trackerServer.getConnection();
|
||||||
OutputStream out = trackerSocket.getOutputStream();
|
OutputStream out = connection.getOutputStream();
|
||||||
|
|
||||||
|
try {
|
||||||
bs = groupName.getBytes(ClientGlobal.g_charset);
|
bs = groupName.getBytes(ClientGlobal.g_charset);
|
||||||
bGroupName = new byte[ProtoCommon.FDFS_GROUP_NAME_MAX_LEN];
|
bGroupName = new byte[ProtoCommon.FDFS_GROUP_NAME_MAX_LEN];
|
||||||
|
|
||||||
@ -698,10 +673,22 @@ public class TrackerClient {
|
|||||||
System.arraycopy(bIpAddr, 0, wholePkg, header.length + bGroupName.length, ipAddrLen);
|
System.arraycopy(bIpAddr, 0, wholePkg, header.length + bGroupName.length, ipAddrLen);
|
||||||
out.write(wholePkg);
|
out.write(wholePkg);
|
||||||
|
|
||||||
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(trackerSocket.getInputStream(),
|
ProtoCommon.RecvPackageInfo pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(),
|
||||||
ProtoCommon.TRACKER_PROTO_CMD_RESP, 0);
|
ProtoCommon.TRACKER_PROTO_CMD_RESP, 0);
|
||||||
this.errno = pkgInfo.errno;
|
this.errno = pkgInfo.errno;
|
||||||
return pkgInfo.errno == 0;
|
return pkgInfo.errno == 0;
|
||||||
|
} catch (IOException e) {
|
||||||
|
try {
|
||||||
|
trackerServer.close(connection);
|
||||||
|
} finally {
|
||||||
|
connection = null;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (connection != null) {
|
||||||
|
trackerServer.releaseConnection(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -711,7 +698,7 @@ public class TrackerClient {
|
|||||||
* @param storageIpAddr the storage server ip address
|
* @param storageIpAddr the storage server ip address
|
||||||
* @return true for success, false for fail
|
* @return true for success, false for fail
|
||||||
*/
|
*/
|
||||||
public boolean deleteStorage(String groupName, String storageIpAddr) throws IOException {
|
public boolean deleteStorage(String groupName, String storageIpAddr) throws IOException, MyException {
|
||||||
return this.deleteStorage(ClientGlobal.g_tracker_group, groupName, storageIpAddr);
|
return this.deleteStorage(ClientGlobal.g_tracker_group, groupName, storageIpAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,7 +711,7 @@ public class TrackerClient {
|
|||||||
* @return true for success, false for fail
|
* @return true for success, false for fail
|
||||||
*/
|
*/
|
||||||
public boolean deleteStorage(TrackerGroup trackerGroup,
|
public boolean deleteStorage(TrackerGroup trackerGroup,
|
||||||
String groupName, String storageIpAddr) throws IOException {
|
String groupName, String storageIpAddr) throws IOException, MyException {
|
||||||
int serverIndex;
|
int serverIndex;
|
||||||
int notFoundCount;
|
int notFoundCount;
|
||||||
TrackerServer trackerServer;
|
TrackerServer trackerServer;
|
||||||
@ -732,14 +719,12 @@ public class TrackerClient {
|
|||||||
notFoundCount = 0;
|
notFoundCount = 0;
|
||||||
for (serverIndex = 0; serverIndex < trackerGroup.tracker_servers.length; serverIndex++) {
|
for (serverIndex = 0; serverIndex < trackerGroup.tracker_servers.length; serverIndex++) {
|
||||||
try {
|
try {
|
||||||
trackerServer = trackerGroup.getConnection(serverIndex);
|
trackerServer = trackerGroup.getTrackerServer(serverIndex);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace(System.err);
|
ex.printStackTrace(System.err);
|
||||||
this.errno = ProtoCommon.ECONNREFUSED;
|
this.errno = ProtoCommon.ECONNREFUSED;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
StructStorageStat[] storageStats = listStorages(trackerServer, groupName, storageIpAddr);
|
StructStorageStat[] storageStats = listStorages(trackerServer, groupName, storageIpAddr);
|
||||||
if (storageStats == null) {
|
if (storageStats == null) {
|
||||||
if (this.errno == ProtoCommon.ERR_NO_ENOENT) {
|
if (this.errno == ProtoCommon.ERR_NO_ENOENT) {
|
||||||
@ -754,13 +739,7 @@ public class TrackerClient {
|
|||||||
this.errno = ProtoCommon.ERR_NO_EBUSY;
|
this.errno = ProtoCommon.ERR_NO_EBUSY;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
trackerServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notFoundCount == trackerGroup.tracker_servers.length) {
|
if (notFoundCount == trackerGroup.tracker_servers.length) {
|
||||||
@ -771,15 +750,13 @@ public class TrackerClient {
|
|||||||
notFoundCount = 0;
|
notFoundCount = 0;
|
||||||
for (serverIndex = 0; serverIndex < trackerGroup.tracker_servers.length; serverIndex++) {
|
for (serverIndex = 0; serverIndex < trackerGroup.tracker_servers.length; serverIndex++) {
|
||||||
try {
|
try {
|
||||||
trackerServer = trackerGroup.getConnection(serverIndex);
|
trackerServer = trackerGroup.getTrackerServer(serverIndex);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
System.err.println("connect to server " + trackerGroup.tracker_servers[serverIndex].getAddress().getHostAddress() + ":" + trackerGroup.tracker_servers[serverIndex].getPort() + " fail");
|
System.err.println("connect to server " + trackerGroup.tracker_servers[serverIndex].getAddress().getHostAddress() + ":" + trackerGroup.tracker_servers[serverIndex].getPort() + " fail");
|
||||||
ex.printStackTrace(System.err);
|
ex.printStackTrace(System.err);
|
||||||
this.errno = ProtoCommon.ECONNREFUSED;
|
this.errno = ProtoCommon.ECONNREFUSED;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
if (!this.deleteStorage(trackerServer, groupName, storageIpAddr)) {
|
if (!this.deleteStorage(trackerServer, groupName, storageIpAddr)) {
|
||||||
if (this.errno != 0) {
|
if (this.errno != 0) {
|
||||||
if (this.errno == ProtoCommon.ERR_NO_ENOENT) {
|
if (this.errno == ProtoCommon.ERR_NO_ENOENT) {
|
||||||
@ -789,13 +766,7 @@ public class TrackerClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
trackerServer.close();
|
|
||||||
} catch (IOException ex1) {
|
|
||||||
ex1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notFoundCount == trackerGroup.tracker_servers.length) {
|
if (notFoundCount == trackerGroup.tracker_servers.length) {
|
||||||
|
@ -10,7 +10,6 @@ package org.csource.fastdfs;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracker server group
|
* Tracker server group
|
||||||
@ -39,7 +38,7 @@ public class TrackerGroup {
|
|||||||
*
|
*
|
||||||
* @return connected tracker server, null for fail
|
* @return connected tracker server, null for fail
|
||||||
*/
|
*/
|
||||||
public TrackerServer getConnection(int serverIndex) throws IOException {
|
public TrackerServer getTrackerServer(int serverIndex) throws IOException {
|
||||||
return new TrackerServer(this.tracker_servers[serverIndex]);
|
return new TrackerServer(this.tracker_servers[serverIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +47,7 @@ public class TrackerGroup {
|
|||||||
*
|
*
|
||||||
* @return connected tracker server, null for fail
|
* @return connected tracker server, null for fail
|
||||||
*/
|
*/
|
||||||
public TrackerServer getConnection() throws IOException {
|
public TrackerServer getTrackerServer() throws IOException {
|
||||||
int current_index;
|
int current_index;
|
||||||
|
|
||||||
synchronized (this.lock) {
|
synchronized (this.lock) {
|
||||||
@ -61,7 +60,7 @@ public class TrackerGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return this.getConnection(current_index);
|
return this.getTrackerServer(current_index);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
System.err.println("connect to server " + this.tracker_servers[current_index].getAddress().getHostAddress() + ":" + this.tracker_servers[current_index].getPort() + " fail");
|
System.err.println("connect to server " + this.tracker_servers[current_index].getAddress().getHostAddress() + ":" + this.tracker_servers[current_index].getPort() + " fail");
|
||||||
ex.printStackTrace(System.err);
|
ex.printStackTrace(System.err);
|
||||||
@ -73,7 +72,7 @@ public class TrackerGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TrackerServer trackerServer = this.getConnection(i);
|
TrackerServer trackerServer = this.getTrackerServer(i);
|
||||||
|
|
||||||
synchronized (this.lock) {
|
synchronized (this.lock) {
|
||||||
if (this.tracker_server_index == current_index) {
|
if (this.tracker_server_index == current_index) {
|
||||||
|
@ -8,14 +8,13 @@
|
|||||||
|
|
||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
import org.csource.fastdfs.pool.ConnectionInfo;
|
import org.csource.common.MyException;
|
||||||
|
import org.csource.fastdfs.pool.Connection;
|
||||||
import org.csource.fastdfs.pool.ConnectionPool;
|
import org.csource.fastdfs.pool.ConnectionPool;
|
||||||
|
import org.csource.fastdfs.pool.ConnectionFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracker Server Info
|
* Tracker Server Info
|
||||||
@ -24,46 +23,22 @@ import java.net.Socket;
|
|||||||
* @version Version 1.11
|
* @version Version 1.11
|
||||||
*/
|
*/
|
||||||
public class TrackerServer {
|
public class TrackerServer {
|
||||||
protected Socket sock;
|
|
||||||
protected InetSocketAddress inetSockAddr;
|
protected InetSocketAddress inetSockAddr;
|
||||||
|
|
||||||
private Long lastAccessTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param sock Socket of server
|
|
||||||
* @param inetSockAddr the server info
|
|
||||||
*/
|
|
||||||
public TrackerServer(Socket sock, InetSocketAddress inetSockAddr) {
|
|
||||||
this.sock = sock;
|
|
||||||
this.inetSockAddr = inetSockAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TrackerServer(InetSocketAddress inetSockAddr) throws IOException {
|
public TrackerServer(InetSocketAddress inetSockAddr) throws IOException {
|
||||||
this.inetSockAddr = inetSockAddr;
|
this.inetSockAddr = inetSockAddr;
|
||||||
this.sock = getSocket();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Connection getConnection() throws MyException, IOException {
|
||||||
* get the connected socket
|
Connection connection;
|
||||||
*
|
|
||||||
* @return the socket
|
|
||||||
*/
|
|
||||||
public Socket getSocket() throws IOException {
|
|
||||||
if (this.sock == null) {
|
|
||||||
if (ClientGlobal.g_connection_pool_enabled) {
|
if (ClientGlobal.g_connection_pool_enabled) {
|
||||||
ConnectionInfo connection = ConnectionPool.getConnection(this.inetSockAddr);
|
connection = ConnectionPool.getConnection(this.inetSockAddr);
|
||||||
this.sock = connection.getSocket();
|
|
||||||
this.lastAccessTime = connection.getLastAccessTime();
|
|
||||||
} else {
|
} else {
|
||||||
this.sock = ClientGlobal.getSocket(this.inetSockAddr);
|
connection = ConnectionFactory.create(this.inetSockAddr);
|
||||||
}
|
}
|
||||||
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.sock;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the server info
|
* get the server info
|
||||||
*
|
*
|
||||||
@ -72,88 +47,28 @@ public class TrackerServer {
|
|||||||
public InetSocketAddress getInetSocketAddress() {
|
public InetSocketAddress getInetSocketAddress() {
|
||||||
return this.inetSockAddr;
|
return this.inetSockAddr;
|
||||||
}
|
}
|
||||||
|
public void close(Connection connection) throws IOException {
|
||||||
public OutputStream getOutputStream() throws IOException {
|
|
||||||
return this.sock.getOutputStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
|
||||||
return this.sock.getInputStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() throws IOException {
|
|
||||||
//if connection enabled get from connection pool
|
//if connection enabled get from connection pool
|
||||||
if (ClientGlobal.g_connection_pool_enabled) {
|
if (ClientGlobal.g_connection_pool_enabled) {
|
||||||
ConnectionPool.freeConnection(this);
|
ConnectionPool.closeConnection(connection);
|
||||||
} else {
|
} else {
|
||||||
this.closeDirect();
|
connection.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* close direct if not create from pool or not open pool
|
* releaseConnection connection
|
||||||
|
* @param connection
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void closeDirect() throws IOException {
|
public void releaseConnection(Connection connection) throws IOException {
|
||||||
if (this.sock != null) {
|
if (ClientGlobal.g_connection_pool_enabled) {
|
||||||
try {
|
ConnectionPool.releaseConnection(connection);
|
||||||
ProtoCommon.closeSocket(this.sock);
|
} else {
|
||||||
} finally {
|
connection.close();
|
||||||
this.sock = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void finalize() throws Throwable {
|
|
||||||
this.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 Long getLastAccessTime() {
|
|
||||||
return lastAccessTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastAccessTime(Long lastAccessTime) {
|
|
||||||
this.lastAccessTime = lastAccessTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "TrackerServer{" +
|
|
||||||
"sock=" + sock +
|
|
||||||
", inetSockAddr=" + inetSockAddr +
|
|
||||||
", lastAccessTime=" + lastAccessTime +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
107
src/main/java/org/csource/fastdfs/pool/Connection.java
Normal file
107
src/main/java/org/csource/fastdfs/pool/Connection.java
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
package org.csource.fastdfs.pool;
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* close direct if not create from pool or not open pool
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void close() 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TrackerServer{" +
|
||||||
|
"sock=" + sock +
|
||||||
|
", inetSockAddr=" + inetSockAddr +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -5,9 +5,8 @@ import org.csource.fastdfs.ClientGlobal;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
public class ConnectionFactory {
|
||||||
public class PoolConnectionFactory {
|
public static Connection create(String key) throws IOException {
|
||||||
public static ConnectionInfo create(String key) throws IOException {
|
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
System.err.printf("ip:port entry conn't be null");
|
System.err.printf("ip:port entry conn't be null");
|
||||||
return null;
|
return null;
|
||||||
@ -24,7 +23,21 @@ public class PoolConnectionFactory {
|
|||||||
sock.setSoTimeout(ClientGlobal.g_network_timeout);
|
sock.setSoTimeout(ClientGlobal.g_network_timeout);
|
||||||
InetSocketAddress inetSocketAddress = new InetSocketAddress(ip, port);
|
InetSocketAddress inetSocketAddress = new InetSocketAddress(ip, port);
|
||||||
sock.connect(inetSocketAddress, ClientGlobal.g_connect_timeout);
|
sock.connect(inetSocketAddress, ClientGlobal.g_connect_timeout);
|
||||||
return new ConnectionInfo(sock, inetSocketAddress, System.currentTimeMillis(), false);
|
return new Connection(sock, inetSocketAddress);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create from InetSocketAddress
|
||||||
|
* @param socketAddress
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static Connection create(InetSocketAddress socketAddress) throws IOException {
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,60 +0,0 @@
|
|||||||
package org.csource.fastdfs.pool;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
|
|
||||||
public class ConnectionInfo {
|
|
||||||
private Socket socket;
|
|
||||||
protected InetSocketAddress inetSockAddr;
|
|
||||||
private Long lastAccessTime;
|
|
||||||
private boolean needActiveCheck = false;
|
|
||||||
|
|
||||||
public Socket getSocket() {
|
|
||||||
return socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSocket(Socket socket) {
|
|
||||||
this.socket = socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetSocketAddress getInetSockAddr() {
|
|
||||||
return inetSockAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInetSockAddr(InetSocketAddress inetSockAddr) {
|
|
||||||
this.inetSockAddr = inetSockAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getLastAccessTime() {
|
|
||||||
return lastAccessTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastAccessTime(Long lastAccessTime) {
|
|
||||||
this.lastAccessTime = lastAccessTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNeedActiveCheck() {
|
|
||||||
return needActiveCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNeedActiveCheck(boolean needActiveCheck) {
|
|
||||||
this.needActiveCheck = needActiveCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectionInfo(Socket socket, InetSocketAddress inetSockAddr, Long lastAccessTime, boolean needActiveCheck) {
|
|
||||||
this.socket = socket;
|
|
||||||
this.inetSockAddr = inetSockAddr;
|
|
||||||
this.lastAccessTime = lastAccessTime;
|
|
||||||
this.needActiveCheck = needActiveCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ConnectionInfo{" +
|
|
||||||
"socket=" + socket +
|
|
||||||
", inetSockAddr=" + inetSockAddr +
|
|
||||||
", lastAccessTime=" + lastAccessTime +
|
|
||||||
", needActiveCheck=" + needActiveCheck +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,7 @@
|
|||||||
package org.csource.fastdfs.pool;
|
package org.csource.fastdfs.pool;
|
||||||
|
|
||||||
|
import org.csource.common.MyException;
|
||||||
import org.csource.fastdfs.ClientGlobal;
|
import org.csource.fastdfs.ClientGlobal;
|
||||||
import org.csource.fastdfs.ProtoCommon;
|
|
||||||
import org.csource.fastdfs.TrackerServer;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -37,7 +35,7 @@ public class ConnectionManager {
|
|||||||
/**
|
/**
|
||||||
* free connections
|
* free connections
|
||||||
*/
|
*/
|
||||||
private volatile ConcurrentLinkedQueue<ConnectionInfo> freeConnections = new ConcurrentLinkedQueue<ConnectionInfo>();
|
private volatile ConcurrentLinkedQueue<Connection> freeConnections = new ConcurrentLinkedQueue<Connection>();
|
||||||
|
|
||||||
private ConnectionManager() {
|
private ConnectionManager() {
|
||||||
|
|
||||||
@ -47,57 +45,46 @@ public class ConnectionManager {
|
|||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized ConnectionInfo newConnection() throws IOException {
|
private Connection newConnection() throws IOException {
|
||||||
try {
|
try {
|
||||||
ConnectionInfo connectionInfo = PoolConnectionFactory.create(this.key);
|
Connection connection = ConnectionFactory.create(this.key);
|
||||||
return connectionInfo;
|
return connection;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized ConnectionInfo getConnection() throws IOException {
|
public Connection getConnection() throws MyException {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
ConnectionInfo connectionInfo = null;
|
Connection connection = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (freeCount.get() > 0) {
|
if (freeCount.get() > 0) {
|
||||||
connectionInfo = freeConnections.poll();
|
|
||||||
if ((System.currentTimeMillis() - connectionInfo.getLastAccessTime()) > ClientGlobal.getG_connection_pool_max_idle_time()) {
|
|
||||||
closeConnection(connectionInfo);
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
freeCount.decrementAndGet();
|
freeCount.decrementAndGet();
|
||||||
|
connection = freeConnections.poll();
|
||||||
|
if (!connection.isAvaliable() || (System.currentTimeMillis() - connection.getLastAccessTime()) > ClientGlobal.getG_connection_pool_max_idle_time()) {
|
||||||
|
closeConnection(connection);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
} else if (ClientGlobal.getG_connection_pool_max_count_per_entry() == 0 || totalCount.get() < ClientGlobal.getG_connection_pool_max_count_per_entry()) {
|
} else if (ClientGlobal.getG_connection_pool_max_count_per_entry() == 0 || totalCount.get() < ClientGlobal.getG_connection_pool_max_count_per_entry()) {
|
||||||
connectionInfo = newConnection();
|
connection = newConnection();
|
||||||
if (connectionInfo != null) {
|
if (connection != null) {
|
||||||
totalCount.incrementAndGet();
|
totalCount.incrementAndGet();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (condition.await(ClientGlobal.getG_connection_pool_max_wait_time(), TimeUnit.MILLISECONDS)) {
|
if (condition.await(ClientGlobal.getG_connection_pool_max_wait_time_in_ms(), TimeUnit.MILLISECONDS)) {
|
||||||
//wait single success
|
//wait single success
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
throw new MyException("get connection fail, wait_time greater than " + ClientGlobal.g_connection_pool_max_wait_time_in_ms + "ms");
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
throw new MyException("get connection fail, emsg > " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if need check active
|
return connection;
|
||||||
if (connectionInfo.isNeedActiveCheck()) {
|
|
||||||
boolean activeYes = ProtoCommon.activeTest(connectionInfo.getSocket());
|
|
||||||
if (activeYes) {
|
|
||||||
connectionInfo.setLastAccessTime(System.currentTimeMillis());
|
|
||||||
} else {
|
|
||||||
//close if check fail
|
|
||||||
closeConnection(connectionInfo);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return connectionInfo;
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return null;
|
return null;
|
||||||
@ -106,33 +93,34 @@ public class ConnectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void freeConnection(TrackerServer trackerServer) throws IOException {
|
public void releaseConnection(Connection connection) throws IOException {
|
||||||
if (trackerServer == null || !trackerServer.isConnected()) {
|
if (connection == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ConnectionInfo connectionInfo = new ConnectionInfo(trackerServer.getSocket(),trackerServer.getInetSocketAddress(),System.currentTimeMillis(),true);
|
if ((System.currentTimeMillis() - connection.getLastAccessTime()) < ClientGlobal.g_connection_pool_max_idle_time) {
|
||||||
if ((System.currentTimeMillis() - trackerServer.getLastAccessTime()) < ClientGlobal.getG_connection_pool_max_idle_time()) {
|
|
||||||
try {
|
try {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
freeConnections.add(connectionInfo);
|
freeConnections.add(connection);
|
||||||
freeCount.incrementAndGet();
|
freeCount.incrementAndGet();
|
||||||
condition.signal();
|
condition.signal();
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
closeConnection(connectionInfo);
|
closeConnection(connection);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeConnection(ConnectionInfo connectionInfo) throws IOException {
|
|
||||||
if (connectionInfo.getSocket() != null) {
|
|
||||||
totalCount.decrementAndGet();
|
|
||||||
try {
|
|
||||||
ProtoCommon.closeSocket(connectionInfo.getSocket());
|
|
||||||
} finally {
|
|
||||||
connectionInfo.setSocket(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void closeConnection(Connection connection) throws IOException {
|
||||||
|
try {
|
||||||
|
if (connection != null) {
|
||||||
|
totalCount.decrementAndGet();
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("close socket error , msg:" + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package org.csource.fastdfs.pool;
|
package org.csource.fastdfs.pool;
|
||||||
|
|
||||||
import org.csource.fastdfs.TrackerServer;
|
import org.csource.common.MyException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -13,54 +13,51 @@ public class ConnectionPool {
|
|||||||
*/
|
*/
|
||||||
private final static ConcurrentHashMap<String, ConnectionManager> CP = new ConcurrentHashMap<String, ConnectionManager>();
|
private final static ConcurrentHashMap<String, ConnectionManager> CP = new ConcurrentHashMap<String, ConnectionManager>();
|
||||||
|
|
||||||
public static synchronized ConnectionInfo getConnection(InetSocketAddress socketAddress) throws IOException {
|
public static Connection getConnection(InetSocketAddress socketAddress) throws MyException {
|
||||||
if (socketAddress == null) {
|
if (socketAddress == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String key = getKey(socketAddress);
|
String key = getKey(socketAddress);
|
||||||
ConnectionManager connectionManager = CP.get(key);
|
ConnectionManager connectionManager;
|
||||||
|
synchronized (ConnectionPool.class) {
|
||||||
|
connectionManager = CP.get(key);
|
||||||
if (connectionManager == null) {
|
if (connectionManager == null) {
|
||||||
connectionManager = new ConnectionManager(key);
|
connectionManager = new ConnectionManager(key);
|
||||||
CP.put(key, connectionManager);
|
CP.put(key, connectionManager);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return connectionManager.getConnection();
|
return connectionManager.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static void releaseConnection(Connection connection) throws IOException {
|
||||||
* release connection
|
if (connection == null) {
|
||||||
*/
|
|
||||||
public static void closeConnection(TrackerServer trackerServer) throws IOException {
|
|
||||||
if (trackerServer == null || trackerServer.getInetSocketAddress() == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String key = getKey(trackerServer.getInetSocketAddress());
|
String key = getKey(connection.getInetSocketAddress());
|
||||||
if (key != null) {
|
|
||||||
ConnectionManager connectionManager = CP.get(key);
|
ConnectionManager connectionManager = CP.get(key);
|
||||||
if (connectionManager != null) {
|
if (connectionManager != null) {
|
||||||
connectionManager.closeConnection(new ConnectionInfo(trackerServer.getSocket(), trackerServer.getInetSocketAddress(),trackerServer.getLastAccessTime(),true));
|
connectionManager.releaseConnection(connection);
|
||||||
} else {
|
} else {
|
||||||
trackerServer.closeDirect();
|
try {
|
||||||
}
|
connection.close();
|
||||||
} else {
|
} catch (IOException e) {
|
||||||
trackerServer.closeDirect();
|
System.err.println("close socket error, msg:" + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void freeConnection(TrackerServer trackerServer) throws IOException {
|
|
||||||
if (trackerServer == null || trackerServer.getInetSocketAddress() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String key = getKey(trackerServer.getInetSocketAddress());
|
|
||||||
if (key != null) {
|
|
||||||
ConnectionManager connectionManager = CP.get(key);
|
|
||||||
if (connectionManager != null) {
|
|
||||||
connectionManager.freeConnection(trackerServer);
|
|
||||||
} else {
|
|
||||||
trackerServer.closeDirect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
} else {
|
} else {
|
||||||
trackerServer.closeDirect();
|
connection.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +67,7 @@ public class ConnectionPool {
|
|||||||
}
|
}
|
||||||
return String.format("%s:%s", socketAddress.getHostName(), socketAddress.getPort());
|
return String.format("%s:%s", socketAddress.getHostName(), socketAddress.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (!CP.isEmpty()) {
|
if (!CP.isEmpty()) {
|
||||||
|
@ -14,4 +14,4 @@ fastdfs.tracker_servers = 10.0.11.201:22122,10.0.11.202:22122,10.0.11.203:22122
|
|||||||
fastdfs.connection_pool.enabled = false
|
fastdfs.connection_pool.enabled = false
|
||||||
fastdfs.connection_pool.max_count_per_entry = 50
|
fastdfs.connection_pool.max_count_per_entry = 50
|
||||||
fastdfs.connection_pool.max_idle_time = 60
|
fastdfs.connection_pool.max_idle_time = 60
|
||||||
fastdfs.connection_pool.max_wait_time = 5
|
fastdfs.connection_pool.max_wait_time_in_ms = 5000
|
@ -18,4 +18,4 @@ fastdfs.connection_pool.enabled = false
|
|||||||
fastdfs.connection_pool.max_count_per_entry = 100
|
fastdfs.connection_pool.max_count_per_entry = 100
|
||||||
|
|
||||||
fastdfs.connection_pool.max_idle_time = 60
|
fastdfs.connection_pool.max_idle_time = 60
|
||||||
fastdfs.connection_pool.max_wait_time = 5
|
fastdfs.connection_pool.max_wait_time_in_ms = 5000
|
@ -11,4 +11,4 @@ tracker_server = 10.0.11.244:22122
|
|||||||
connection_pool.enabled = false
|
connection_pool.enabled = false
|
||||||
connection_pool.max_count_per_entry = 100
|
connection_pool.max_count_per_entry = 100
|
||||||
connection_pool.max_idle_time = 60
|
connection_pool.max_idle_time = 60
|
||||||
connection_pool.max_wait_time = 5
|
connection_pool.max_wait_time_in_ms = 5000
|
@ -31,7 +31,7 @@ public class FdfsTest {
|
|||||||
LOGGER.info("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
LOGGER.info("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
||||||
LOGGER.info("charset=" + ClientGlobal.g_charset);
|
LOGGER.info("charset=" + ClientGlobal.g_charset);
|
||||||
TrackerClient tracker = new TrackerClient();
|
TrackerClient tracker = new TrackerClient();
|
||||||
trackerServer = tracker.getConnection();
|
trackerServer = tracker.getTrackerServer();
|
||||||
StorageServer storageServer = null;
|
StorageServer storageServer = null;
|
||||||
storageClient = new StorageClient(trackerServer, storageServer);
|
storageClient = new StorageClient(trackerServer, storageServer);
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
import org.csource.fastdfs.*;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,7 +46,7 @@ public class Monitor {
|
|||||||
System.out.println("delete storage errno: " + tracker.getErrorCode());
|
System.out.println("delete storage errno: " + tracker.getErrorCode());
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TrackerServer trackerServer = tracker.getConnection();
|
TrackerServer trackerServer = tracker.getTrackerServer();
|
||||||
if (trackerServer == null) {
|
if (trackerServer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -157,8 +155,6 @@ public class Monitor {
|
|||||||
System.out.println("\t\tlast_synced_timestamp = " + df.format(storageStat.getLastSyncedTimestamp()) + getSyncedDelayString(storageStats, storageStat));
|
System.out.println("\t\tlast_synced_timestamp = " + df.format(storageStat.getLastSyncedTimestamp()) + getSyncedDelayString(storageStats, storageStat));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trackerServer.close();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
import org.csource.common.NameValuePair;
|
import org.csource.common.NameValuePair;
|
||||||
import org.csource.fastdfs.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* client test
|
* client test
|
||||||
@ -46,7 +45,7 @@ public class Test {
|
|||||||
System.out.println("charset=" + ClientGlobal.g_charset);
|
System.out.println("charset=" + ClientGlobal.g_charset);
|
||||||
|
|
||||||
TrackerClient tracker = new TrackerClient();
|
TrackerClient tracker = new TrackerClient();
|
||||||
TrackerServer trackerServer = tracker.getConnection();
|
TrackerServer trackerServer = tracker.getTrackerServer();
|
||||||
StorageServer storageServer = null;
|
StorageServer storageServer = null;
|
||||||
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
|
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
|
||||||
|
|
||||||
@ -60,8 +59,6 @@ public class Test {
|
|||||||
byte[] result = client.download_file1(fileId);
|
byte[] result = client.download_file1(fileId);
|
||||||
System.out.println(i + ", download result is: " + result.length);
|
System.out.println(i + ", download result is: " + result.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
trackerServer.close();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
import org.csource.common.NameValuePair;
|
import org.csource.common.NameValuePair;
|
||||||
import org.csource.fastdfs.*;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
@ -39,9 +38,9 @@ public class Test1 {
|
|||||||
TrackerGroup tg = new TrackerGroup(new InetSocketAddress[]{new InetSocketAddress("47.95.221.159", 22122)});
|
TrackerGroup tg = new TrackerGroup(new InetSocketAddress[]{new InetSocketAddress("47.95.221.159", 22122)});
|
||||||
TrackerClient tc = new TrackerClient(tg);
|
TrackerClient tc = new TrackerClient(tg);
|
||||||
|
|
||||||
TrackerServer ts = tc.getConnection();
|
TrackerServer ts = tc.getTrackerServer();
|
||||||
if (ts == null) {
|
if (ts == null) {
|
||||||
System.out.println("getConnection return null");
|
System.out.println("getTrackerServer return null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
import org.csource.common.NameValuePair;
|
import org.csource.common.NameValuePair;
|
||||||
import org.csource.fastdfs.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -53,7 +52,7 @@ public class TestAppender {
|
|||||||
String remote_filename;
|
String remote_filename;
|
||||||
ServerInfo[] servers;
|
ServerInfo[] servers;
|
||||||
TrackerClient tracker = new TrackerClient();
|
TrackerClient tracker = new TrackerClient();
|
||||||
TrackerServer trackerServer = tracker.getConnection();
|
TrackerServer trackerServer = tracker.getTrackerServer();
|
||||||
|
|
||||||
StorageServer storageServer = null;
|
StorageServer storageServer = null;
|
||||||
|
|
||||||
@ -298,14 +297,10 @@ public class TestAppender {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* for test only */
|
/* for test only */
|
||||||
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
|
System.out.println("active test to storage server: " + storageServer.getConnection().activeTest());
|
||||||
|
|
||||||
storageServer.close();
|
|
||||||
|
|
||||||
/* for test only */
|
/* for test only */
|
||||||
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
|
System.out.println("active test to tracker server: " + trackerServer.getConnection().activeTest());
|
||||||
|
|
||||||
trackerServer.close();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
import org.csource.common.NameValuePair;
|
import org.csource.common.NameValuePair;
|
||||||
import org.csource.fastdfs.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -51,7 +50,7 @@ public class TestAppender1 {
|
|||||||
long startTime;
|
long startTime;
|
||||||
ServerInfo[] servers;
|
ServerInfo[] servers;
|
||||||
TrackerClient tracker = new TrackerClient();
|
TrackerClient tracker = new TrackerClient();
|
||||||
TrackerServer trackerServer = tracker.getConnection();
|
TrackerServer trackerServer = tracker.getTrackerServer();
|
||||||
|
|
||||||
StorageServer storageServer = null;
|
StorageServer storageServer = null;
|
||||||
|
|
||||||
@ -276,15 +275,12 @@ public class TestAppender1 {
|
|||||||
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
|
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* for test only */
|
|
||||||
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
|
|
||||||
|
|
||||||
storageServer.close();
|
|
||||||
|
|
||||||
/* for test only */
|
/* for test only */
|
||||||
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
|
System.out.println("active test to storage server: " + storageServer.getConnection().activeTest());
|
||||||
|
|
||||||
trackerServer.close();
|
/* for test only */
|
||||||
|
System.out.println("active test to tracker server: " + trackerServer.getConnection().activeTest());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
import org.csource.common.NameValuePair;
|
import org.csource.common.NameValuePair;
|
||||||
import org.csource.fastdfs.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -53,7 +52,7 @@ public class TestClient {
|
|||||||
String remote_filename;
|
String remote_filename;
|
||||||
ServerInfo[] servers;
|
ServerInfo[] servers;
|
||||||
TrackerClient tracker = new TrackerClient();
|
TrackerClient tracker = new TrackerClient();
|
||||||
TrackerServer trackerServer = tracker.getConnection();
|
TrackerServer trackerServer = tracker.getTrackerServer();
|
||||||
|
|
||||||
StorageServer storageServer = null;
|
StorageServer storageServer = null;
|
||||||
|
|
||||||
@ -288,15 +287,12 @@ public class TestClient {
|
|||||||
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
|
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* for test only */
|
|
||||||
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
|
|
||||||
|
|
||||||
storageServer.close();
|
|
||||||
|
|
||||||
/* for test only */
|
/* for test only */
|
||||||
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
|
System.out.println("active test to storage server: " + storageServer.getConnection().activeTest());
|
||||||
|
|
||||||
trackerServer.close();
|
/* for test only */
|
||||||
|
System.out.println("active test to tracker server: " + trackerServer.getConnection().activeTest());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
import org.csource.common.NameValuePair;
|
import org.csource.common.NameValuePair;
|
||||||
import org.csource.fastdfs.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -52,7 +51,7 @@ public class TestClient1 {
|
|||||||
String file_id;
|
String file_id;
|
||||||
|
|
||||||
TrackerClient tracker = new TrackerClient();
|
TrackerClient tracker = new TrackerClient();
|
||||||
TrackerServer trackerServer = tracker.getConnection();
|
TrackerServer trackerServer = tracker.getTrackerServer();
|
||||||
|
|
||||||
StorageServer storageServer = null;
|
StorageServer storageServer = null;
|
||||||
/*
|
/*
|
||||||
@ -251,14 +250,12 @@ public class TestClient1 {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for test only */
|
|
||||||
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
|
|
||||||
storageServer.close();
|
|
||||||
|
|
||||||
/* for test only */
|
/* for test only */
|
||||||
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
|
System.out.println("active test to storage server: " + storageServer.getConnection().activeTest());
|
||||||
|
|
||||||
trackerServer.close();
|
/* for test only */
|
||||||
|
System.out.println("active test to tracker server: " + trackerServer.getConnection().activeTest());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
package org.csource.fastdfs;
|
package org.csource.fastdfs;
|
||||||
|
|
||||||
import org.csource.fastdfs.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* load test class
|
* load test class
|
||||||
*
|
*
|
||||||
@ -88,7 +86,7 @@ public class TestLoad {
|
|||||||
|
|
||||||
public Uploader() throws Exception {
|
public Uploader() throws Exception {
|
||||||
this.tracker = new TrackerClient();
|
this.tracker = new TrackerClient();
|
||||||
this.trackerServer = tracker.getConnection();
|
this.trackerServer = tracker.getTrackerServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int uploadFile() throws Exception {
|
public int uploadFile() throws Exception {
|
||||||
@ -129,7 +127,7 @@ public class TestLoad {
|
|||||||
|
|
||||||
public Downloader() throws Exception {
|
public Downloader() throws Exception {
|
||||||
this.tracker = new TrackerClient();
|
this.tracker = new TrackerClient();
|
||||||
this.trackerServer = tracker.getConnection();
|
this.trackerServer = tracker.getTrackerServer();
|
||||||
this.callback = new DownloadFileDiscard();
|
this.callback = new DownloadFileDiscard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user