Derecho  0.9
Distributed systems toolkit for RDMA
ObjectStoreService.cpp
Go to the documentation of this file.
3 #include <derecho/conf/conf.hpp>
4 #include <iostream>
5 #include <sstream>
6 #include <string.h>
7 void throwJavaException(JNIEnv* env, const char* msg) {
8  jclass Exception = env->FindClass("java/lang/Exception");
9  env->ThrowNew(Exception, msg);
10 }
11 int argc;
12 char** argv;
13 
14 JNIEXPORT void JNICALL
15 Java_com_derecho_objectstore_ObjectStoreService_put(JNIEnv* env, jobject obj, jlong oid, jstring jdata) {
16  const char* data = env->GetStringUTFChars(jdata, NULL);
17  objectstore::Object object(oid, data, strlen(data) + 1);
18 
19  try {
21  [&](const objectstore::OID& oid, const objectstore::Object& object) {
22  std::cout << "watcher: " << oid << "->" << object << std::endl;
23  });
24  oss.bio_put(object);
25  } catch(std::exception& ex) {
26  throwJavaException(env, ex.what());
27  } catch(...) {
28  throwJavaException(env, "Caught unknown exception in put.");
29  }
30 }
31 
32 JNIEXPORT jboolean JNICALL Java_com_derecho_objectstore_ObjectStoreService_remove(JNIEnv* env, jobject obj, jlong oid) {
34  [&](const objectstore::OID& oid, const objectstore::Object& object) {
35  std::cout << "watcher: " << oid << "->" << object << std::endl;
36  });
37  try {
38  oss.bio_remove(oid);
39  return true;
40  } catch(...) {
41  std::cout << "error in remove" << std::endl;
42  return false;
43  }
44 }
45 
46 JNIEXPORT jstring JNICALL Java_com_derecho_objectstore_ObjectStoreService_get(JNIEnv* env, jobject obj, jlong oid) {
47  try {
49  [&](const objectstore::OID& oid, const objectstore::Object& object) {
50  std::cout << "watcher: " << oid << "->" << object << std::endl;
51  });
52  objectstore::Object obj = oss.bio_get(oid);
53  std::cout << obj;
54  std::stringstream ss;
55  ss << std::cout.rdbuf();
56  std::string str = ss.str();
57  return env->NewStringUTF(str.c_str());
58  } catch(...) {
59  return NULL;
60  }
61 }
62 
63 JNIEXPORT void JNICALL Java_com_derecho_objectstore_ObjectStoreService_leave(JNIEnv* env, jobject obj) {
64  try {
66  [&](const objectstore::OID& oid, const objectstore::Object& object) {
67  std::cout << "watcher: " << oid << "->" << object << std::endl;
68  });
69  oss.leave();
70  } catch(...) {
71  throwJavaException(env, "Caught unknown exception in remove.");
72  }
73 }
74 
75 JNIEXPORT void JNICALL Java_com_derecho_objectstore_ObjectStoreService_initialize(JNIEnv* env, jobject obj, jstring jargv) {
76  const char* argv_str = env->GetStringUTFChars(jargv, NULL);
77 
78  // parsing argv
79  char* argv_copy = strdup(argv_str);
80  char* tokens[50];
81  int n = 0;
82 
83  for(char* p = strtok(argv_copy, " "); p; p = strtok(NULL, " ")) {
84  if(n >= 50) {
85  // maximum number of storable tokens exceeded
86  break;
87  }
88  tokens[n++] = p;
89  }
90 
91  argc = n;
92  argv = tokens;
93  try {
95 
96  } catch(std::exception& ex) {
97  throwJavaException(env, ex.what());
98  } catch(...) {
99  throwJavaException(env, "Caught unknown exception in init.");
100  }
101 }
static IObjectStoreService & getObjectStoreService(int argc, char **argv, const ObjectWatcher &ow={})
int argc
virtual std::tuple< version_t, uint64_t > bio_put(const Object &object, const bool &force_client=false)=0
virtual std::tuple< version_t, uint64_t > bio_remove(const OID &oid, const bool &force_client=false)=0
static void initialize(int argc, char *argv[], const char *conf_file=nullptr)
Definition: conf.cpp:67
char ** argv
JNIEXPORT void JNICALL Java_com_derecho_objectstore_ObjectStoreService_put(JNIEnv *env, jobject obj, jlong oid, jstring jdata)
void throwJavaException(JNIEnv *env, const char *msg)
JNIEXPORT void JNICALL Java_com_derecho_objectstore_ObjectStoreService_leave(JNIEnv *env, jobject obj)
JNIEXPORT jboolean JNICALL Java_com_derecho_objectstore_ObjectStoreService_remove(JNIEnv *env, jobject obj, jlong oid)
uint64_t OID
Definition: Object.hpp:70
virtual void leave(bool group_shutdown=false)=0
JNIEXPORT jstring JNICALL Java_com_derecho_objectstore_ObjectStoreService_get(JNIEnv *env, jobject obj, jlong oid)
JNIEXPORT void JNICALL Java_com_derecho_objectstore_ObjectStoreService_initialize(JNIEnv *env, jobject obj, jstring jargv)