Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HRCPP-41 & HRCPP-84 Add missing RemoteCacheManager and RemoteCache methods #75

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 8 additions & 11 deletions CMakeLists.txt
Expand Up @@ -2,16 +2,10 @@ cmake_minimum_required (VERSION 2.6)

project (infinispan-hotrod-c++ C CXX)



#file(READ version.txt HR_VERSION_FILE)
#string(REGEX MATCHALL "[0-9]+" HR_VERSION_LIST "${HR_VERSION_FILE}")

#list(GET HR_VERSION_LIST 0 HR_VERSION_MAJOR)
#list(GET HR_VERSION_LIST 1 HR_VERSION_MINOR)

#set (HR_VERSION "${HR_VERSION_MAJOR}.${HR_VERSION_MINOR}")
#message(STATUS "HR_VERSION: ${HR_VERSION}")
set (CPACK_PACKAGE_VERSION_MAJOR "6")
set (CPACK_PACKAGE_VERSION_MINOR "0")
set (CPACK_PACKAGE_VERSION_PATCH "0-SNAPSHOT")
set (HOTROD_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/src")

Expand Down Expand Up @@ -102,6 +96,8 @@ else(HOTROD_WINAPI)
src/hotrod/sys/posix/platform.cpp src/hotrod/sys/posix/Mutex.cpp)
endif(HOTROD_WINAPI)

configure_file(src/hotrod/impl/Version.cpp.in ${CMAKE_BINARY_DIR}/Version.cpp @ONLY)

set (library_sources
src/hotrod/api/RemoteCacheManager.cpp
src/hotrod/api/RemoteCacheBase.cpp
Expand Down Expand Up @@ -155,6 +151,7 @@ set (library_sources
src/hotrod/impl/transport/tcp/RoundRobinBalancingStrategy.cpp
src/hotrod/sys/Runnable.cpp
${platform_sources}
${CMAKE_BINARY_DIR}/Version.cpp
)

add_library (
Expand Down Expand Up @@ -267,7 +264,6 @@ else (WIN32)
endif(WIN32)
message (STATUS "Building for ${PLATFORM} on ${PACKAGE_ARCH}")
set (CPACK_SYSTEM_NAME "${PLATFORM}-${PACKAGE_ARCH}")

set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")

Expand All @@ -277,3 +273,4 @@ install (FILES "${CMAKE_CURRENT_SOURCE_DIR}/License.txt" "${CMAKE_CURRENT_SOURCE
install (TARGETS hotrod hotrod-static DESTINATION lib)

include (CPack)

11 changes: 6 additions & 5 deletions include/infinispan/hotrod/RemoteCache.h
Expand Up @@ -9,6 +9,7 @@
#include "infinispan/hotrod/MetadataValue.h"
#include "infinispan/hotrod/TimeUnit.h"
#include "infinispan/hotrod/VersionedValue.h"
#include "infinispan/hotrod/Version.h"

#include <cmath>
#include <set>
Expand All @@ -24,15 +25,15 @@ template <class K, class V> class RemoteCache : private RemoteCacheBase
{
public:
std::string getName() {
throw UnsupportedOperationException();
return base_getName();
}

std::string getVersion() {
throw UnsupportedOperationException();
return Version::getVersion();
}

std::string getProtocolVersion() {
throw UnsupportedOperationException();
return Version::getProtocolVersion();
}

V* get(const K& key) {
Expand Down Expand Up @@ -190,7 +191,7 @@ template <class K, class V> class RemoteCache : private RemoteCacheBase
}

std::map<HR_SHARED_PTR<K>, HR_SHARED_PTR<V> > getBulk() {
throw UnsupportedOperationException();
return getBulk(0);
}

std::map<HR_SHARED_PTR<K>, HR_SHARED_PTR<V> > getBulk(int nrOfEntries) {
Expand All @@ -206,7 +207,7 @@ template <class K, class V> class RemoteCache : private RemoteCacheBase
}

std::set<std::pair<K, V> > entrySet() {
throw UnsupportedOperationException();
throw UnsupportedOperationException();
}

std::set<HR_SHARED_PTR<K> > keySet() {
Expand Down
1 change: 1 addition & 0 deletions include/infinispan/hotrod/RemoteCacheBase.h
Expand Up @@ -28,6 +28,7 @@ class HR_EXTERN RemoteCacheBase
: public infinispan::hotrod::Handle<RemoteCacheImpl>
{
public:
const std::string& base_getName();
void base_get(const void *key, void *rbuf);
void base_put(const void *key, const void *value, int64_t life, int64_t idle, void *buf);
void base_putIfAbsent(const void *key, const void *value, int64_t life, int64_t idle, void *buf);
Expand Down
22 changes: 22 additions & 0 deletions include/infinispan/hotrod/Version.h
@@ -0,0 +1,22 @@
#ifndef ISPN_HOTROD_VERSION_H
#define ISPN_HOTROD_VERSION_H

#include "infinispan/hotrod/ImportExport.h"
#include <string>

namespace infinispan {
namespace hotrod {

class Version {
private:
HR_EXTERN static const std::string PROTOCOL_VERSION;
HR_EXTERN static const std::string VERSION;

public:
static const std::string& getProtocolVersion() { return PROTOCOL_VERSION; }
static const std::string& getVersion() { return VERSION; }
};

}}

#endif // ISPN_HOTROD_VERSIONEDVALUE_H
4 changes: 4 additions & 0 deletions src/hotrod/api/RemoteCacheBase.cpp
Expand Up @@ -39,6 +39,10 @@ void RemoteCacheBase::init(operations::OperationsFactory* operationFactory) {
impl->init(operationFactory);
}

const std::string& RemoteCacheBase::base_getName() {
return impl->getName();
}

void RemoteCacheBase::base_get(const void *key, void *buf) {
impl->get(*this, key, buf);
}
Expand Down
4 changes: 4 additions & 0 deletions src/hotrod/impl/RemoteCacheImpl.cpp
Expand Up @@ -175,6 +175,10 @@ void RemoteCacheImpl::getWithMetadata(RemoteCacheBase& remoteCacheBase, const vo
metadata->maxIdle = m.maxIdle;
}

void RemoteCacheImpl::getBulk(RemoteCacheBase& remoteCacheBase, std::map<void*, void*>* mbuf) {
getBulk(remoteCacheBase, 0, mbuf);
}

void RemoteCacheImpl::getBulk(RemoteCacheBase& remoteCacheBase, int size, std::map<void*, void*>* mbuf) {
assertRemoteCacheManagerIsStarted();
hr_scoped_ptr<BulkGetOperation> gco(operationsFactory->newBulkGetOperation(size));
Expand Down
1 change: 1 addition & 0 deletions src/hotrod/impl/RemoteCacheImpl.h
Expand Up @@ -33,6 +33,7 @@ class RemoteCacheImpl
void removeWithVersion(RemoteCacheBase& rcb, const void* k, uint64_t version, bool* res);
void getWithMetadata(RemoteCacheBase& rcb, const void *key, void* vbuf, MetadataValue* metadata);
void getWithVersion(RemoteCacheBase& rcb, const void *key, void* vbuf, VersionedValue* version);
void getBulk(RemoteCacheBase& rcb, std::map<void*, void*>* mbuf);
void getBulk(RemoteCacheBase& rcb, int size, std::map<void*, void*>* mbuf);
void keySet(RemoteCacheBase& rcb, int scope, std::set<void*>* result);
void stats(std::map<std::string,std::string>* stats);
Expand Down
9 changes: 9 additions & 0 deletions src/hotrod/impl/Version.cpp.in
@@ -0,0 +1,9 @@
#include "infinispan/hotrod/Version.h"

namespace infinispan {
namespace hotrod {

const std::string Version::PROTOCOL_VERSION = "HotRod C++ client, protocol version :1.2";
const std::string Version::VERSION = "@HOTROD_VERSION@";

}}
4 changes: 4 additions & 0 deletions test/JniTest.java
Expand Up @@ -151,6 +151,10 @@ public static void main(String[] args) {
bulkGetSimpleTest = new BulkGetSimpleTest();
invokeMethod(bulkGetSimpleTest, "createCacheManagers");

System.out.println("=== Bulk Get Simple test - test Get Bulk ====");
bulkGetSimpleTest.testBulkGet();
System.out.println("=== Bulk Get Simple test - test Get Bulk PASSED ====");

System.out.println("=== Bulk Get Simple test - test Get Bulk With Size ====");
bulkGetSimpleTest.testBulkGetWithSize();
System.out.println("=== Bulk Get Simple test - test Get Bulk With Size PASSED ====");
Expand Down
6 changes: 5 additions & 1 deletion test/Simple.cpp
Expand Up @@ -2,6 +2,7 @@
#include "infinispan/hotrod/RemoteCacheManager.h"
#include "infinispan/hotrod/RemoteCache.h"
#include "infinispan/hotrod/ScopedBuffer.h"
#include "infinispan/hotrod/Version.h"

#include <stdlib.h>
#include <iostream>
Expand All @@ -19,6 +20,9 @@ int main(int argc, char** argv) {
RemoteCache<std::string, std::string> cache = cacheManager.getCache<std::string, std::string>();
cacheManager.start();

std::cout << "HotRod C++ Library version " << cache.getVersion() << std::endl;
std::cout << "Protocol " << cache.getProtocolVersion() << std::endl;

std::string k1("key13");
std::string k2("key14");
std::string v1("boron");
Expand Down Expand Up @@ -181,7 +185,7 @@ int main(int argc, char** argv) {
std::cout << "PASS: simple keySet" << std::endl;

// getBulk
std::map<HR_SHARED_PTR<std::string>,HR_SHARED_PTR<std::string> > map = cache.getBulk(0);
std::map<HR_SHARED_PTR<std::string>,HR_SHARED_PTR<std::string> > map = cache.getBulk();
if (map.size()!=1) {
std::cerr << "getBulk fail got" << map.size() << " entries expected 1" << std::endl;
return 1;
Expand Down
2 changes: 2 additions & 0 deletions test/jniapi/org/infinispan/client/hotrod/RemoteCache.java
Expand Up @@ -55,6 +55,8 @@ public interface RemoteCache<K, V> {

MetadataValue<V> getWithMetadata(K key);

Map<K, V> getBulk();

Map<K, V> getBulk(int size);

boolean isEmpty();
Expand Down
31 changes: 31 additions & 0 deletions test/jniapi/org/infinispan/client/hotrod/impl/RemoteCacheImpl.java
Expand Up @@ -331,6 +331,37 @@ public Object invoke(RelayBytes... rbs) {
return result;
}

@Override
public Map<K, V> getBulk() {
if (jniRemoteCache == null) {
return null;
}

final MapReturn mapReturn = jniRemoteCache.getBulk();
final VectorReturn vectorReturn = Hotrod.keySet(mapReturn);

Map<K, V> result = new HashMap<K, V>();
for (int i = 0; i < vectorReturn.size(); i++) {
final int index = i;
K key = relayedInvoker(new RelayedMethod() {
@Override
public Object invoke(RelayBytes... rbs) {
return Hotrod.dereference(vectorReturn.get(index));
}
});
V value = relayedInvoker(new RelayedMethod() {
@Override
public Object invoke(RelayBytes... rbs) {
return Hotrod.dereference(mapReturn.get(vectorReturn.get(index)));
}
});

result.put(key, value);
}

return result;
}

@Override
public Map<K, V> getBulk(int size) {
if (jniRemoteCache == null) {
Expand Down