mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-23 11:47:40 +00:00
Evict fixes
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14106 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
c3718d531b
commit
8663b65640
@ -32,7 +32,9 @@
|
|||||||
import org.jboss.cache.config.Option;
|
import org.jboss.cache.config.Option;
|
||||||
import org.jboss.cache.notifications.annotation.CacheListener;
|
import org.jboss.cache.notifications.annotation.CacheListener;
|
||||||
import org.jboss.cache.notifications.annotation.NodeModified;
|
import org.jboss.cache.notifications.annotation.NodeModified;
|
||||||
|
import org.jboss.cache.notifications.annotation.NodeRemoved;
|
||||||
import org.jboss.cache.notifications.event.NodeModifiedEvent;
|
import org.jboss.cache.notifications.event.NodeModifiedEvent;
|
||||||
|
import org.jboss.cache.notifications.event.NodeRemovedEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the behavior of the timestamps cache region for JBossCache 2.x.
|
* Defines the behavior of the timestamps cache region for JBossCache 2.x.
|
||||||
@ -81,7 +83,7 @@ public void evict(Object key) throws CacheException {
|
|||||||
// TODO Is this a valid operation on a timestamps cache?
|
// TODO Is this a valid operation on a timestamps cache?
|
||||||
localCache.remove(key);
|
localCache.remove(key);
|
||||||
Option opt = getNonLockingDataVersionOption(true);
|
Option opt = getNonLockingDataVersionOption(true);
|
||||||
CacheHelper.remove(getCacheInstance(), getRegionFqn(), key, opt);
|
CacheHelper.removeNode(getCacheInstance(), getRegionFqn(), key, opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void evictAll() throws CacheException {
|
public void evictAll() throws CacheException {
|
||||||
@ -89,6 +91,8 @@ public void evictAll() throws CacheException {
|
|||||||
localCache.clear();
|
localCache.clear();
|
||||||
Option opt = getNonLockingDataVersionOption(true);
|
Option opt = getNonLockingDataVersionOption(true);
|
||||||
CacheHelper.removeAll(getCacheInstance(), getRegionFqn(), opt);
|
CacheHelper.removeAll(getCacheInstance(), getRegionFqn(), opt);
|
||||||
|
// Restore the region root node
|
||||||
|
CacheHelper.addNode(getCacheInstance(), getRegionFqn(), false, true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(Object key) throws CacheException {
|
public Object get(Object key) throws CacheException {
|
||||||
@ -121,11 +125,11 @@ public void put(Object key, Object value) throws CacheException {
|
|||||||
// prevents reads and other updates
|
// prevents reads and other updates
|
||||||
Transaction tx = suspend();
|
Transaction tx = suspend();
|
||||||
try {
|
try {
|
||||||
// We ensure ASYNC semantics (JBCACHE-1175)
|
// TODO Why not use the timestamp in a DataVersion?
|
||||||
Option opt = getNonLockingDataVersionOption(false);
|
Option opt = getNonLockingDataVersionOption(false);
|
||||||
|
// We ensure ASYNC semantics (JBCACHE-1175)
|
||||||
opt.setForceAsynchronous(true);
|
opt.setForceAsynchronous(true);
|
||||||
getCacheInstance().getInvocationContext().setOptionOverrides(opt);
|
CacheHelper.put(getCacheInstance(), getRegionFqn(), key, value, opt);
|
||||||
getCacheInstance().put(new Fqn(regionFqn, key), ITEM, value);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CacheException(e);
|
throw new CacheException(e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -160,6 +164,30 @@ public void nodeModified(NodeModifiedEvent event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monitors cache events and updates the local cache
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@NodeRemoved
|
||||||
|
public void nodeRemoved(NodeRemovedEvent event) {
|
||||||
|
if (event.isOriginLocal() || event.isPre())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Fqn fqn = event.getFqn();
|
||||||
|
Fqn regFqn = getRegionFqn();
|
||||||
|
if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) {
|
||||||
|
Object key = fqn.get(regFqn.size());
|
||||||
|
localCache.remove(key);
|
||||||
|
}
|
||||||
|
else if (fqn.equals(regFqn)) {
|
||||||
|
localCache.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Brings all data from the distributed cache into our local cache.
|
||||||
|
*/
|
||||||
private void populateLocalCache() {
|
private void populateLocalCache() {
|
||||||
Set children = CacheHelper.getChildrenNames(getCacheInstance(), getRegionFqn());
|
Set children = CacheHelper.getChildrenNames(getCacheInstance(), getRegionFqn());
|
||||||
for (Object key : children) {
|
for (Object key : children) {
|
||||||
@ -191,7 +219,8 @@ private boolean updateLocalCache(Object key, Object value) {
|
|||||||
// Double check that it was an increase
|
// Double check that it was an increase
|
||||||
if (oldVal != null && oldVal.longValue() > newVal) {
|
if (oldVal != null && oldVal.longValue() > newVal) {
|
||||||
// Nope; Restore the old value
|
// Nope; Restore the old value
|
||||||
increase = updateLocalCache(key, oldVal);
|
updateLocalCache(key, oldVal);
|
||||||
|
increase = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user