From b74bc430077bfa16c7733149587fa1ea55c4aa2d Mon Sep 17 00:00:00 2001 From: Redkale Date: Mon, 16 Jan 2023 08:50:13 +0800 Subject: [PATCH] =?UTF-8?q?Client=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/redkale/net/client/Client.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/redkale/net/client/Client.java b/src/main/java/org/redkale/net/client/Client.java index efd4d4835..b67efd980 100644 --- a/src/main/java/org/redkale/net/client/Client.java +++ b/src/main/java/org/redkale/net/client/Client.java @@ -80,7 +80,7 @@ public abstract class Client, R extends ClientR protected Supplier closeRequestSupplier; //创建连接后进行的登录鉴权操作 - protected Function, CompletableFuture> authenticate; + protected Function> authenticate; protected Client(String name, AsyncGroup group, ClientAddress address) { this(name, group, true, address, Utility.cpus(), DEFAULT_MAX_PIPELINES, null, null, null); @@ -99,18 +99,18 @@ public abstract class Client, R extends ClientR } protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns, - Function, CompletableFuture> authenticate) { + Function> authenticate) { this(name, group, tcp, address, maxConns, DEFAULT_MAX_PIPELINES, null, null, authenticate); } protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns, - Supplier closeRequestSupplier, Function, CompletableFuture> authenticate) { + Supplier closeRequestSupplier, Function> authenticate) { this(name, group, tcp, address, maxConns, DEFAULT_MAX_PIPELINES, null, closeRequestSupplier, authenticate); } @SuppressWarnings("OverridableMethodCallInConstructor") protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns, - int maxPipelines, Supplier pingRequestSupplier, Supplier closeRequestSupplier, Function, CompletableFuture> authenticate) { + int maxPipelines, Supplier pingRequestSupplier, Supplier closeRequestSupplier, Function> authenticate) { if (maxPipelines < 1) { throw new IllegalArgumentException("maxPipelines must bigger 0"); } @@ -277,7 +277,10 @@ public abstract class Client, R extends ClientR } else { future = future.thenApply(conn -> (C) conn.readChannel()); } - return (authenticate == null ? future : authenticate.apply(future)).thenApply(c -> { + if (authenticate != null) { + future = future.thenCompose(authenticate); + } + return future.thenApply(c -> { c.setAuthenticated(true); this.connArray[index] = c; CompletableFuture f;