11 : obj_ (0), class_ (0),
12 run_method_ (0), init_method_ (0), cleanup_method_ (0)
24 "threads::JavaThread::destructor:" 25 " Deleting global references.\n");
27 jvm.
env->DeleteGlobalRef (
obj_);
36 "threads::JavaThread::assignment:" \
37 " Checking for source not being same as dest\n");
39 if (
this != &rhs &&
obj_ != rhs.
obj_)
41 JNIEnv * env = ::madara_jni_get_env ();
47 "threads::JavaThread::assignment:" \
48 " Deleting global references from left hand side\n");
50 env->DeleteGlobalRef (
obj_);
51 env->DeleteGlobalRef (
class_);
66 JNIEnv * env = jvm.
env;
69 "threads::JavaThread(%s)::run:" \
70 " Calling user-defined run method\n",
name.c_str ());
79 JNIEnv * env = jvm.
env;
82 "threads::JavaThread(%s)::cleanup:" \
83 " Calling user-defined cleanup method\n",
name.c_str ());
92 JNIEnv * env = jvm.
env;
95 "threads::JavaThread(%s)::init:" \
96 " Creating Java KnowledgeBase from data plane\n",
name.c_str ());
98 jclass kb_class = madara::utility::java::find_class (env,
99 "com/madara/KnowledgeBase");
101 jmethodID fromPointerCall = env->GetStaticMethodID (kb_class,
102 "fromPointer",
"(JZ)Lcom/madara/KnowledgeBase;");
104 jboolean manage (
false);
106 jobject jknowledge = env->CallStaticObjectMethod (kb_class,
107 fromPointerCall, (jlong) &context, manage);
110 "threads::JavaThread(%s)::init:" \
111 " Calling user-defined init method\n",
name.c_str ());
115 env->DeleteLocalRef (jknowledge);
116 env->DeleteWeakGlobalRef (kb_class);
138 JNIEnv * env = jvm.
env;
145 "threads::JavaThread(%s)::check_compliance:" \
146 " allocating global reference for object\n",
name.c_str ());
148 obj_ = (jobject) env->NewGlobalRef (obj);
153 "threads::JavaThread(%s)::check_compliance:" \
154 " allocating global reference for object's class\n",
name.c_str ());
156 class_ = (jclass) env->NewGlobalRef (env->GetObjectClass (obj_));
160 "threads::JavaThread(%s)::check_compliance:" \
161 " class and object obtained successfully\n",
name.c_str ());
167 "init",
"(Lcom/madara/KnowledgeBase;)V" );
174 "threads::JavaThread(%s)::check_compliance:" \
175 " ERROR: run method must be defined\n",
name.c_str ());
183 "threads::JavaThread(%s)::check_compliance:" \
184 " ERROR: init method must be defined\n",
name.c_str ());
192 "threads::JavaThread(%s)::check_compliance:" \
193 " ERROR: cleanup method must be defined\n",
name.c_str ());
201 "threads::JavaThread(%s)::check_compliance:" \
202 " ERROR: class object inaccessible\n",
name.c_str ());
210 "threads::JavaThread(%s)::check_compliance:" \
211 " ERROR: object is invalid\n",
name.c_str ());
219 "threads::JavaThread(%s)::check_compliance:" \
220 " ERROR: unable to acquire JAVA environment\n",
name.c_str ());
236 JNIEnv * env = ::madara_jni_get_env ();
239 "threads::JavaThread(%s)::init_control_vars:" \
240 " Populating user control plane variables\n",
name.c_str ());
243 jclass i_class = madara::utility::java::find_class (env,
244 "com/madara/containers/Integer");
245 jmethodID fromPointerCall = env->GetStaticMethodID (i_class,
246 "fromPointer",
"(JZ)Lcom/madara/containers/Integer;");
249 jboolean manage (
false);
252 jobject jterminate = env->CallStaticObjectMethod (i_class,
253 fromPointerCall, (jlong) &
terminated, manage);
254 jobject jpaused = env->CallStaticObjectMethod (i_class,
255 fromPointerCall, (jlong) &
paused, manage);
258 jfieldID fieldId = env->GetFieldID(
class_,
259 "terminated",
"Lcom/madara/containers/Integer;");
260 env->SetObjectField (
obj_, fieldId, jterminate);
262 fieldId = env->GetFieldID(
class_,
263 "paused",
"Lcom/madara/containers/Integer;");
264 env->SetObjectField (
obj_, fieldId, jpaused);
266 jvm.
env->DeleteWeakGlobalRef (i_class);
267 jvm.
env->DeleteLocalRef (jterminate);
268 jvm.
env->DeleteLocalRef (jpaused);
JNIEnv * env
The Java environment.
madara::knowledge::containers::Integer paused
thread safe paused flag that may be set by the Threader
jmethodID run_method_
handle to the run method
This class encapsulates attaching and detaching to a VM.
bool check_compliance(jobject obj)
Checks a Java object for compliance with com.madara.threads.BaseThread.
virtual void init_control_vars(knowledge::KnowledgeBase &control)
Initializes the Java thread implementation's control plane variables.
madara::knowledge::containers::Integer terminated
thread safe terminated flag that may be set by the Threader base
MADARA_Export utility::Refcounter< logger::Logger > global_logger
jclass class_
the class of the Java object obj_
virtual void run(void)
Executes the Java thread's logic.
Provides a quality-of-service-enabled threading library.
virtual void init_control_vars(knowledge::KnowledgeBase &control)
Initializes the Java thread implementation's control plane variables.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
virtual void cleanup(void)
Calls the Java cleanup method.
This class provides a distributed knowledge base to users.
void operator=(const JavaThread &rhs)
Assignment operator.
virtual void init(knowledge::KnowledgeBase &context)
Initializes Java thread with MADARA context.
jmethodID cleanup_method_
handle to the cleanup method
std::string name
The unique name of your thread.
Provides functions and classes for the distributed knowledge base.
jmethodID init_method_
handle to the init method
jobject obj_
the Java thread implementation of com.madara.threads.BaseThread
A facade for a user-defined Java thread class.
static JavaThread * create(jobject obj)
Creates a JavaThread.