Apache Mesos
zookeeper.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with 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 __ORG_APACHE_ZOOKEEPER_HPP__
18 #define __ORG_APACHE_ZOOKEEPER_HPP__
19 
20 #include <jvm/jvm.hpp>
21 
22 #include <jvm/java/io.hpp>
23 #include <jvm/java/net.hpp>
24 
25 
26 // Package 'org.apache.zookeeper.server'.
27 
28 namespace org {
29 namespace apache {
30 namespace zookeeper {
31 namespace server {
32 
33 // Package 'org.apache.zookeeper.server.persistence'.
34 
35 namespace persistence {
36 
38 {
39 public:
41  const java::io::File& snapDir)
42  {
43  static Jvm::Constructor constructor = Jvm::get()->findConstructor(
45  "org/apache/zookeeper/server/persistence/FileTxnSnapLog")
46  .constructor()
47  .parameter(Jvm::Class::named("java/io/File"))
48  .parameter(Jvm::Class::named("java/io/File")));
49 
50  object = Jvm::get()->invoke(
51  constructor, (jobject) dataDir, (jobject) snapDir);
52  }
53 };
54 
55 } // namespace persistence {
56 
57 
58 class SessionTracker : public Jvm::Object {};
59 
60 
62 extern const char ZOOKEEPERSERVER_SESSIONTRACKER[];
63 
64 
66 {
67 public:
68  class DataTreeBuilder : public Jvm::Object {};
69 
71  {
72  public:
74  {
75  static Jvm::Constructor constructor = Jvm::get()->findConstructor(
77  "org/apache/zookeeper/server/ZooKeeperServer$BasicDataTreeBuilder") // NOLINT(whitespace/line_length)
78  .constructor());
79 
80  object = Jvm::get()->invoke(constructor);
81  }
82  };
83 
85  const DataTreeBuilder& treeBuilder)
87  Jvm::Class::named("org/apache/zookeeper/server/ZooKeeperServer"))
88  {
89  static Jvm::Constructor constructor = Jvm::get()->findConstructor(
90  Jvm::Class::named("org/apache/zookeeper/server/ZooKeeperServer")
91  .constructor()
92  .parameter(
94  "org/apache/zookeeper/server/persistence/FileTxnSnapLog"))
95  .parameter(
97  "org/apache/zookeeper/server/ZooKeeperServer$DataTreeBuilder"))); // NOLINT(whitespace/line_length)
98 
99  object = Jvm::get()->invoke(
100  constructor, (jobject) txnLogFactory, (jobject) treeBuilder);
101 
102  // We need to "bind" the 'sessionTracker' Variable after we assign
103  // 'object' above so that '*this' is a Jvm::Object instance that
104  // doesn't point to a nullptr jobject.
105  sessionTracker.bind(*this);
106  }
107 
109  {
110  static Jvm::Method method = Jvm::get()->findMethod(
111  Jvm::Class::named("org/apache/zookeeper/server/ZooKeeperServer")
112  .method("setMaxSessionTimeout")
113  .parameter(Jvm::get()->intClass)
114  .returns(Jvm::get()->voidClass));
115 
116  Jvm::get()->invoke<void>(object, method, max);
117  }
118 
120  {
121  static Jvm::Method method = Jvm::get()->findMethod(
122  Jvm::Class::named("org/apache/zookeeper/server/ZooKeeperServer")
123  .method("setMinSessionTimeout")
124  .parameter(Jvm::get()->intClass)
125  .returns(Jvm::get()->voidClass));
126 
127  Jvm::get()->invoke<void>(object, method, min);
128  }
129 
131  {
132  static Jvm::Method method = Jvm::get()->findMethod(
133  Jvm::Class::named("org/apache/zookeeper/server/ZooKeeperServer")
134  .method("getMaxSessionTimeout")
135  .returns(Jvm::get()->intClass));
136 
137  return Jvm::get()->invoke<int>(object, method);
138  }
139 
141  {
142  static Jvm::Method method = Jvm::get()->findMethod(
143  Jvm::Class::named("org/apache/zookeeper/server/ZooKeeperServer")
144  .method("getMinSessionTimeout")
145  .returns(Jvm::get()->intClass));
146 
147  return Jvm::get()->invoke<int>(object, method);
148  }
149 
151  {
152  static Jvm::Method method = Jvm::get()->findMethod(
153  Jvm::Class::named("org/apache/zookeeper/server/ZooKeeperServer")
154  .method("getClientPort")
155  .returns(Jvm::get()->intClass));
156 
157  return Jvm::get()->invoke<int>(object, method);
158  }
159 
160  void closeSession(int64_t sessionId)
161  {
162  static Jvm::Method method = Jvm::get()->findMethod(
163  Jvm::Class::named("org/apache/zookeeper/server/ZooKeeperServer")
164  .method("closeSession")
165  .parameter(Jvm::get()->longClass)
166  .returns(Jvm::get()->voidClass));
167 
168  Jvm::get()->invoke<void>(object, method, sessionId);
169  }
170 
174 };
175 
176 
177 // TODO(benh): Extends ServerCnxnFactory implements Runnable.
179 {
180 public:
182  {
183  static Jvm::Constructor constructor = Jvm::get()->findConstructor(
185  "org/apache/zookeeper/server/NIOServerCnxnFactory")
186  .constructor());
187 
188  object = Jvm::get()->invoke(constructor);
189  }
190 
191  void configure(const java::net::InetSocketAddress& addr, int maxcc)
192  {
193  static Jvm::Method method = Jvm::get()->findMethod(
195  "org/apache/zookeeper/server/NIOServerCnxnFactory")
196  .method("configure")
197  .parameter(Jvm::Class::named("java/net/InetSocketAddress"))
198  .parameter(Jvm::get()->intClass)
199  .returns(Jvm::get()->voidClass));
200 
201 
202  Jvm::get()->invoke<void>(object, method, (jobject) addr, maxcc);
203  }
204 
205  void startup(const ZooKeeperServer& zks)
206  {
207  static Jvm::Method method = Jvm::get()->findMethod(
209  "org/apache/zookeeper/server/NIOServerCnxnFactory")
210  .method("startup")
211  .parameter(Jvm::Class::named(
212  "org/apache/zookeeper/server/ZooKeeperServer"))
213  .returns(Jvm::get()->voidClass));
214 
215  Jvm::get()->invoke<void>(object, method, (jobject) zks);
216  }
217 
218  void shutdown()
219  {
220  static Jvm::Method method = Jvm::get()->findMethod(
222  "org/apache/zookeeper/server/NIOServerCnxnFactory")
223  .method("shutdown")
224  .returns(Jvm::get()->voidClass));
225 
226  Jvm::get()->invoke<void>(object, method);
227  }
228 };
229 
230 } // namespace server {
231 } // namespace zookeeper {
232 } // namespace apache {
233 } // namespace org {
234 
235 #endif // __ORG_APACHE_ZOOKEEPER_HPP__
ZooKeeperServer(const persistence::FileTxnSnapLog &txnLogFactory, const DataTreeBuilder &treeBuilder)
Definition: zookeeper.hpp:84
Jvm::Variable< SessionTracker, ZOOKEEPERSERVER_SESSIONTRACKER, ZOOKEEPERSERVER_SESSIONTRACKER_SIGNATURE > sessionTracker
Definition: zookeeper.hpp:173
void setMinSessionTimeout(int min)
Definition: zookeeper.hpp:119
int getClientPort()
Definition: zookeeper.hpp:150
Definition: net.hpp:26
Constructor findConstructor(const ConstructorFinder &finder)
Method findMethod(const MethodSignature &signature)
Definition: jvm.hpp:144
NIOServerCnxnFactory()
Definition: zookeeper.hpp:181
Definition: jvm.hpp:295
Option< T > max(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:199
FileTxnSnapLog(const java::io::File &dataDir, const java::io::File &snapDir)
Definition: zookeeper.hpp:40
Definition: jvm.hpp:208
const char ZOOKEEPERSERVER_SESSIONTRACKER[]
Option< T > min(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:170
void closeSession(int64_t sessionId)
Definition: zookeeper.hpp:160
Definition: jvm.hpp:244
int getMinSessionTimeout()
Definition: zookeeper.hpp:140
int getMaxSessionTimeout()
Definition: zookeeper.hpp:130
static Jvm * get()
jobject object
Definition: jvm.hpp:287
void setMaxSessionTimeout(int max)
Definition: zookeeper.hpp:108
void configure(const java::net::InetSocketAddress &addr, int maxcc)
Definition: zookeeper.hpp:191
Definition: io.hpp:25
jobject invoke(const Constructor ctor,...)
void shutdown()
Definition: zookeeper.hpp:218
static const Class named(const std::string &name)
const char ZOOKEEPERSERVER_SESSIONTRACKER_SIGNATURE[]
Definition: jvm.hpp:50
void startup(const ZooKeeperServer &zks)
Definition: zookeeper.hpp:205
Class
Definition: elf.hpp:38