| Apache Ignite C++

ignite_binding.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_IGNITE_BINDING
24 #define _IGNITE_IGNITE_BINDING
25
26 #include <ignite/common/common.h>
27 #include <ignite/common/concurrent.h>
28
29 #include <ignite/impl/ignite_binding_impl.h>
30 #include <ignite/impl/bindings.h>
31
32 namespace ignite
33 {
38 class IGNITE_IMPORT_EXPORT IgniteBinding
39 {
40 public:
44 IgniteBinding() :
45 impl()
46 {
47 // No-op.
48 }
49
55 IgniteBinding(common::concurrent::SharedPointer<impl::IgniteBindingImpl> impl) :
56 impl(impl)
57 {
58 // No-op.
59 }
60
67 template<typename P>
68 void RegisterCacheEntryProcessor()
69 {
70 IgniteError err;
71
72 RegisterCacheEntryProcessor<P>(err);
73
74 IgniteError::ThrowIfNeeded(err);
75 }
76
85 template<typename P>
86 void RegisterCacheEntryProcessor(IgniteError& err)
87 {
88 impl::IgniteBindingImpl *im = impl.Get();
89
90 if (im)
91 {
92 im->RegisterCallback(impl::IgniteBindingImpl::CallbackType::CACHE_ENTRY_PROCESSOR_APPLY,
93 binary::BinaryType<P>::GetTypeId(), impl::binding::ListenerApply<P, typename P::KeyType,
94 typename P::ValueType, typename P::ReturnType, typename P::ArgumentType>, err);
95 }
96 else
97 {
98 err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
99 "Instance is not usable (did you check for error?).");
100 }
101 }
102
109 template<typename F>
110 void RegisterCacheEntryEventFilter()
111 {
112 impl::IgniteBindingImpl *im = impl.Get();
113
114 int32_t typeId = binary::BinaryType<F>::GetTypeId();
115
116 if (im)
117 {
118 im->RegisterCallback(impl::IgniteBindingImpl::CallbackType::CACHE_ENTRY_FILTER_CREATE,
119 typeId, impl::binding::FilterCreate<F>);
120 }
121 else
122 {
123 throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
124 "Instance is not usable (did you check for error?).");
125 }
126 }
127
134 template<typename F>
135 void RegisterComputeFunc()
136 {
137 impl::IgniteBindingImpl *im = impl.Get();
138
139 int32_t typeId = binary::BinaryType<F>::GetTypeId();
140
141 if (im)
142 {
143 im->RegisterCallback(impl::IgniteBindingImpl::CallbackType::COMPUTE_JOB_CREATE,
144 typeId, impl::binding::ComputeJobCreate<F, typename F::ReturnType>);
145 }
146 else
147 {
148 throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
149 "Instance is not usable (did you check for error?).");
150 }
151 }
152
163 bool IsValid() const
164 {
165 return impl.IsValid();
166 }
167
168 private:
170 common::concurrent::SharedPointer<impl::IgniteBindingImpl> impl;
171 };
172 }
173
174 #endif //_IGNITE_IGNITE_BINDING
ignite::IgniteBinding
Ignite Binding.
Definition: ignite_binding.h:38
ignite::IgniteBinding::IsValid
bool IsValid() const
Check if the instance is valid.
Definition: ignite_binding.h:163
ignite::IgniteBinding::RegisterCacheEntryProcessor
void RegisterCacheEntryProcessor()
Register type as Cache Entry Processor.
Definition: ignite_binding.h:68
ignite::IgniteBinding::IgniteBinding
IgniteBinding()
Default constructor.
Definition: ignite_binding.h:44
ignite::IgniteBinding::RegisterComputeFunc
void RegisterComputeFunc()
Register type as Compute function.
Definition: ignite_binding.h:135
ignite::binary::BinaryType
Binary type structure.
Definition: binary_type.h:149
ignite::IgniteError
Ignite error information.
Definition: ignite_error.h:94
ignite::IgniteBinding::RegisterCacheEntryEventFilter
void RegisterCacheEntryEventFilter()
Register type as Cache Entry Event Filter.
Definition: ignite_binding.h:110
ignite::IgniteBinding::RegisterCacheEntryProcessor
void RegisterCacheEntryProcessor(IgniteError &err)
Register Type as Cache Entry Processor.
Definition: ignite_binding.h:86
ignite::IgniteBinding::IgniteBinding
IgniteBinding(common::concurrent::SharedPointer< impl::IgniteBindingImpl > impl)
Constructor.
Definition: ignite_binding.h:55
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::IgniteError::ThrowIfNeeded
static void ThrowIfNeeded(const IgniteError &err)
Throw an error if code is not IGNITE_SUCCESS.
Definition: ignite_error.cpp:27
ignite::IgniteError::IGNITE_ERR_GENERIC
static const int IGNITE_ERR_GENERIC
Generic Ignite error.
Definition: ignite_error.h:131