You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/08/24 16:12:02 UTC

[GitHub] [ignite] ptupitsyn commented on a change in pull request #9354: IGNITE-15113 Add Compute for C++ thin client

ptupitsyn commented on a change in pull request #9354:
URL: https://github.com/apache/ignite/pull/9354#discussion_r694993095



##########
File path: modules/platforms/cpp/thin-client/include/ignite/thin/compute/compute_client.h
##########
@@ -0,0 +1,201 @@
+/*
+ * 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.
+ */
+
+/**
+ * @file
+ * Declares ignite::thin::compute::ComputeClient class.
+ */
+
+#ifndef _IGNITE_THIN_COMPUTE_COMPUTE_CLIENT
+#define _IGNITE_THIN_COMPUTE_COMPUTE_CLIENT
+
+#include <ignite/common/concurrent.h>
+
+namespace ignite
+{
+    namespace thin
+    {
+        namespace compute
+        {
+            struct ComputeClientFlags
+            {
+                enum Type
+                {
+                    NONE = 0,
+                    NO_FAILOVER = 1,
+                    NO_RESULT_CACHE = 2
+                };
+            };
+
+            /**
+             * Client Compute API.
+             *
+             * @see IgniteClient::GetCompute()
+             *
+             * This class is implemented as a reference to an implementation so copying of this class instance will only
+             * create another reference to the same underlying object. Underlying object will be released automatically
+             * once all the instances are destructed.
+             */
+            class IGNITE_IMPORT_EXPORT ComputeClient
+            {
+                typedef common::concurrent::SharedPointer<void> SP_Void;
+            public:
+                /**
+                 * Default constructor.
+                 */
+                ComputeClient()
+                {
+                    // No-op.
+                }
+
+                /**
+                 * Constructor.
+                 *
+                 * @param impl Implementation.
+                 */
+                ComputeClient(const SP_Void& impl) :
+                    impl(impl),
+                    flags(ComputeClientFlags::NONE),
+                    timeout(0)
+                {
+                    // No-op.
+                }
+
+                /**
+                 * Destructor.
+                 */
+                ~ComputeClient()
+                {
+                    // No-op.
+                }
+
+                /**
+                 * Executes given Java task by class name.
+                 *
+                 * @param taskName Java task name.
+                 * @param taskArg Argument of task execution of type A.
+                 * @return Task result of type @c R.
+                 *
+                 * @tparam R Type of task result.
+                 * @tparam A Type of task argument.
+                 */
+                template<typename R, typename A>
+                R ExecuteJavaTask(const std::string& taskName, const A& taskArg)
+                {
+                    R result;
+
+                    impl::thin::WritableImpl<A> wrArg(taskArg);
+                    impl::thin::ReadableImpl<R> rdResult(result);
+
+                    InternalExecuteJavaTask(taskName, wrArg, rdResult);
+
+                    return result;
+                }
+
+                /**
+                 * Executes given Java task by class name.
+                 *
+                 * @param taskName Java task name.
+                 * @return Task result of type @c R.
+                 *
+                 * @tparam R Type of task result.
+                 */
+                template<typename R>
+                R ExecuteJavaTask(const std::string& taskName)
+                {
+                    R result;
+
+                    impl::thin::WritableImpl<int*> wrArg(0);
+                    impl::thin::ReadableImpl<R> rdResult(result);
+
+                    InternalExecuteJavaTask(taskName, wrArg, rdResult);
+
+                    return result;
+                }
+
+                /**
+                 * Returns a new instance of ComputeClient with a timeout for all task executions.
+                 *
+                 * @param timeoutMs Timeout in milliseconds.
+                 * @return New ComputeClient instance with timeout.
+                 */
+                ComputeClient WithTimeout(int64_t timeoutMs)
+                {
+                    return ComputeClient(impl, flags, timeoutMs);
+                }
+
+                /**
+                 * Returns a new instance of ComputeClient with disabled failover.
+                 * When failover is disabled, compute jobs won't be retried in case of node crashes.
+                 *
+                 * @return New Compute instance with disabled failover.
+                 */
+                ComputeClient WithNoFailover()
+                {
+                    return ComputeClient(impl, flags | ComputeClientFlags::NO_FAILOVER, timeout);

Review comment:
       When current instance has the flag, we can return it as is.




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org