GridGain C++
compute_client.h
Go to the documentation of this file.
1 /*
2  * Copyright 2021 GridGain Systems, Inc. and Contributors.
3  *
4  * Licensed under the GridGain Community Edition License (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef _IGNITE_THIN_COMPUTE_COMPUTE_CLIENT
23 #define _IGNITE_THIN_COMPUTE_COMPUTE_CLIENT
24 
25 #include <ignite/common/concurrent.h>
26 
27 namespace ignite
28 {
29  namespace thin
30  {
31  namespace compute
32  {
34  {
35  enum Type
36  {
37  NONE = 0,
38  NO_FAILOVER = 1,
39  NO_RESULT_CACHE = 2
40  };
41  };
42 
52  class IGNITE_IMPORT_EXPORT ComputeClient
53  {
54  typedef common::concurrent::SharedPointer<void> SP_Void;
55  public:
60  {
61  // No-op.
62  }
63 
69  ComputeClient(const SP_Void& impl) :
70  impl(impl),
71  flags(ComputeClientFlags::NONE),
72  timeout(0)
73  {
74  // No-op.
75  }
76 
81  {
82  // No-op.
83  }
84 
95  template<typename R, typename A>
96  R ExecuteJavaTask(const std::string& taskName, const A& taskArg)
97  {
98  R result;
99 
100  impl::thin::WritableImpl<A> wrArg(taskArg);
101  impl::thin::ReadableImpl<R> rdResult(result);
102 
103  InternalExecuteJavaTask(taskName, wrArg, rdResult);
104 
105  return result;
106  }
107 
116  template<typename R>
117  R ExecuteJavaTask(const std::string& taskName)
118  {
119  R result;
120  int* nullVal = 0;
121 
122  impl::thin::WritableImpl<int*> wrArg(nullVal);
123  impl::thin::ReadableImpl<R> rdResult(result);
124 
125  InternalExecuteJavaTask(taskName, wrArg, rdResult);
126 
127  return result;
128  }
129 
136  ComputeClient WithTimeout(int64_t timeoutMs)
137  {
138  return ComputeClient(impl, flags, timeoutMs);
139  }
140 
148  {
149  return ComputeClient(impl, flags | ComputeClientFlags::NO_FAILOVER, timeout);
150  }
151 
158  {
159  return ComputeClient(impl, flags | ComputeClientFlags::NO_RESULT_CACHE, timeout);
160  }
161 
162  private:
170  ComputeClient(const SP_Void& impl, int8_t flags, int64_t timeout) :
171  impl(impl),
172  flags(flags),
173  timeout(timeout)
174  {
175  // No-op.
176  }
177 
185  void InternalExecuteJavaTask(const std::string& taskName, impl::thin::Writable& wrArg,
186  impl::thin::Readable& res);
187 
189  SP_Void impl;
190 
192  int8_t flags;
193 
195  int64_t timeout;
196  };
197  }
198  }
199 }
200 
201 #endif // _IGNITE_THIN_COMPUTE_COMPUTE_CLIENT
ignite
Ignite API.
Definition: cache.h:47
ignite::thin::compute::ComputeClient::WithNoFailover
ComputeClient WithNoFailover()
Returns a new instance of ComputeClient with disabled failover.
Definition: compute_client.h:147
ignite::thin::compute::ComputeClient::ExecuteJavaTask
R ExecuteJavaTask(const std::string &taskName)
Executes given Java task by class name.
Definition: compute_client.h:117
ignite::thin::compute::ComputeClient
Client Compute API.
Definition: compute_client.h:52
ignite::thin::compute::ComputeClient::ExecuteJavaTask
R ExecuteJavaTask(const std::string &taskName, const A &taskArg)
Executes given Java task by class name.
Definition: compute_client.h:96
ignite::thin::compute::ComputeClientFlags
Definition: compute_client.h:33
ignite::thin::compute::ComputeClient::ComputeClient
ComputeClient(const SP_Void &impl)
Constructor.
Definition: compute_client.h:69
ignite::thin::compute::ComputeClient::~ComputeClient
~ComputeClient()
Destructor.
Definition: compute_client.h:80
ignite::thin::compute::ComputeClient::WithTimeout
ComputeClient WithTimeout(int64_t timeoutMs)
Returns a new instance of ComputeClient with a timeout for all task executions.
Definition: compute_client.h:136
ignite::thin::compute::ComputeClient::ComputeClient
ComputeClient()
Default constructor.
Definition: compute_client.h:59
ignite::thin::compute::ComputeClient::WithNoResultCache
ComputeClient WithNoResultCache()
Returns a new instance of ComputeClient with disabled result cache.
Definition: compute_client.h:157
ignite::impl::thin::ReadableImpl
Definition: thin-client/include/ignite/thin/cache/cache_entry.h:35