ptupitsyn commented on code in PR #12732:
URL: https://github.com/apache/ignite/pull/12732#discussion_r2798734507


##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java:
##########
@@ -17,172 +17,19 @@
 
 package org.apache.ignite.internal.client.thin;
 
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ForkJoinPool;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.function.BiFunction;
 import java.util.function.Consumer;
 import java.util.function.Function;
-import java.util.stream.Collectors;
-import org.apache.ignite.IgniteBinary;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.client.ClientAuthenticationException;
 import org.apache.ignite.client.ClientAuthorizationException;
-import org.apache.ignite.client.ClientConnectionException;
 import org.apache.ignite.client.ClientException;
-import org.apache.ignite.client.ClientOperationType;
-import org.apache.ignite.client.ClientPartitionAwarenessMapperFactory;
-import org.apache.ignite.client.ClientRetryPolicy;
-import org.apache.ignite.client.ClientRetryPolicyContext;
 import org.apache.ignite.client.IgniteClientFuture;
-import org.apache.ignite.configuration.ClientConfiguration;
-import org.apache.ignite.internal.client.thin.io.ClientConnectionMultiplexer;
-import 
org.apache.ignite.internal.client.thin.io.gridnioserver.GridNioClientConnectionMultiplexer;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.logger.NullLogger;
-import org.jetbrains.annotations.Nullable;
 
 /**
- * Communication channel with failover and partition awareness.
+ * Interface for communication channel with failover and partition awareness.
  */
-final class ReliableChannel implements AutoCloseable {
-    /** Channel factory. */
-    private final BiFunction<ClientChannelConfiguration, 
ClientConnectionMultiplexer, ClientChannel> chFactory;
-
-    /** Client channel holders for each configured address. */
-    private volatile List<ClientChannelHolder> channels;
-
-    /**
-     * Limit of attempts to execute each {@link #service}.
-     * Each channel is tried twice, and both attempts count as a single 
attempt toward this limit.
-     */
-    private volatile int attemptsLimit;
-
-    /** Index of the current channel. */
-    private volatile int curChIdx = -1;
-
-    /** Partition awareness enabled. */
-    final boolean partitionAwarenessEnabled;
-
-    /** Cache partition awareness context. */
-    private final ClientCacheAffinityContext affinityCtx;
-
-    /** Nodes discovery context. */
-    private final ClientDiscoveryContext discoveryCtx;
-
-    /** Client configuration. */
-    private final ClientConfiguration clientCfg;
-
-    /** Logger. */
-    private final IgniteLogger log;
-
-    /** Node channels. */
-    private final Map<UUID, ClientChannelHolder> nodeChannels = new 
ConcurrentHashMap<>();
-
-    /** Channels reinit was scheduled. */
-    private final AtomicBoolean scheduledChannelsReinit = new AtomicBoolean();
-
-    /** Timestamp of start of channels reinitialization. */
-    private volatile long startChannelsReInit;
-
-    /** Timestamp of finish of channels reinitialization. */
-    private volatile long finishChannelsReInit;
-
-    /** Affinity map update is in progress. */
-    private final AtomicBoolean affinityUpdateInProgress = new AtomicBoolean();
-
-    /** Channel is closed. */
-    private volatile boolean closed;
-
-    /** Fail (disconnect) listeners. */
-    private final ArrayList<Runnable> chFailLsnrs = new ArrayList<>();
-
-    /** Guard channels and curChIdx together. */
-    private final ReadWriteLock curChannelsGuard = new 
ReentrantReadWriteLock();
-
-    /** Connection manager. */
-    private final ClientConnectionMultiplexer connMgr;
-
-    /** Open channels counter. */
-    private final AtomicInteger channelsCnt = new AtomicInteger();
-
-    /**
-     * Constructor.
-     */
-    ReliableChannel(
-            BiFunction<ClientChannelConfiguration, 
ClientConnectionMultiplexer, ClientChannel> chFactory,
-            ClientConfiguration clientCfg,
-            IgniteBinary binary
-    ) {
-        if (chFactory == null)
-            throw new NullPointerException("chFactory");
-
-        if (clientCfg == null)
-            throw new NullPointerException("clientCfg");
-
-        this.clientCfg = clientCfg;
-        this.chFactory = chFactory;
-        log = NullLogger.whenNull(clientCfg.getLogger());
-
-        partitionAwarenessEnabled = clientCfg.isPartitionAwarenessEnabled();
-
-        String dcId = 
IgniteSystemProperties.getString(IgniteSystemProperties.IGNITE_DATA_CENTER_ID);
-
-        if (dcId == null && !F.isEmpty(clientCfg.getUserAttributes()))
-            dcId = 
clientCfg.getUserAttributes().get(IgniteSystemProperties.IGNITE_DATA_CENTER_ID);
-
-        affinityCtx = new ClientCacheAffinityContext(
-            binary,
-            clientCfg.getPartitionAwarenessMapperFactory(),
-            this::isConnectionEstablished,
-            dcId
-        );
-
-        discoveryCtx = new ClientDiscoveryContext(clientCfg);
-
-        connMgr = new GridNioClientConnectionMultiplexer(clientCfg);
-        connMgr.start();
-
-        if (log.isDebugEnabled())
-            log.debug("ReliableChannel created");
-    }
-
-    /** {@inheritDoc} */
-    @Override public synchronized void close() {
-        if (log.isDebugEnabled())
-            log.debug("ReliableChannel stopping");
-
-        closed = true;
-
-        connMgr.stop();
-
-        List<ClientChannelHolder> holders = channels;
-
-        if (holders != null) {
-            for (ClientChannelHolder hld: holders)
-                hld.close();
-        }
-
-        if (log.isDebugEnabled())
-            log.debug("ReliableChannel stopped");
-    }
-
+interface ReliableChannel extends AutoCloseable {

Review Comment:
   The diff is huge. I think if we keep `ReliableChannel` class as is and 
rename the new interface to something else, the diff will be smaller.
   
   Also we could make a separate PR for refactoring - "make the change easy 
then make the easy change".



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to