Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/hotrod/impl/CustomClientListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,39 @@ class CustomClientListener : public ClientListener



virtual void processEvent(ClientCacheEntryCreatedEvent<std::vector<char>> marshEv, std::vector<char >listId, uint8_t isCustom) const
virtual void processEvent(ClientCacheEntryCreatedEvent<std::vector<char>> marshEv, std::vector<char >/*listId*/, uint8_t /*isCustom*/) const
{
for (auto callable: createdCallbacks)
{
callable(marshEv);
}
}

virtual void processEvent(ClientCacheEntryModifiedEvent<std::vector<char>> marshEv, std::vector<char >listId, uint8_t isCustom) const
virtual void processEvent(ClientCacheEntryModifiedEvent<std::vector<char>> marshEv, std::vector<char >/*listId*/, uint8_t /*isCustom*/) const
{
for (auto callable: modifiedCallbacks)
{
callable(marshEv);
}
}

virtual void processEvent(ClientCacheEntryRemovedEvent<std::vector<char>> marshEv, std::vector<char >listId, uint8_t isCustom) const
virtual void processEvent(ClientCacheEntryRemovedEvent<std::vector<char>> marshEv, std::vector<char >/*listId*/, uint8_t /*isCustom*/) const
{
for (auto callable: removedCallbacks)
{
callable(marshEv);
}
}

virtual void processEvent(ClientCacheEntryExpiredEvent<std::vector<char>> marshEv, std::vector<char >listId, uint8_t isCustom) const
virtual void processEvent(ClientCacheEntryExpiredEvent<std::vector<char>> marshEv, std::vector<char >/*listId*/, uint8_t /*isCustom*/) const
{
for (auto callable: expiredCallbacks)
{
callable(marshEv);
}
}

virtual void processEvent(ClientCacheEntryCustomEvent ev, std::vector<char >listId, uint8_t isCustom) const
virtual void processEvent(ClientCacheEntryCustomEvent ev, std::vector<char >/*listId*/, uint8_t /*isCustom*/) const
{
for (auto callable: customCallbacks)
{
Expand Down
60 changes: 13 additions & 47 deletions src/hotrod/impl/NearRemoteCacheImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class NearRemoteCacheImpl: public RemoteCacheImpl {
_nearMap[key] = value;
}

void removeElementFromMap(std::vector<char>& key) {
void removeElementFromMap(const std::vector<char>& key) {
std::lock_guard<std::mutex> guard(_nearMutex);
auto it = std::find(_nearFifo.begin(), _nearFifo.end(), key);
if (it != _nearFifo.end()) {
Expand All @@ -150,59 +150,25 @@ class NearRemoteCacheImpl: public RemoteCacheImpl {
_nearMap.clear();
}
void startListener() {
std::string convStr("___eager-key-value-version-converter");
cl.converterFactoryName = std::vector<char>(convStr.begin(),
convStr.end());
cl.useRawData = true;
std::function<void(ClientCacheEntryCustomEvent ce)> f =
[this] (ClientCacheEntryCustomEvent ce) {listener(this->_nearMap, ce);};
std::function<void(ClientCacheEntryCreatedEvent<std::vector<char>> ev)> created =
[this] (ClientCacheEntryCreatedEvent<std::vector<char>> ev) {removeElementFromMap(ev.getKey());};
std::function<void(ClientCacheEntryRemovedEvent<std::vector<char>> ev)> removed =
[this] (ClientCacheEntryRemovedEvent<std::vector<char>> ev) {removeElementFromMap(ev.getKey());};
std::function<void(ClientCacheEntryExpiredEvent<std::vector<char>> ev)> expired =
[this] (ClientCacheEntryExpiredEvent<std::vector<char>> ev) {removeElementFromMap(ev.getKey());};
std::function<void(ClientCacheEntryModifiedEvent<std::vector<char>> ev)> modified =
[this] (ClientCacheEntryModifiedEvent<std::vector<char>> ev) {removeElementFromMap(ev.getKey());};
std::function < void() > failOverHandler =
[this] () {
this->invalidateCache();
};
cl.add_listener(f);
cl.add_listener(created);
cl.add_listener(removed);
cl.add_listener(modified);
cl.add_listener(expired);
this->addClientListener(cl, filterFactoryParams, converterFactoryParams,
failOverHandler);
}
void listener(
std::map<std::vector<char>, VersionedValueImpl<std::vector<char> > > &map,
ClientCacheEntryCustomEvent &ce) {
// bytearray format is <keyLen[1]><key[keyLen]><valueLen[1]><value[valueLen]>
const std::vector<char> &v = ce.getEventData();
if (v.size() == 0)
return;
unsigned int sizeKey = v[0];
if (sizeKey == 0)
return;
auto i = v.begin() + 1;
auto f = v.begin() + 1 + sizeKey;
std::vector<char> key(i, f);
unsigned int sizeValue;
std::vector<char> value;
if (sizeKey + 1 < v.size()) {
sizeValue = *(v.data() + sizeKey + 1);
const char* i1 = v.data() + sizeKey + 2;
const char* f1 = v.data() + sizeKey + 2 + sizeValue;
value = std::vector<char>(i1, f1);
}
else
{
// If no value it's an entry removed event
removeElementFromMap(key);
return;
}
unsigned long version = 0;
if (v.size() - sizeKey - sizeValue - 2 >= 8) {
for (unsigned int i = 0; i < 8; i++) {
version = (version << 8) + v[sizeKey + sizeValue + 2 + i];
}
}
VersionedValueImpl<std::vector<char> > vv;
vv.setValue(value);
vv.setVersion(version);
addElementToMap(key, vv);
}

};

}
Expand Down