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

Cleaning code and multithread support #18

Closed
wants to merge 2 commits into from
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
24 changes: 0 additions & 24 deletions include/infinispan/hotrod/Configuration.h

This file was deleted.

20 changes: 16 additions & 4 deletions include/infinispan/hotrod/RemoteCache.h
Expand Up @@ -18,9 +18,6 @@ namespace hotrod {
template <class K, class V> class RemoteCache : private RemoteCacheBase
{
public:
RemoteCache(const RemoteCache &other): RemoteCacheBase(this, other),
keyMarshaller(other.keyMarshaller), valueMarshaller(other.valueMarshaller) {}

V* get(const K& key) {
ScopedBuffer vbuf;
base_get(&key, &vbuf);
Expand Down Expand Up @@ -140,10 +137,25 @@ template <class K, class V> class RemoteCache : private RemoteCacheBase
return *this;
}

RemoteCache(const RemoteCache &other) :
RemoteCacheBase(other), keyMarshaller(other.keyMarshaller), valueMarshaller(other.valueMarshaller)
{
setMarshallers(this, &keyMarshall, &valueMarshall, &keyUnmarshall, &valueUnmarshall);
}

RemoteCache<K,V>& operator=(const RemoteCache& other) {
RemoteCacheBase::operator=(other);
keyMarshaller = other.keyMarshaller;
valueMarshaller = other.valueMarshaller;
setMarshallers(this, &keyMarshall, &valueMarshall, &keyUnmarshall, &valueUnmarshall);
return *this;
}

private:
RemoteCache(const std::string& name) : RemoteCacheBase(name) {
RemoteCache() : RemoteCacheBase() {
setMarshallers(this, &keyMarshall, &valueMarshall, &keyUnmarshall, &valueUnmarshall);
}

// type-hiding and resurrecting support
static void keyMarshall(void *thisp, const void* key, void* buf) {
((RemoteCache<K, V> *) thisp)->keyMarshaller->marshall(*(const K *) key, *(ScopedBuffer *) buf);
Expand Down
11 changes: 5 additions & 6 deletions include/infinispan/hotrod/RemoteCacheBase.h
Expand Up @@ -19,6 +19,8 @@ class OperationsFactory;
}

class RemoteCacheImpl;
class RemoteCacheManagerImpl;

typedef void (*MarshallHelperFn) (void*, const void*, void*);
typedef void* (*UnmarshallHelperFn) (void*, const void*);

Expand All @@ -42,16 +44,13 @@ class HR_EXTERN RemoteCacheBase
void base_clear();
void base_withFlags(Flag flag);

void init(const std::string& name, operations::OperationsFactory* operationFactory);
void init(operations::OperationsFactory* operationFactory);

protected:
RemoteCacheBase(const std::string& name);
RemoteCacheBase(void *newRemoteCachePtr, const RemoteCacheBase &);
protected:
RemoteCacheBase();
void setMarshallers(void* rc, MarshallHelperFn kf, MarshallHelperFn vf, UnmarshallHelperFn ukf, UnmarshallHelperFn uvf);

private:
RemoteCacheBase(const RemoteCacheBase &);

void *remoteCachePtr;
MarshallHelperFn baseKeyMarshallFn;
MarshallHelperFn baseValueMarshallFn;
Expand Down
19 changes: 11 additions & 8 deletions include/infinispan/hotrod/RemoteCacheManager.h
Expand Up @@ -29,24 +29,25 @@ class HR_EXTERN RemoteCacheManager : public Handle<RemoteCacheManagerImpl>
void start();
void stop();
bool isStarted();

// TODO: change to std::map?
const Configuration& getConfiguration();

template <class K, class V> RemoteCache<K, V> getCache(
bool forceReturnValue = false)
{
RemoteCache<K, V> rcache("");
RemoteCache<K, V> rcache;
initCache(rcache, forceReturnValue);
rcache.keyMarshaller.reset(new sys::BasicMarshaller<K>());
rcache.valueMarshaller.reset(new sys::BasicMarshaller<V>());
return rcache;
}
}

template <class K, class V> RemoteCache<K, V> getCache(
const std::string& name, bool forceReturnValue = false)
{
RemoteCache<K, V> rcache(name);
initCache(rcache, forceReturnValue);
RemoteCache<K, V> rcache;
initCache(rcache, name, forceReturnValue);
rcache.keyMarshaller.reset(new sys::BasicMarshaller<K>());
rcache.valueMarshaller.reset(new sys::BasicMarshaller<V>());
return rcache;
Expand All @@ -56,25 +57,27 @@ class HR_EXTERN RemoteCacheManager : public Handle<RemoteCacheManagerImpl>
HR_SHARED_PTR<Marshaller<K> > km, HR_SHARED_PTR<Marshaller<V> > vm,
bool forceReturnValue = false)
{
RemoteCache<K, V> rcache("");
RemoteCache<K, V> rcache;
initCache(rcache, forceReturnValue);
rcache.keyMarshaller = km;
rcache.valueMarshaller = vm;
return rcache; }
return rcache;
}

template <class K, class V> RemoteCache<K, V> getCache(
HR_SHARED_PTR<Marshaller<K> > km, HR_SHARED_PTR<Marshaller<V> > vm,
const std::string& name, bool forceReturnValue = false)
{
RemoteCache<K, V> rcache(name);
initCache(rcache, forceReturnValue);
RemoteCache<K, V> rcache;
initCache(rcache, name, forceReturnValue);
rcache.keyMarshaller = km;
rcache.valueMarshaller = vm;
return rcache;
}

private:
void initCache(RemoteCacheBase& cache, bool forceReturnValue);
void initCache(RemoteCacheBase& cache, const std::string& name, bool forceReturnValue);

// not implemented
RemoteCacheManager(const RemoteCacheManager&);
Expand Down
18 changes: 15 additions & 3 deletions include/infinispan/hotrod/exceptions.h
Expand Up @@ -4,7 +4,6 @@


#include "infinispan/hotrod/ImportExport.h"
#include "hotrod/impl/transport/tcp/InetSocketAddress.h"
#include <exception>
#include <string>

Expand Down Expand Up @@ -33,12 +32,14 @@ struct HR_EXTERN HotRodClientException : public Exception

struct HR_EXTERN TransportException : public HotRodClientException
{
transport::InetSocketAddress serverAddress;
std::string host;
int port;
TransportException(const std::string& host, int port,
const std::string&);
~TransportException() throw();

const transport::InetSocketAddress& getServerAddress() const;
const std::string& getHost() const;
int getPort() const;
};

struct HR_EXTERN InvalidResponseException : public HotRodClientException
Expand All @@ -56,6 +57,17 @@ struct HR_EXTERN InternalException : public HotRodClientException
InternalException(const std::string&);
};

struct HR_EXTERN RemoteCacheManagerNotStartedException : public HotRodClientException
{
RemoteCacheManagerNotStartedException(const std::string&);
};

// not existent in java code
struct HR_EXTERN RemoteCacheNotExistException : public HotRodClientException
{
RemoteCacheNotExistException(const std::string&);
};

}} // namespace

#endif /* ISPN_HOTROD_EXCEPTIONS_H */
13 changes: 0 additions & 13 deletions src/hotrod/api/Configuration.cpp

This file was deleted.

41 changes: 15 additions & 26 deletions src/hotrod/api/RemoteCacheBase.cpp
@@ -1,27 +1,16 @@


#include "infinispan/hotrod/RemoteCacheBase.h"
#include "infinispan/hotrod/RemoteCacheManager.h"
#include "hotrod/impl/RemoteCacheImpl.h"
//#include "hotrod/impl/MetadataValueImpl.h"

#include <iostream>

namespace infinispan {
namespace hotrod {

RemoteCacheBase::RemoteCacheBase(const std::string& name) :
Handle<RemoteCacheImpl>(new RemoteCacheImpl(*this, name)) {}
RemoteCacheBase::RemoteCacheBase() : Handle<RemoteCacheImpl>(NULL) {}

RemoteCacheBase::RemoteCacheBase(void *newRemoteCachePtr, const RemoteCacheBase &other):
Handle<RemoteCacheImpl>(new RemoteCacheImpl(*this, other.impl->getName())),
remoteCachePtr(newRemoteCachePtr),
baseKeyMarshallFn(other.baseKeyMarshallFn),
baseValueMarshallFn(other.baseValueMarshallFn),
baseKeyUnmarshallFn(other.baseKeyUnmarshallFn),
baseValueUnmarshallFn(other.baseValueUnmarshallFn) {
impl->init(*other.impl);
}

void RemoteCacheBase::setMarshallers(void* rc, MarshallHelperFn kf, MarshallHelperFn vf, UnmarshallHelperFn ukf, UnmarshallHelperFn uvf) {
remoteCachePtr = rc;
baseKeyMarshallFn = kf;
Expand All @@ -46,59 +35,59 @@ void* RemoteCacheBase::baseValueUnmarshall(const void* buf) {
return baseValueUnmarshallFn(remoteCachePtr, buf);
}

void RemoteCacheBase::init(const std::string& name, operations::OperationsFactory* operationFactory) {
impl->init(name, operationFactory);
void RemoteCacheBase::init(operations::OperationsFactory* operationFactory) {
impl->init(operationFactory);
}

void RemoteCacheBase::base_get(const void *key, void *buf) {
impl->get(key, buf);
impl->get(*this, key, buf);
}

void RemoteCacheBase::base_put(const void *key, const void *val, int64_t life, int64_t idle, void *buf) {
impl->put(key, val, life, idle, buf);
impl->put(*this, key, val, life, idle, buf);
}

void RemoteCacheBase::base_putIfAbsent(const void *key, const void *val, int64_t life, int64_t idle, void *buf) {
impl->putIfAbsent(key, val, life, idle, buf);
impl->putIfAbsent(*this, key, val, life, idle, buf);
}

void RemoteCacheBase::base_replace(const void *key, const void *val, int64_t life, int64_t idle, void *buf) {
impl->replace(key, val, life, idle, buf);
impl->replace(*this, key, val, life, idle, buf);
}

void RemoteCacheBase::base_remove(const void *key, void *rbuf) {
impl->remove(key, rbuf);
impl->remove(*this, key, rbuf);
}

void RemoteCacheBase::base_containsKey(const void *key, bool *res){
impl->containsKey(key, res);
impl->containsKey(*this, key, res);
}

void RemoteCacheBase::base_replaceWithVersion(const void *key, const void *value, int64_t version, int64_t life, int64_t idle, bool *res)
{
impl->replaceWithVersion(key, value, version, life, idle, res);
impl->replaceWithVersion(*this, key, value, version, life, idle, res);
}

void RemoteCacheBase::base_removeWithVersion(const void *key, int64_t version, bool *res)
{
impl->removeWithVersion(key, version, res);
impl->removeWithVersion(*this, key, version, res);
}

void RemoteCacheBase::base_getWithMetadata(
const void *key, void* vbuf, MetadataValue* metadata)
{
impl->getWithMetadata(key, vbuf, metadata);
impl->getWithMetadata(*this, key, vbuf, metadata);
}

void RemoteCacheBase::base_getBulk(int size, std::map<void*, void*>* mbuf)
{
impl->getBulk(size, mbuf);
impl->getBulk(*this, size, mbuf);
}


void RemoteCacheBase::base_keySet(int scope, std::set<void*>* result)
{
impl->keySet(scope, result);
impl->keySet(*this, scope, result);
}

void RemoteCacheBase::base_stats(std::map<std::string,std::string>* stats)
Expand Down
17 changes: 14 additions & 3 deletions src/hotrod/api/RemoteCacheManager.cpp
Expand Up @@ -20,11 +20,22 @@ RemoteCacheManager::RemoteCacheManager(bool start_)


RemoteCacheManager::RemoteCacheManager(const std::map<std::string,std::string>& properties, bool start_)
: Handle<RemoteCacheManagerImpl>(new RemoteCacheManagerImpl(properties,start_)) { }
: Handle<RemoteCacheManagerImpl>(new RemoteCacheManagerImpl(properties, start_)) { }

void RemoteCacheManager::initCache(
RemoteCacheBase& cache, bool forceReturnValue) {
impl->initCache(*cache.impl, forceReturnValue);
RemoteCacheBase& cache, bool forceReturnValue)
{
cache.impl = impl->createRemoteCache(forceReturnValue);
if(!impl)
throw RemoteCacheNotExistException("cache doesn't exist");
}

void RemoteCacheManager::initCache(
RemoteCacheBase& cache, const std::string& name, bool forceReturnValue)
{
cache.impl = impl->createRemoteCache(name, forceReturnValue);
if(!impl)
throw RemoteCacheNotExistException("cache doesn't exist");
}

void RemoteCacheManager::start() {
Expand Down
14 changes: 11 additions & 3 deletions src/hotrod/api/exceptions.cpp
Expand Up @@ -11,12 +11,16 @@ const char* Exception::what() const throw() { return message.c_str(); }

HotRodClientException::HotRodClientException(const std::string& msg) : Exception(msg) {}

TransportException::TransportException(const std::string& host, int port, const std::string& msg)
: HotRodClientException(msg), serverAddress(host, port) {}
TransportException::TransportException(const std::string& h, int p, const std::string& msg)
: HotRodClientException(msg), host(h), port(p) {}

TransportException::~TransportException() throw() {}

const transport::InetSocketAddress& TransportException::getServerAddress() const { return serverAddress;}
const std::string& TransportException::getHost() const { return host;}
int TransportException::getPort() const { return port;}


//const transport::InetSocketAddress& TransportException::getServerAddress() const { return serverAddress;}


InvalidResponseException::InvalidResponseException(const std::string& msg) : HotRodClientException(msg) {}
Expand All @@ -25,4 +29,8 @@ RemoteNodeSuspectException::RemoteNodeSuspectException(const std::string& msg) :

InternalException::InternalException(const std::string& msg) : HotRodClientException(msg) {}

RemoteCacheManagerNotStartedException::RemoteCacheManagerNotStartedException(const std::string& msg) : HotRodClientException(msg) {}

RemoteCacheNotExistException::RemoteCacheNotExistException(const std::string& msg) : HotRodClientException(msg) {}

}} /* namespace */