00001 /* Copyright (C) 2010 webis.de 00002 * All rights reserved. 00003 */ 00004 #ifndef AITOOLS_INVERTEDINDEX_JNI_GATEWAY_HPP 00005 #define AITOOLS_INVERTEDINDEX_JNI_GATEWAY_HPP 00006 00007 #include "Builder.hpp" 00008 #include "Searcher.hpp" 00009 #include <boost/thread/mutex.hpp> 00010 #include <tr1/unordered_map> 00011 #include <jni.h> 00012 00013 namespace aitools { 00014 namespace invertedindex { 00015 00023 class JNIGateway { 00024 00025 private: // nested types 00026 00027 typedef std::tr1::unordered_map<jint, Builder::shared_pointer> BuilderMap; 00028 typedef std::tr1::unordered_map<jint, Searcher::SharedPointer> SearcherMap; 00029 typedef std::tr1::unordered_map<jint, Iterator::SharedPointer> IteratorMap; 00030 00031 private: // disallow instantiation and copying 00032 00033 JNIGateway(); 00034 00035 JNIGateway(const JNIGateway& gateway); 00036 00037 JNIGateway& operator=(const JNIGateway& gateway); 00038 00039 private: // class member 00040 00041 static BuilderMap builders; 00042 static SearcherMap searchers; 00043 static IteratorMap iterators; 00044 static boost::mutex mutex; 00045 00046 public: // class member 00047 00048 static const char* java_exception; 00049 00050 public: // class methods 00051 00052 static void copy_string(JNIEnv* env, jstring jstr, std::string& cstr); 00053 00054 static Builder::shared_pointer create_builder(JNIEnv* env, jstring jclazz) 00055 throw (std::invalid_argument); 00056 00057 static Searcher::SharedPointer create_searcher(JNIEnv* env, jstring jclazz) 00058 throw (std::invalid_argument); 00059 00060 static void delete_builder(jint oid); 00061 00062 static void delete_searcher(jint oid); 00063 00064 static void delete_iterator(jint oid); 00065 00066 static Builder::shared_pointer& get_builder(jint oid) 00067 throw (std::invalid_argument); 00068 00069 static Searcher::SharedPointer& get_searcher(jint oid) 00070 throw (std::invalid_argument); 00071 00072 static Iterator::SharedPointer& get_iterator(jint oid) 00073 throw (std::invalid_argument); 00074 00075 static jint put_builder(const Builder::shared_pointer& builder); 00076 00077 static jint put_searcher(const Searcher::SharedPointer& searcher); 00078 00079 static jint put_iterator(const Iterator::SharedPointer& iterator); 00080 00081 }; 00082 00083 } // namespace invertedindex 00084 } // namespace aitools 00085 00086 #endif // AITOOLS_INVERTEDINDEX_JNI_GATEWAY_HPP