Apache Ignite C++
compute_client.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
23 #ifndef _IGNITE_THIN_COMPUTE_COMPUTE_CLIENT
24 #define _IGNITE_THIN_COMPUTE_COMPUTE_CLIENT
25 
26 #include <ignite/common/concurrent.h>
27 
28 namespace ignite
29 {
30  namespace thin
31  {
32  namespace compute
33  {
35  {
36  enum Type
37  {
38  NONE = 0,
39  NO_FAILOVER = 1,
40  NO_RESULT_CACHE = 2
41  };
42  };
43 
53  class IGNITE_IMPORT_EXPORT ComputeClient
54  {
55  typedef common::concurrent::SharedPointer<void> SP_Void;
56  public:
61  {
62  // No-op.
63  }
64 
70  ComputeClient(const SP_Void& impl) :
71  impl(impl),
72  flags(ComputeClientFlags::NONE),
73  timeout(0)
74  {
75  // No-op.
76  }
77 
82  {
83  // No-op.
84  }
85 
96  template<typename R, typename A>
97  R ExecuteJavaTask(const std::string& taskName, const A& taskArg)
98  {
99  R result;
100 
101  impl::thin::WritableImpl<A> wrArg(taskArg);
102  impl::thin::ReadableImpl<R> rdResult(result);
103 
104  InternalExecuteJavaTask(taskName, wrArg, rdResult);
105 
106  return result;
107  }
108 
117  template<typename R>
118  R ExecuteJavaTask(const std::string& taskName)
119  {
120  R result;
121  int* nullVal = 0;
122 
123  impl::thin::WritableImpl<int*> wrArg(nullVal);
124  impl::thin::ReadableImpl<R> rdResult(result);
125 
126  InternalExecuteJavaTask(taskName, wrArg, rdResult);
127 
128  return result;
129  }
130 
137  ComputeClient WithTimeout(int64_t timeoutMs)
138  {
139  return ComputeClient(impl, flags, timeoutMs);
140  }
141 
149  {
150  return ComputeClient(impl, flags | ComputeClientFlags::NO_FAILOVER, timeout);
151  }
152 
159  {
160  return ComputeClient(impl, flags | ComputeClientFlags::NO_RESULT_CACHE, timeout);
161  }
162 
163  private:
171  ComputeClient(const SP_Void& impl, int8_t flags, int64_t timeout) :
172  impl(impl),
173  flags(flags),
174  timeout(timeout)
175  {
176  // No-op.
177  }
178 
186  void InternalExecuteJavaTask(const std::string& taskName, impl::thin::Writable& wrArg,
187  impl::thin::Readable& res);
188 
190  SP_Void impl;
191 
193  int8_t flags;
194 
196  int64_t timeout;
197  };
198  }
199  }
200 }
201 
202 #endif // _IGNITE_THIN_COMPUTE_COMPUTE_CLIENT
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::thin::compute::ComputeClient::WithNoFailover
ComputeClient WithNoFailover()
Returns a new instance of ComputeClient with disabled failover.
Definition: compute_client.h:148
ignite::thin::compute::ComputeClient::ExecuteJavaTask
R ExecuteJavaTask(const std::string &taskName)
Executes given Java task by class name.
Definition: compute_client.h:118
ignite::thin::compute::ComputeClient
Client Compute API.
Definition: compute_client.h:53
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:97
ignite::thin::compute::ComputeClientFlags
Definition: compute_client.h:34
ignite::thin::compute::ComputeClient::ComputeClient
ComputeClient(const SP_Void &impl)
Constructor.
Definition: compute_client.h:70
ignite::thin::compute::ComputeClient::~ComputeClient
~ComputeClient()
Destructor.
Definition: compute_client.h:81
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:137
ignite::thin::compute::ComputeClient::ComputeClient
ComputeClient()
Default constructor.
Definition: compute_client.h:60
ignite::thin::compute::ComputeClient::WithNoResultCache
ComputeClient WithNoResultCache()
Returns a new instance of ComputeClient with disabled result cache.
Definition: compute_client.h:158
ignite::impl::thin::ReadableImpl
Definition: thin-client/include/ignite/thin/cache/cache_entry.h:36