ptupitsyn commented on a change in pull request #7572: IGNITE-12835 Thin 
client: compute support
URL: https://github.com/apache/ignite/pull/7572#discussion_r400770612
 
 

 ##########
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientComputeImpl.java
 ##########
 @@ -0,0 +1,379 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.client.thin;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import org.apache.ignite.client.ClientClusterGroup;
+import org.apache.ignite.client.ClientCompute;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.ClientFeatureNotSupportedByServerException;
+import org.apache.ignite.client.ClientFuture;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.streams.BinaryHeapInputStream;
+import org.apache.ignite.internal.processors.platform.client.ClientFeature;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
+
+import static 
org.apache.ignite.internal.client.thin.ClientOperation.COMPUTE_TASK_EXECUTE;
+import static 
org.apache.ignite.internal.client.thin.ClientOperation.RESOURCE_CLOSE;
+
+/**
+ * Implementation of {@link ClientCompute}.
+ */
+class ClientComputeImpl implements ClientCompute, NotificationListener {
+    /** No failover flag mask. */
+    private static final byte NO_FAILOVER_FLAG_MASK = 0x01;
+
+    /** No result cache flag mask. */
+    private static final byte NO_RESULT_CACHE_FLAG_MASK = 0x02;
+
+    /** Channel. */
+    private final ReliableChannel ch;
+
+    /** Binary marshaller. */
+    private final ClientBinaryMarshaller marsh;
+
+    /** Utils for serialization/deserialization. */
+    private final ClientUtils utils;
+
+    /** ClientCluster instance. */
+    private final ClientClusterImpl cluster;
+
+    /** Active tasks. */
+    private final Map<ClientChannel, Map<Long, ClientComputeTask<Object>>> 
activeTasks = new ConcurrentHashMap<>();
+
+    /** Guard lock for active tasks. */
+    private final ReadWriteLock guard = new ReentrantReadWriteLock();
+
+    /** Constructor. */
+    ClientComputeImpl(ReliableChannel ch, ClientBinaryMarshaller marsh, 
ClientClusterImpl cluster) {
+        this.ch = ch;
+        this.marsh = marsh;
+        this.cluster = cluster;
+
+        utils = new ClientUtils(marsh);
+
+        ch.addNotificationListener(this);
+
+        ch.addChannelCloseListener(clientCh -> {
+            guard.writeLock().lock();
+
+            try {
+                Map<Long, ClientComputeTask<Object>> chTasks = 
activeTasks.remove(clientCh);
+
+                if (!F.isEmpty(chTasks)) {
+                    for (ClientComputeTask<?> task : chTasks.values())
+                        task.fut.onDone(new ClientException("Channel to server 
is closed"));
+                }
+            }
+            finally {
+                guard.writeLock().unlock();
+            }
+        });
+    }
+
+    /** {@inheritDoc} */
+    @Override public ClientClusterGroup clusterGroup() {
+        return cluster;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T, R> R execute(String taskName, @Nullable T arg) throws 
ClientException, InterruptedException {
+        return (R)executeAsync(taskName, arg).get();
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T, R> ClientFuture<R> executeAsync(String taskName, 
@Nullable T arg) throws ClientException {
+        return executeAsync0(taskName, arg, cluster, (byte)0, 0L);
+    }
+
+    /** {@inheritDoc} */
+    @Override public ClientCompute withTimeout(long timeout) {
+        return timeout == 0L ? this : new ClientComputeModificator(this, 
cluster, (byte)0, timeout);
+    }
+
+    /** {@inheritDoc} */
+    @Override public ClientCompute withNoFailover() {
+        return new ClientComputeModificator(this, cluster, 
NO_FAILOVER_FLAG_MASK, 0L);
+    }
+
+    /** {@inheritDoc} */
+    @Override public ClientCompute withNoResultCache() {
+        return new ClientComputeModificator(this, cluster, 
NO_RESULT_CACHE_FLAG_MASK, 0L);
+    }
+
+    /**
+     * Gets compute facade over the specified cluster group.
+     *
+     * @param grp Cluster group.
+     */
+    public ClientCompute withClusterGroup(ClientClusterGroupImpl grp) {
+        return new ClientComputeModificator(this, grp, (byte)0, 0L);
+    }
+
+    /**
+     * @param taskName Task name.
+     * @param arg Argument.
+     */
+    private <T, R> ClientFuture<R> executeAsync0(
+        String taskName,
 
 Review comment:
   `taskName` is never validated against null or empty string

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to