use of com.bonree.brfs.common.net.tcp.client.TcpClientConfig in project BRFS by zhangnianli.
the class TcpClientUtils method getClient.
public static TcpDiskNodeClient getClient(String host, int port, int export, int timeout) throws InterruptedException, IOException {
TcpClient<BaseMessage, BaseResponse> tcpClient = group.createClient(new TcpClientConfig() {
@Override
public SocketAddress remoteAddress() {
return new InetSocketAddress(host, port);
}
@Override
public int connectTimeoutMillis() {
return timeout;
}
});
TcpClient<ReadObject, FileContentPart> readerClient = group2.createClient(new AsyncFileReaderCreateConfig() {
@Override
public SocketAddress remoteAddress() {
return new InetSocketAddress(host, export);
}
@Override
public int connectTimeoutMillis() {
return timeout;
}
@Override
public int maxPendingRead() {
return 0;
}
});
return new TcpDiskNodeClient(tcpClient, readerClient);
}
use of com.bonree.brfs.common.net.tcp.client.TcpClientConfig in project BRFS by zhangnianli.
the class TcpDiskNodeConnectionPool method getConnection.
@Override
public DiskNodeConnection getConnection(String serviceGroup, String serviceId) {
TcpDiskNodeConnection connection = connectionCache.get(serviceGroup, serviceId);
if (connection != null) {
if (connection.isValid()) {
return connection;
}
synchronized (connectionCache) {
connectionCache.remove(serviceGroup, serviceId);
}
}
try {
synchronized (connectionCache) {
Service service = serviceManager.getServiceById(serviceGroup, serviceId);
if (service == null) {
return null;
}
TcpClient<BaseMessage, BaseResponse> client = tcpClientGroup.createClient(new TcpClientConfig() {
@Override
public SocketAddress remoteAddress() {
return new InetSocketAddress(service.getHost(), service.getPort());
}
@Override
public int connectTimeoutMillis() {
return 3000;
}
}, executor);
if (client == null) {
return null;
}
connection = new TcpDiskNodeConnection(client);
connectionCache.put(serviceGroup, serviceId, connection);
}
return connection;
} catch (Exception e) {
LOG.error("connect tcp connection to disk node error", e);
}
return null;
}
Aggregations