Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,17 @@ set_target_properties(events PROPERTIES COMPILE_DEFINITIONS "${DLLEXPORT_STATIC}
set_target_properties (events PROPERTIES COMPILE_FLAGS "${COMPILER_FLAGS} ${WARNING_FLAGS_NO_PEDANTIC} ${NO_UNUSED_FLAGS}")
target_link_libraries (events hotrod hotrod_protobuf ${PROTOBUF_LIBRARY} ${platform_libs})

add_executable (nearCacheTest test/NearCacheTest.cpp)
target_include_directories(nearCacheTest PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/test/query_proto"
"${INCLUDE_FILES_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
"${PROTOBUF_INCLUDE_DIR}")
set_property(TARGET nearCacheTest PROPERTY CXX_STANDARD 11)
set_property(TARGET nearCacheTest PROPERTY CXX_STANDARD_REQUIRED ON)
set_target_properties(nearCacheTest PROPERTIES COMPILE_DEFINITIONS "${DLLEXPORT_STATIC}")
set_target_properties (nearCacheTest PROPERTIES COMPILE_FLAGS "${COMPILER_FLAGS} ${WARNING_FLAGS_NO_PEDANTIC} ${NO_UNUSED_FLAGS}")
target_link_libraries (nearCacheTest hotrod hotrod_protobuf ${PROTOBUF_LIBRARY} ${platform_libs})

add_executable (simple-tls test/SimpleTLS.cpp)
target_include_directories(simple-tls PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/test/query_proto"
"${INCLUDE_FILES_DIR}"
Expand Down Expand Up @@ -650,6 +661,7 @@ else (NOT ((EXISTS "${HOTROD_JBOSS_HOME}/bin/standalone.sh") AND (EXISTS "${HOTR
add_test (queryTest queryTest)
add_test (queryTest-static queryTest-static)
add_test (events events)
add_test (nearCacheTest nearCacheTest)
add_test (stop_server ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bin/server_ctl.py stop)
add_test (start_ssl_server ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bin/server_ctl.py start ${JAVA_RUNTIME} ${HOTROD_JBOSS_HOME} standalone-hotrod-ssl.xml)
add_test (probe_ssl_port ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bin/probe_port.py localhost 11222 60)
Expand Down
13 changes: 9 additions & 4 deletions include/infinispan/hotrod/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include <vector>
#include "infinispan/hotrod/portable.h"
#include "infinispan/hotrod/ImportExport.h"
#include "ConnectionPoolConfiguration.h"
#include "ServerConfiguration.h"
#include "SslConfiguration.h"
#include "infinispan/hotrod/ConnectionPoolConfiguration.h"
#include "infinispan/hotrod/ServerConfiguration.h"
#include "infinispan/hotrod/SslConfiguration.h"
#include "infinispan/hotrod/NearCacheConfiguration.h"
#include "infinispan/hotrod/FailOverRequestBalancingStrategy.h"
#include "infinispan/hotrod/JBasicEventMarshaller.h"

Expand Down Expand Up @@ -49,14 +50,15 @@ class Configuration
bool _tcpNoDelay,
int _valueSizeEstimate,
int _maxRetries,
NearCacheConfiguration _nearCacheConfiguration,
FailOverRequestBalancingStrategy::ProducerFn bsp=0,
const event::EventMarshaller &eventMarshaller = event::JBasicEventMarshaller()):
protocolVersion(_protocolVersion), protocolVersionPtr(),
connectionPoolConfiguration(_connectionPoolConfiguration),
connectionTimeout(_connectionTimeout), forceReturnValue(_forceReturnValue),
keySizeEstimate(_keySizeEstimate),
socketTimeout(_socketTimeout), sslConfiguration(_sslConfiguration),tcpNoDelay(_tcpNoDelay),
valueSizeEstimate(_valueSizeEstimate), maxRetries(_maxRetries), balancingStrategyProducer(bsp),
valueSizeEstimate(_valueSizeEstimate), maxRetries(_maxRetries), nearCacheConfiguration(_nearCacheConfiguration), balancingStrategyProducer(bsp),
eventMarshaller(eventMarshaller)
{
std::map<portable::string, portable::vector<ServerConfiguration>> tmpMap;
Expand Down Expand Up @@ -173,6 +175,8 @@ class Configuration
SslConfiguration& getSslConfiguration() { return sslConfiguration; }
HR_EXTERN const event::EventMarshaller &getEventMarshaller() const;

const NearCacheConfiguration& getNearCacheConfiguration() const { return nearCacheConfiguration; }

private:
portable::string protocolVersion;
portable::local_ptr<std::string> protocolVersionPtr;
Expand All @@ -186,6 +190,7 @@ class Configuration
bool tcpNoDelay;
int valueSizeEstimate;
int maxRetries;
const NearCacheConfiguration nearCacheConfiguration;
FailOverRequestBalancingStrategy::ProducerFn balancingStrategyProducer;
const event::EventMarshaller &eventMarshaller;

Expand Down
53 changes: 52 additions & 1 deletion include/infinispan/hotrod/ConfigurationBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
#include "ConnectionPoolConfigurationBuilder.h"
#include "ServerConfigurationBuilder.h"
#include "SslConfigurationBuilder.h"
#include "NearCacheConfiguration.h"

using namespace infinispan::hotrod::event;

namespace infinispan {
namespace hotrod {

class ClusterConfigurationBuilder
{
public:
Expand All @@ -32,6 +34,43 @@ class ClusterConfigurationBuilder
std::vector<ServerConfigurationBuilder>& servers;
ConfigurationBuilder &m_parent;
};

/**
* Configuration classes for near cache
*/
class NearCacheConfigurationBuilder : public ConfigurationChildBuilder
{
public:
NearCacheConfigurationBuilder(ConfigurationBuilder& _builder) : ConfigurationChildBuilder(_builder) {}

int getMaxEntries() const {
return m_maxEntries;
}

NearCacheConfigurationBuilder& maxEntries(int maxEntries = 0) {
this->m_maxEntries = maxEntries;
return *this;
}

NearCacheMode getMode() const {
return m_mode;
}

NearCacheConfigurationBuilder& mode(NearCacheMode mode = DISABLED) {
this->m_mode = mode;
return *this;
}

NearCacheConfiguration create()
{
return NearCacheConfiguration(m_mode,m_maxEntries);
}

private:
NearCacheMode m_mode=DISABLED;
int m_maxEntries=0;
};

/**
* ConfigurationBuilder used to generate immutable Configuration objects that are in turn
* used to configure RemoteCacheManager instances.
Expand All @@ -54,7 +93,8 @@ class ConfigurationBuilder
__pragma(warning(suppress:4355)) // passing uninitialized 'this'
connectionPoolConfigurationBuilder(*this),
__pragma(warning(suppress:4355))
sslConfigurationBuilder(*this)
sslConfigurationBuilder(*this),
nearCacheConfigurationBuilder(*this)
{}

void validate() {}
Expand Down Expand Up @@ -178,6 +218,15 @@ class ConfigurationBuilder
return sslConfigurationBuilder;
}

/**
* Returns NearCacheConfigurationBuilder for near cache enabling and configuration.
*
*\return NearCacheConfigurationBuilder instance to be used for configuration
*/
NearCacheConfigurationBuilder& nearCache() {
return nearCacheConfigurationBuilder;
}

/**
* Set tcpNoDelay for this ConfigurationBuilder. Default is true.
*
Expand Down Expand Up @@ -259,6 +308,7 @@ class ConfigurationBuilder
m_tcpNoDelay,
m_valueSizeEstimate,
m_maxRetries,
nearCacheConfigurationBuilder.create(),
m_balancingStrategyProducer,
m_eventMarshaller);

Expand Down Expand Up @@ -298,6 +348,7 @@ class ConfigurationBuilder
ConnectionPoolConfigurationBuilder connectionPoolConfigurationBuilder;
SslConfigurationBuilder sslConfigurationBuilder;
JBasicEventMarshaller m_defaultEventMarshaller;
NearCacheConfigurationBuilder nearCacheConfigurationBuilder;

EventMarshaller &m_eventMarshaller=m_defaultEventMarshaller;
};
Expand Down
47 changes: 47 additions & 0 deletions include/infinispan/hotrod/NearCacheConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* NearCacheConfiguration.h
*
* Created on: Nov 29, 2016
* Author: rigazilla
*/

#ifndef INCLUDE_INFINISPAN_HOTROD_NEARCACHECONFIGURATION_H_
#define INCLUDE_INFINISPAN_HOTROD_NEARCACHECONFIGURATION_H_


#include "infinispan/hotrod/ImportExport.h"

namespace infinispan {
namespace hotrod {

enum NearCacheMode { DISABLED=0, INVALIDATED=1 };

class HR_EXTERN NearCacheConfiguration
{
public:
NearCacheConfiguration(NearCacheMode mode=DISABLED, int maxEntries=0) : m_mode(mode), m_maxEntries(maxEntries) {}

int getMaxEntries() const {
return m_maxEntries;
}

void maxEntries(int maxEntries = 0) {
this->m_maxEntries = maxEntries;
}

NearCacheMode getMode() const {
return m_mode;
}

void mode(NearCacheMode mode = DISABLED) {
this->m_mode = mode;
}
private:
NearCacheMode m_mode=DISABLED;
int m_maxEntries=0;
};
}
}


#endif /* INCLUDE_INFINISPAN_HOTROD_NEARCACHECONFIGURATION_H_ */
4 changes: 2 additions & 2 deletions include/infinispan/hotrod/RemoteCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

namespace infinispan {
namespace hotrod {

/**
* Provides remote reference to a cache residing on a Hot Rod server/cluster.
*
Expand Down Expand Up @@ -909,11 +908,12 @@ template <class K, class V> class RemoteCache : private RemoteCacheBase
return *this;
}

private:
protected:
RemoteCache() : RemoteCacheBase() {
setMarshallers(this, &keyMarshall, &valueMarshall, &keyUnmarshall, &valueUnmarshall);
}

private:
uint64_t toSeconds(uint64_t time, TimeUnit unit) {
uint64_t result;
switch (unit) {
Expand Down
1 change: 1 addition & 0 deletions include/infinispan/hotrod/RemoteCacheBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class RemoteCacheBase

friend class RemoteCacheManager;
friend class RemoteCacheImpl;
friend class NearRemoteCacheImpl;
friend class KeyUnmarshallerFtor;
friend class ValueUnmarshallerFtor;
template <class K, class V>
Expand Down
17 changes: 9 additions & 8 deletions include/infinispan/hotrod/RemoteCacheManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ class HR_EXTERN RemoteCacheManager
const std::string key = forceReturnValue ? "/true" : "/false";
if (remoteCacheMap.find(key)==remoteCacheMap.end())
{
RemoteCache<K,V> *pRc= new RemoteCache<K,V>();
RemoteCache<K,V> *pRc;
pRc= new RemoteCache<K,V>();
remoteCacheMap[key]= std::unique_ptr<RemoteCacheBase>(pRc);
RemoteCache<K, V> *rcache=(RemoteCache<K, V> *)remoteCacheMap[key].get();
initCache(*rcache, forceReturnValue);
initCache(*rcache, forceReturnValue, getConfiguration().getNearCacheConfiguration());
rcache->keyMarshaller.reset(new BasicMarshaller<K>(), &Marshaller<K>::destroy);
rcache->valueMarshaller.reset(new BasicMarshaller<V>(), &Marshaller<V>::destroy);
return *rcache;
Expand Down Expand Up @@ -191,14 +192,14 @@ class HR_EXTERN RemoteCacheManager
remoteCacheMap[key] = std::unique_ptr < RemoteCacheBase > (pRc);
RemoteCache<K, V> *rcache =
(RemoteCache<K, V> *) remoteCacheMap[key].get();
initCache(*rcache, forceReturnValue);
initCache(*rcache, forceReturnValue, getConfiguration().getNearCacheConfiguration());
rcache->keyMarshaller.reset(km, kd);
rcache->valueMarshaller.reset(vm, vd);
return *rcache;
}
RemoteCache<K, V> *rcache =
(RemoteCache<K, V> *) remoteCacheMap[key].get();
initCache(*rcache, forceReturnValue);
initCache(*rcache, forceReturnValue, getConfiguration().getNearCacheConfiguration());
rcache->keyMarshaller.reset(km, kd);
rcache->valueMarshaller.reset(vm, vd);
return *rcache;
Expand Down Expand Up @@ -243,14 +244,14 @@ class HR_EXTERN RemoteCacheManager
remoteCacheMap[key] = std::unique_ptr < RemoteCacheBase > (pRc);
RemoteCache<K, V> *rcache =
(RemoteCache<K, V> *) remoteCacheMap[key].get();
initCache(*rcache, name.c_str(), forceReturnValue);
initCache(*rcache, name.c_str(), forceReturnValue, getConfiguration().getNearCacheConfiguration());
rcache->keyMarshaller.reset(km, kd);
rcache->valueMarshaller.reset(vm, vd);
return *rcache;
}
RemoteCache<K, V> *rcache =
(RemoteCache<K, V> *) remoteCacheMap[key].get();
initCache(*rcache, name.c_str(), forceReturnValue);
initCache(*rcache, name.c_str(), forceReturnValue, getConfiguration().getNearCacheConfiguration());
rcache->keyMarshaller.reset(km, kd);
rcache->valueMarshaller.reset(vm, vd);
return *rcache;
Expand Down Expand Up @@ -295,8 +296,8 @@ class HR_EXTERN RemoteCacheManager

void init(const portable::map<portable::string, portable::string>& configuration, bool start);

void initCache(RemoteCacheBase& cache, bool forceReturnValue);
void initCache(RemoteCacheBase& cache, const char *name, bool forceReturnValue);
void initCache(RemoteCacheBase& cache, bool forceReturnValue, NearCacheConfiguration nc = NearCacheConfiguration());
void initCache(RemoteCacheBase& cache, const char *name, bool forceReturnValue, NearCacheConfiguration nc = NearCacheConfiguration());

// not implemented
RemoteCacheManager(const RemoteCacheManager&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.infinispan.client.hotrod.impl.transport.tcp.RequestBalancingStrategy;
import org.infinispan.client.hotrod.configuration.ConnectionPoolConfiguration;
import org.infinispan.client.hotrod.configuration.SslConfiguration;
import org.infinispan.client.hotrod.configuration.NearCacheConfiguration;
import org.infinispan.commons.configuration.BuiltBy;
import org.infinispan.commons.marshall.Marshaller;

Expand Down Expand Up @@ -51,10 +52,10 @@ public Configuration(org.infinispan.client.hotrod.jni.Configuration jniConfigura
Configuration(ExecutorFactoryConfiguration asyncExecutorFactory, Class<? extends RequestBalancingStrategy> balancingStrategy, ClassLoader classLoader,
ConnectionPoolConfiguration connectionPool, int connectionTimeout, Class<? extends ConsistentHash>[] consistentHashImpl, boolean forceReturnValues, int keySizeEstimate, Class<? extends Marshaller> marshallerClass,
boolean pingOnStartup, String protocolVersion, List<ServerConfiguration> servers, List<ServerConfiguration> failOverServers, int socketTimeout, SslConfiguration ssl, boolean tcpNoDelay,
Class<? extends TransportFactory> transportFactory, int valueSizeEstimate, int maxRetries) {
Class<? extends TransportFactory> transportFactory, int valueSizeEstimate, int maxRetries, NearCacheConfiguration nearCache) {
this.jniConfiguration = new org.infinispan.client.hotrod.jni.Configuration(protocolVersion, connectionPool.getJniConnectionPoolConfiguration(),
connectionTimeout, forceReturnValues, keySizeEstimate, null, socketTimeout, ssl.getJniSslConfiguration(), tcpNoDelay,
valueSizeEstimate, maxRetries);
valueSizeEstimate, maxRetries, nearCache.getJniNearCacheConfiguration());
this.asyncExecutorFactory = asyncExecutorFactory;
this.balancingStrategy = balancingStrategy;
this.classLoader = new WeakReference<ClassLoader>(classLoader);
Expand Down Expand Up @@ -134,6 +135,10 @@ public SslConfiguration ssl() {
return new SslConfiguration(this.jniConfiguration.getSslConfiguration());
}

public NearCacheConfiguration nearCache() {
return new NearCacheConfiguration(this.jniConfiguration.getNearCacheConfiguration());
}

public boolean tcpNoDelay() {
return this.jniConfiguration.isTcpNoDelay();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.infinispan.client.hotrod.configuration;


/**
* NearCacheConfiguration.
*
* @author Vittorio Rigamonti
*/

import org.infinispan.client.hotrod.jni.NearCacheMode;

public class NearCacheConfiguration {
private final NearCacheMode mode;
private final int maxEntries;
private org.infinispan.client.hotrod.jni.NearCacheConfiguration jniNearCacheConfiguration;

public org.infinispan.client.hotrod.jni.NearCacheConfiguration getJniNearCacheConfiguration() {
return jniNearCacheConfiguration;
}

public NearCacheConfiguration(org.infinispan.client.hotrod.jni.NearCacheConfiguration jniNearCacheConfiguration) {
super();
this.jniNearCacheConfiguration = jniNearCacheConfiguration;
mode=NearCacheMode.DISABLED;
maxEntries=0;
}

NearCacheConfiguration(NearCacheMode mode, int maxEntries) {
this.mode=mode;
this.maxEntries=maxEntries;
this.jniNearCacheConfiguration = new org.infinispan.client.hotrod.jni.NearCacheConfiguration(NearCacheMode.DISABLED, 0);
}

NearCacheMode getMode()
{
return mode;
}

int getMaxEntries()
{
return maxEntries;
}

@Override
public String toString() {
return "NearCacheConfiguration [mode=" + (mode==NearCacheMode.INVALIDATED ? "INVALIDATED" : "DISABLED") + ", maxEntries=" + maxEntries+"]";
}
}
Loading