fxi
parent
1b99e59cf7
commit
b7739178c9
|
@ -6,9 +6,11 @@ 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 ConnectionFactory {
|
||||||
/**
|
/**
|
||||||
* create from InetSocketAddress
|
* create from InetSocketAddress
|
||||||
|
*
|
||||||
* @param socketAddress
|
* @param socketAddress
|
||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
@ -21,8 +23,7 @@ public class ConnectionFactory {
|
||||||
sock.connect(socketAddress, ClientGlobal.g_connect_timeout);
|
sock.connect(socketAddress, ClientGlobal.g_connect_timeout);
|
||||||
return new Connection(sock, socketAddress);
|
return new Connection(sock, socketAddress);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("get connection error , emsg:" + e.getMessage());
|
throw new MyException("get connection error, ip:host = " + socketAddress.getHostName() + ":" + socketAddress.getPort() + ", emsg:" + e.getMessage());
|
||||||
throw new MyException("get connection error , emsg:" + e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.csource.fastdfs.ClientGlobal;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
|
@ -36,7 +35,7 @@ public class ConnectionManager {
|
||||||
/**
|
/**
|
||||||
* free connections
|
* free connections
|
||||||
*/
|
*/
|
||||||
private volatile LinkedList<Connection> freeConnections = new LinkedList<Connection>();
|
private LinkedList<Connection> freeConnections = new LinkedList<Connection>();
|
||||||
|
|
||||||
private ConnectionManager() {
|
private ConnectionManager() {
|
||||||
|
|
||||||
|
@ -67,10 +66,10 @@ public class ConnectionManager {
|
||||||
//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");
|
throw new MyException("get connection fail,ip:port = " + inetSocketAddress.getHostName() + ":" + inetSocketAddress.getPort() + " ,wait_time > " + 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());
|
throw new MyException("get connection fail, ip:port = " + inetSocketAddress.getHostName() + ":" + inetSocketAddress.getPort() + ", emsg:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return connection;
|
return connection;
|
||||||
|
@ -103,7 +102,7 @@ public class ConnectionManager {
|
||||||
connection.closeDirectly();
|
connection.closeDirectly();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("close socket error , msg:" + e.getMessage());
|
System.err.println("close socket error,ip:port = " + inetSocketAddress.getHostName() + ":" + inetSocketAddress.getPort() + ",emsg:" + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue