client优化
This commit is contained in:
@@ -197,41 +197,36 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
|
|||||||
if (closed.compareAndSet(false, true)) {
|
if (closed.compareAndSet(false, true)) {
|
||||||
this.timeoutScheduler.shutdownNow();
|
this.timeoutScheduler.shutdownNow();
|
||||||
for (ClientConnection conn : this.connArray) {
|
for (ClientConnection conn : this.connArray) {
|
||||||
if (conn == null) {
|
closeConnection(conn);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final R closeReq = closeRequestSupplier == null ? null : closeRequestSupplier.get();
|
|
||||||
if (closeReq == null) {
|
|
||||||
conn.dispose(null);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
conn.writeChannel(closeReq).get(1, TimeUnit.SECONDS);
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
conn.dispose(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (AddressConnEntry<C> entry : this.connAddrEntrys.values()) {
|
for (AddressConnEntry<C> entry : this.connAddrEntrys.values()) {
|
||||||
ClientConnection conn = entry.connection;
|
closeConnection(entry.connection);
|
||||||
if (conn == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final R closeReq = closeRequestSupplier == null ? null : closeRequestSupplier.get();
|
|
||||||
if (closeReq == null) {
|
|
||||||
conn.dispose(null);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
conn.writeChannel(closeReq).get(1, TimeUnit.SECONDS);
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
conn.dispose(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.connAddrEntrys.clear();
|
this.connAddrEntrys.clear();
|
||||||
|
for (ClientConnection conn : this.localConnList) {
|
||||||
|
closeConnection(conn);
|
||||||
|
}
|
||||||
|
this.localConnList.clear();
|
||||||
group.close();
|
group.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void closeConnection(ClientConnection conn) {
|
||||||
|
if (conn == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final R closeReq = closeRequestSupplier == null ? null : closeRequestSupplier.get();
|
||||||
|
if (closeReq == null) {
|
||||||
|
conn.dispose(null);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
conn.writeChannel(closeReq).get(1, TimeUnit.SECONDS);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
conn.dispose(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final CompletableFuture<P> sendAsync(R request) {
|
public final CompletableFuture<P> sendAsync(R request) {
|
||||||
if (request.workThread == null) {
|
if (request.workThread == null) {
|
||||||
request.workThread = WorkThread.currWorkThread();
|
request.workThread = WorkThread.currWorkThread();
|
||||||
|
|||||||
Reference in New Issue
Block a user