GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
org_graphlab_Aggregator.cpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
24 
25 using namespace graphlab;
26 
27 //---------------------------------------------------------------
28 // proxy_aggregator static members
29 //---------------------------------------------------------------
30 
31 jmethodID proxy_aggregator::java_exec = 0;
32 jmethodID proxy_aggregator::java_add = 0;
34 jmethodID proxy_aggregator::java_clone = 0;
35 
36 JNIEXPORT void JNICALL
37  Java_org_graphlab_Aggregator_initNative
38  (JNIEnv *env, jclass clazz){
39 
40  // Aggregator#exec
42  env->GetMethodID(clazz, "exec", "(JLorg/graphlab/data/Vertex;)V");
43 
44  // Aggregator#add
46  env->GetMethodID(clazz, "add", "(Lorg/graphlab/Aggregator;)V");
47 
48  // Aggregator#finalize
50  env->GetMethodID(clazz, "finalize", "(J)V");
51 
52  // Aggregator#clone
54  env->GetMethodID(clazz, "clone", "()Lorg/graphlab/Aggregator;");
55 
56 }
57 
58 //---------------------------------------------------------------
59 // proxy_aggregator instance members
60 //---------------------------------------------------------------
61 
63  proxy_aggregator(JNIEnv *env, jobject &obj)
64  : java_any(env, obj){}
65 
67  : java_any(){}
68 
71 
72  // other doesn't have an existing ref
73  if (NULL == other.obj()){
74  set_obj(NULL);
75  return;
76  }
77 
78  // clone the java object
79  JNIEnv *env = core::get_jni_env();
80  set_obj(env->CallObjectMethod(other.obj(), java_clone));
81 
82 }
83 
85 
86  if (this == &other) return *this;
87  java_any::operator=(other);
88  return *this;
89 
90 }
91 
93 
94 //---------------------------------------------------------------
95 // proxy_aggregator instance members - the update function
96 //---------------------------------------------------------------
97 
98 void proxy_aggregator::operator()(icontext_type& context){
99 
100  // forward call to org.graphlab.Aggregator#exec
101  JNIEnv *env = core::get_jni_env();
102  env->CallVoidMethod (obj(), java_exec,
103  &context,
104  context.vertex_data().obj());
105  handle_exception(env);
106 
107 }
108 
109 //---------------------------------------------------------------
110 // proxy_aggregator instance members - the add function
111 //---------------------------------------------------------------
112 
113 void proxy_aggregator::operator+=(const proxy_aggregator& other) {
114 
115  // forward call to org.graphlab.Aggregator#add
116  JNIEnv *env = core::get_jni_env();
117  env->CallVoidMethod (obj(), java_add, other.obj());
118  handle_exception(env);
119 
120 }
121 
122 //---------------------------------------------------------------
123 // proxy_aggregator instance members - the finalize function
124 //---------------------------------------------------------------
125 
126 void proxy_aggregator::finalize(iglobal_context& context){
127 
128  // forward call to org.graphlab.Aggregator#finalize
129  JNIEnv *env = core::get_jni_env();
130  env->CallVoidMethod (obj(), java_finalize, &context);
131  handle_exception(env);
132 
133 }