| Apache Ignite C++

utils.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 #ifndef _IGNITE_JNI_UTILS
18 #define _IGNITE_JNI_UTILS
19
20 #include <string>
21
22 #include <ignite/common/common.h>
23 #include <ignite/common/concurrent.h>
24 #include <ignite/jni/java.h>
25
26 namespace ignite
27 {
28 namespace jni
29 {
33 class AttachHelper
34 {
35 public:
39 ~AttachHelper();
40
44 static void OnThreadAttach();
45 };
46
50 class IGNITE_IMPORT_EXPORT JavaGlobalRef
51 {
52 public:
56 JavaGlobalRef() :
57 obj(NULL)
58 {
59 // No-op.
60 }
61
68 JavaGlobalRef(common::concurrent::SharedPointer<java::JniContext>& ctx, jobject obj)
69 : obj(NULL)
70 {
71 Init(ctx, obj);
72 }
73
79 JavaGlobalRef(const JavaGlobalRef& other)
80 : obj(NULL)
81 {
82 Init(other.ctx, other.obj);
83 }
84
91 JavaGlobalRef& operator=(const JavaGlobalRef& other)
92 {
93 if (this != &other)
94 {
95 java::JniContext::Release(obj);
96
97 Init(other.ctx, other.obj);
98 }
99
100 return *this;
101 }
102
106 ~JavaGlobalRef()
107 {
108 java::JniContext::Release(obj);
109 }
110
116 jobject Get()
117 {
118 return obj;
119 }
120
121 private:
123 void Init(const common::concurrent::SharedPointer<java::JniContext>& ctx0, jobject obj0) {
124 ctx = ctx0;
125
126 if (ctx.IsValid())
127 this->obj = ctx.Get()->Acquire(obj0);
128 }
129
131 common::concurrent::SharedPointer<java::JniContext> ctx;
132
134 jobject obj;
135 };
136
145 IGNITE_IMPORT_EXPORT std::string FindJvmLibrary(const std::string& path);
146
153 IGNITE_IMPORT_EXPORT bool LoadJvmLibrary(const std::string& path);
154
162 IGNITE_IMPORT_EXPORT std::string CreateIgniteHomeClasspath(const std::string& home, bool forceTest);
163
171 IGNITE_IMPORT_EXPORT std::string CreateIgniteClasspath(const std::string& usrCp, const std::string& home);
172
186 IGNITE_IMPORT_EXPORT std::string ResolveIgniteHome(const std::string& path = "");
187 }
188 }
189
190 #endif //_IGNITE_JNI_UTILS
ignite::jni::AttachHelper
Helper class to manage attached threads.
Definition: utils.h:33
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::jni::JavaGlobalRef::JavaGlobalRef
JavaGlobalRef(common::concurrent::SharedPointer< java::JniContext > &ctx, jobject obj)
Constructor.
Definition: utils.h:68
ignite::jni::JavaGlobalRef::operator=
JavaGlobalRef & operator=(const JavaGlobalRef &other)
Assignment operator.
Definition: utils.h:91
ignite::jni::JavaGlobalRef::JavaGlobalRef
JavaGlobalRef(const JavaGlobalRef &other)
Copy constructor.
Definition: utils.h:79
ignite::jni::AttachHelper::OnThreadAttach
static void OnThreadAttach()
Callback invoked on successful thread attach ot JVM.
Definition: core/src/jni/os/linux/utils.cpp:73
ignite::jni::JavaGlobalRef
Represents global reference to Java object.
Definition: utils.h:50
ignite::jni::AttachHelper::~AttachHelper
~AttachHelper()
Destructor.
Definition: core/src/jni/os/linux/utils.cpp:68
ignite::jni::JavaGlobalRef::JavaGlobalRef
JavaGlobalRef()
Default constructor.
Definition: utils.h:56
ignite::jni::JavaGlobalRef::~JavaGlobalRef
~JavaGlobalRef()
Destructor.
Definition: utils.h:106
ignite::jni::JavaGlobalRef::Get
jobject Get()
Get object.
Definition: utils.h:116