Apache Ignite C++
ignite_binding.h
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 
18 #ifndef _IGNITE_IGNITE_BINDING
19 #define _IGNITE_IGNITE_BINDING
20 
21 #include <ignite/common/common.h>
22 #include <ignite/common/concurrent.h>
23 
24 #include <ignite/impl/ignite_binding_impl.h>
25 #include <ignite/impl/bindings.h>
26 
27 namespace ignite
28 {
33  class IGNITE_IMPORT_EXPORT IgniteBinding
34  {
35  public:
40  impl()
41  {
42  // No-op.
43  }
44 
50  IgniteBinding(common::concurrent::SharedPointer<impl::IgniteBindingImpl> impl) :
51  impl(impl)
52  {
53  // No-op.
54  }
55 
62  template<typename P>
64  {
65  IgniteError err;
66 
67  RegisterCacheEntryProcessor<P>(err);
68 
70  }
71 
80  template<typename P>
82  {
83  impl::IgniteBindingImpl *im = impl.Get();
84 
85  if (im)
86  {
87  im->RegisterCallback(impl::IgniteBindingImpl::CallbackType::CACHE_ENTRY_PROCESSOR_APPLY,
88  binary::BinaryType<P>::GetTypeId(), impl::binding::ListenerApply<P, typename P::KeyType,
89  typename P::ValueType, typename P::ReturnType, typename P::ArgumentType>, err);
90  }
91  else
92  {
94  "Instance is not usable (did you check for error?).");
95  }
96  }
97 
104  template<typename F>
106  {
107  impl::IgniteBindingImpl *im = impl.Get();
108 
109  int32_t typeId = binary::BinaryType<F>::GetTypeId();
110 
111  if (im)
112  {
113  im->RegisterCallback(impl::IgniteBindingImpl::CallbackType::CACHE_ENTRY_FILTER_CREATE,
114  typeId, impl::binding::FilterCreate<F>);
115  }
116  else
117  {
119  "Instance is not usable (did you check for error?).");
120  }
121  }
122 
129  template<typename F>
131  {
132  impl::IgniteBindingImpl *im = impl.Get();
133 
134  int32_t typeId = binary::BinaryType<F>::GetTypeId();
135 
136  if (im)
137  {
138  im->RegisterCallback(impl::IgniteBindingImpl::CallbackType::COMPUTE_JOB_CREATE,
139  typeId, impl::binding::ComputeJobCreate<F, typename F::ReturnType>);
140  }
141  else
142  {
144  "Instance is not usable (did you check for error?).");
145  }
146  }
147 
158  bool IsValid() const
159  {
160  return impl.IsValid();
161  }
162 
163  private:
165  common::concurrent::SharedPointer<impl::IgniteBindingImpl> impl;
166  };
167 }
168 
169 #endif //_IGNITE_IGNITE_BINDING
Ignite Binding.
Definition: ignite_binding.h:33
void RegisterCacheEntryProcessor()
Register type as Cache Entry Processor.
Definition: ignite_binding.h:63
bool IsValid() const
Check if the instance is valid.
Definition: ignite_binding.h:158
IgniteBinding()
Default constructor.
Definition: ignite_binding.h:39
void RegisterComputeFunc()
Register type as Compute function.
Definition: ignite_binding.h:130
Binary type structure.
Definition: binary_type.h:149
Ignite error information.
Definition: ignite_error.h:94
void RegisterCacheEntryEventFilter()
Register type as Cache Entry Event Filter.
Definition: ignite_binding.h:105
void RegisterCacheEntryProcessor(IgniteError &err)
Register Type as Cache Entry Processor.
Definition: ignite_binding.h:81
IgniteBinding(common::concurrent::SharedPointer< impl::IgniteBindingImpl > impl)
Constructor.
Definition: ignite_binding.h:50
Apache Ignite API.
Definition: cache.h:48
static void ThrowIfNeeded(const IgniteError &err)
Throw an error if code is not IGNITE_SUCCESS.
Definition: ignite_error.cpp:27
static const int IGNITE_ERR_GENERIC
Generic Ignite error.
Definition: ignite_error.h:131