|
@ -5,7 +5,10 @@ import org.csource.fastdfs.ClientGlobal;
|
|
|
import org.csource.fastdfs.StorageClient;
|
|
|
import org.csource.fastdfs.TrackerClient;
|
|
|
import org.csource.fastdfs.TrackerServer;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
@ -15,26 +18,56 @@ import java.util.Map.Entry;
|
|
|
*/
|
|
|
public class FastDFSClientPool {
|
|
|
private static volatile FastDFSClientPool pool;
|
|
|
|
|
|
private Logger logger = (Logger) LoggerFactory.getLogger(FastDFSClientPool.class);
|
|
|
private Map<StorageClient, Boolean> map;
|
|
|
|
|
|
private int maxPoolSize = 20;
|
|
|
private int waitTime = 500;
|
|
|
private int initPoolSize = 5;
|
|
|
|
|
|
static {
|
|
|
{
|
|
|
try {
|
|
|
|
|
|
String basePath = FastDFSClientPool.class.getResource("/").getPath();
|
|
|
|
|
|
ClientGlobal.init(FastDFSUtil.class.getResource("/config/fdfs_client.conf").getPath());
|
|
|
|
|
|
ClientGlobal.init("/data/guns-separation/config/fdfs_client.conf");
|
|
|
|
|
|
System.out.println("FastDFSClientPool→fdfs_client.conf === ");
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String readfile(String file){
|
|
|
InputStream stream = this.getClass().getResourceAsStream(file);
|
|
|
StringBuffer sb = new StringBuffer() ;
|
|
|
BufferedReader br = null ;
|
|
|
try {
|
|
|
br = new BufferedReader(new InputStreamReader(stream,"UTF-8")) ;
|
|
|
String s=null ;
|
|
|
while((s=br.readLine()) !=null){
|
|
|
sb.append(s) ;
|
|
|
}
|
|
|
br.close();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
logger.error("FileNotFoundException:"+e);
|
|
|
} catch (IOException e) {
|
|
|
logger.error("IOException :"+e);
|
|
|
} finally {
|
|
|
if(br !=null){
|
|
|
try {
|
|
|
br.close();
|
|
|
} catch (IOException e) {
|
|
|
logger.error("close br error:"+e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return sb.toString();
|
|
|
}
|
|
|
|
|
|
private FastDFSClientPool() {
|
|
|
|
|
|
init();
|
|
@ -81,8 +114,9 @@ public class FastDFSClientPool {
|
|
|
private StorageClient getNewStorageClient() {
|
|
|
try {
|
|
|
TrackerClient tracker = new TrackerClient();
|
|
|
logger.info("FastDFSClientPool→tracker==="+tracker);
|
|
|
TrackerServer trackerServer = tracker.getConnection();
|
|
|
|
|
|
logger.info("FastDFSClientPool→trackerServer === "+trackerServer);
|
|
|
StorageClient client = new StorageClient(trackerServer, null);
|
|
|
return client;
|
|
|
} catch (Exception e) {
|