GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
org_graphlab_Updater.hpp
Go to the documentation of this file.
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 
23 /**
24  * @file org_graphlab_Updater.hpp
25  * @author Jiunn Haur Lim <[email protected]>
26  */
27 
28 #ifndef ORG_GRAPHLAB_UPDATER_HPP
29 #define ORG_GRAPHLAB_UPDATER_HPP
30 
31 #include <graphlab.hpp>
32 #include "java_any.hpp"
33 #include "org_graphlab_Core.hpp"
34 #include "org_graphlab_Updater.h"
35 
36 namespace graphlab {
37 
38  /** Proxy edge */
39  class proxy_edge : public java_any {
40  public:
41  /**
42  * Creates a new proxy_edge and a new reference to the associated
43  * Java Edge object (so that it doesn't get garbage collected.)
44  * @param[in] env JNI environment, which will be used to create the
45  * reference to the Java object.
46  * @param[in] obj associated org.graphlab.Core object.
47  */
48  proxy_edge (JNIEnv *env, jobject &obj) : java_any (env, obj) {}
49  };
50 
51  /** Proxy vertex */
52  class proxy_vertex : public java_any {
53  public:
54  proxy_vertex () : java_any () {}
55  /**
56  * Creates a new proxy_vertex and a new reference to the associated
57  * Java Vertex object (so that it doesn't get garbage collected.)
58  * @param[in] env JNI environment, which will be used to create the
59  * reference to the Java object.
60  * @param[in] obj associated org.graphlab.Core object.
61  */
62  proxy_vertex (JNIEnv *env, jobject &obj) : java_any (env, obj) {}
63  };
64 
65  /** Proxy graph */
66  typedef graph<proxy_vertex, proxy_edge> proxy_graph;
67 
68  /**
69  * Proxy updater.
70  * Mirrors and forwards update calls to the corresponding Java updater.
71  * The constructor creates a new reference to the Java object (so that it
72  * doesn't get garbage collected.) The destructor will delete the reference
73  * to allow the corresponding Java object to be garbaged collected. The copy
74  * constructor clones the Java object.
75  *
76  * Note that multiple proxy_updaters may correspond to the same
77  * org.graphlab.Updater object.
78  */
79  class proxy_updater :
80  public iupdate_functor<proxy_graph, proxy_updater>,
81  public java_any {
82 
83  public:
84 
85  /** jni_core type that uses the proxy graph and the proxy updater */
87 
88  /** context type that uses the proxy graph and the proxy updater */
89  typedef iupdate_functor<proxy_graph, proxy_updater>::icontext_type context;
90 
91  /** Method ID of org.graphlab.Updater#update */
92  static jmethodID java_update;
93 
94  /** Method ID of org.graphlab.Updater#add */
95  static jmethodID java_add;
96 
97  /** Method ID of org.graphlab.Updater#priority */
98  static jmethodID java_priority;
99 
100  /** Method ID of org.graphlab.Updater#clone */
101  static jmethodID java_clone;
102 
103  /** Method ID of org.graphlab.Updater#isFactorizable */
104  static jmethodID java_is_factorizable;
105 
106  /** Method ID of org.graphlab.Updater#gatherEdges */
107  static jmethodID java_gather_edges;
108 
109  /** Method ID of org.graphlab.Updater#scatterEdges */
110  static jmethodID java_scatter_edges;
111 
112  /** Method ID of org.graphlab.Updater#consistency */
113  static jmethodID java_consistency;
114 
115  /** Method ID of org.graphlab.Updater#gatherConsistency */
116  static jmethodID java_gather_consistency;
117 
118  /** Method ID of org.graphlab.Updater#scatterConsistency */
119  static jmethodID java_scatter_consistency;
120 
121  /** Method ID of org.graphlab.Updater#initGather */
122  static jmethodID java_init_gather;
123 
124  /** Method ID of org.graphlab.Updater#gather */
125  static jmethodID java_gather;
126 
127  /** Method ID of org.graphlab.Updater#merge */
128  static jmethodID java_merge;
129 
130  /** Method ID of org.graphlab.Updater#apply */
131  static jmethodID java_apply;
132 
133  /** Method ID of org.graphlab.Updater#scatter */
134  static jmethodID java_scatter;
135 
136  /**
137  * Constructor for proxy updater.
138  * Initializes this object with the associated Java org.graphlab.Updater
139  * object.
140  * @param[in] env JNI environment - used to create a new reference
141  * to javaUpdater.
142  * @param[in] java_updater Java org.graphlab.Updater object. This constructor
143  * will create a new reference to the object to prevent
144  * garbage collection.
145  */
146  proxy_updater(JNIEnv *env, jobject &java_updater);
147 
148  /** The default constructor does nothing */
149  proxy_updater();
150 
151  /**
152  * Copy constructor for proxy_updater.
153  * If \c other has a \c mjava_updater, creates a new reference to it.
154  */
155  proxy_updater(const proxy_updater& other);
156 
157  /**
158  * Copy assignment operator for proxy_updater.
159  * If \c other has a \c mjava_updater, creates a new reference to it.
160  */
161  proxy_updater &operator=(const proxy_updater &other);
162 
163  /**
164  * Deletes the reference to the Java object so that it may be garbage
165  * collected.
166  */
167  ~proxy_updater();
168 
169  void operator()(icontext_type& context);
170  void operator+=(const update_functor_type& other) const;
171  bool is_factorizable() const;
172  edge_set gather_edges() const;
173  edge_set scatter_edges() const;
174  consistency_model consistency() const;
175  consistency_model gather_consistency() const;
176  consistency_model scatter_consistency() const;
177  void init_gather(icontext_type& context);
178  void gather(icontext_type& context, const edge_type& edge);
179  void merge(const update_functor_type& other);
180  void apply(icontext_type& context);
181  void scatter(icontext_type& context, const edge_type& edge);
182 
183  };
184 
185 }
186 
187 #endif