From e02e85c20f5ac8f69990f04bfb5ce531c6d5ad22 Mon Sep 17 00:00:00 2001 From: Preston-Crary Date: Fri, 26 Jun 2015 08:15:38 -0700 Subject: [PATCH] LPS-56126 SF --- .../journal/util/impl/JournalContentImpl.java | 2 +- .../permission/PermissionCacheUtil.java | 9 +-- .../cache/index/PortalCacheIndexerTest.java | 36 ++++----- .../cache/index/PortalCacheIndexer.java | 76 +++++++++---------- ...appedMethodCallableInvocationHandler.java} | 4 +- 5 files changed, 57 insertions(+), 70 deletions(-) rename portal-test/src/com/liferay/portal/kernel/concurrent/test/{MappedMethodNameCallableInvocationHandler.java => MappedMethodCallableInvocationHandler.java} (95%) diff --git a/modules/apps/journal/journal-service/src/com/liferay/journal/util/impl/JournalContentImpl.java b/modules/apps/journal/journal-service/src/com/liferay/journal/util/impl/JournalContentImpl.java index 0e90f0e25dee26..9b93b58a532ae2 100644 --- a/modules/apps/journal/journal-service/src/com/liferay/journal/util/impl/JournalContentImpl.java +++ b/modules/apps/journal/journal-service/src/com/liferay/journal/util/impl/JournalContentImpl.java @@ -68,7 +68,7 @@ public void clearCache() { public void clearCache( long groupId, String articleId, String ddmTemplateKey) { - _getPortalCacheIndexer().removeIndexedCacheKeys( + _getPortalCacheIndexer().removeKeys( JournalContentKeyIndexAccessor.getIndex( groupId, articleId, ddmTemplateKey)); } diff --git a/portal-impl/src/com/liferay/portal/security/permission/PermissionCacheUtil.java b/portal-impl/src/com/liferay/portal/security/permission/PermissionCacheUtil.java index 8ec03df8b41ac8..e4cac1500e32d9 100644 --- a/portal-impl/src/com/liferay/portal/security/permission/PermissionCacheUtil.java +++ b/portal-impl/src/com/liferay/portal/security/permission/PermissionCacheUtil.java @@ -72,9 +72,8 @@ public static void clearCache(long... userIds) { for (long userId : userIds) { _userPermissionCheckerBagPortalCache.remove(userId); - _userRolePortalCacheIndexer.removeIndexedCacheKeys(userId); - _permissionCheckerBagPortalCacheIndexer.removeIndexedCacheKeys( - userId); + _userRolePortalCacheIndexer.removeKeys(userId); + _permissionCheckerBagPortalCacheIndexer.removeKeys(userId); } _permissionPortalCache.removeAll(); @@ -91,7 +90,7 @@ public static void clearResourceBlockCache( return; } - _resourceBlockIdsBagCacheIndexer.removeIndexedCacheKeys( + _resourceBlockIdsBagCacheIndexer.removeKeys( ResourceBlockIdsBagKeyIndexAccessor.getIndex( companyId, groupId, name)); } @@ -113,7 +112,7 @@ public static void clearResourcePermissionCache( return; } - _permissionPortalCacheIndexer.removeIndexedCacheKeys( + _permissionPortalCacheIndexer.removeKeys( PermissionKeyIndexAccessor.getIndex(name, primKey)); } diff --git a/portal-impl/test/unit/com/liferay/portal/kernel/cache/index/PortalCacheIndexerTest.java b/portal-impl/test/unit/com/liferay/portal/kernel/cache/index/PortalCacheIndexerTest.java index dce13205f8f87f..bc5107da7ab6e2 100644 --- a/portal-impl/test/unit/com/liferay/portal/kernel/cache/index/PortalCacheIndexerTest.java +++ b/portal-impl/test/unit/com/liferay/portal/kernel/cache/index/PortalCacheIndexerTest.java @@ -17,7 +17,7 @@ import com.liferay.portal.cache.test.TestPortalCache; import com.liferay.portal.kernel.cache.CacheListener; import com.liferay.portal.kernel.cache.PortalCache; -import com.liferay.portal.kernel.concurrent.test.MappedMethodNameCallableInvocationHandler; +import com.liferay.portal.kernel.concurrent.test.MappedMethodCallableInvocationHandler; import com.liferay.portal.kernel.test.ReflectionTestUtil; import com.liferay.portal.kernel.test.rule.CodeCoverageAssertor; import com.liferay.portal.kernel.test.util.RandomTestUtil; @@ -52,8 +52,8 @@ public void setUp() throws Exception { _cacheListener = ReflectionTestUtil.getFieldValue( _portalCache, "aggregatedCacheListener"); - _mappedMethodNameCallableInvocationHandler = - new MappedMethodNameCallableInvocationHandler( + _mappedMethodCallableInvocationHandler = + new MappedMethodCallableInvocationHandler( ReflectionTestUtil.getFieldValue( _portalCacheIndexer, "_indexedCacheKeys"), true); @@ -63,14 +63,14 @@ public void setUp() throws Exception { ProxyUtil.newProxyInstance( ClassLoader.getSystemClassLoader(), new Class[] {ConcurrentMap.class}, - _mappedMethodNameCallableInvocationHandler)); + _mappedMethodCallableInvocationHandler)); } @Test public void testAddIndexedCacheKeyConcurrentPutDifferentKeys() throws ReflectiveOperationException { - _mappedMethodNameCallableInvocationHandler.putBeforeCallable( + _mappedMethodCallableInvocationHandler.putBeforeCallable( ConcurrentMap.class.getMethod( "putIfAbsent", Object.class, Object.class), new Callable() { @@ -131,7 +131,7 @@ public void testDispose() { _portalCache.unregisterCacheListeners(); - Set testKeys = _portalCacheIndexer.getIndexedCacheKeys( + Set testKeys = _portalCacheIndexer.getKeys( _indexAccessor.getIndex(_INDEX_1_KEY_1)); Assert.assertTrue(testKeys.isEmpty()); @@ -141,7 +141,7 @@ public void testDispose() { public void testGetIndexedCacheKeysWithIndexKey() { _portalCache.put(_INDEX_1_KEY_1, _VALUE); - Set testKeys = _portalCacheIndexer.getIndexedCacheKeys( + Set testKeys = _portalCacheIndexer.getKeys( _indexAccessor.getIndex(_INDEX_1_KEY_1)); testKeys.clear(); @@ -151,8 +151,7 @@ public void testGetIndexedCacheKeysWithIndexKey() { @Test public void testGetIndexedCacheKeysWithoutIndexKey() { - _portalCacheIndexer.getIndexedCacheKeys( - _indexAccessor.getIndex(_INDEX_1_KEY_1)); + _portalCacheIndexer.getKeys(_indexAccessor.getIndex(_INDEX_1_KEY_1)); assertIndexCacheSynchronization(); } @@ -216,7 +215,7 @@ public void testRemoveIndexedCacheKeyConcurrentPut() _portalCache.put(_INDEX_1_KEY_1, _VALUE); - _mappedMethodNameCallableInvocationHandler.putBeforeCallable( + _mappedMethodCallableInvocationHandler.putBeforeCallable( ConcurrentMap.class.getMethod("remove", Object.class, Object.class), new Callable() { @@ -240,13 +239,13 @@ public void testRemoveIndexedCacheKeyConcurrentRemove() _portalCache.put(_INDEX_1_KEY_1, _VALUE); - _mappedMethodNameCallableInvocationHandler.putBeforeCallable( + _mappedMethodCallableInvocationHandler.putBeforeCallable( ConcurrentMap.class.getMethod("remove", Object.class, Object.class), new Callable() { @Override public Void call() throws Exception { - _portalCacheIndexer.removeIndexedCacheKeys(1L); + _portalCacheIndexer.removeKeys(1L); return null; } @@ -262,8 +261,7 @@ public Void call() throws Exception { public void testRemoveIndexedCacheKeysWithIndex() { _portalCache.put(_INDEX_1_KEY_1, _VALUE); - _portalCacheIndexer.removeIndexedCacheKeys( - _indexAccessor.getIndex(_INDEX_1_KEY_1)); + _portalCacheIndexer.removeKeys(_indexAccessor.getIndex(_INDEX_1_KEY_1)); assertIndexCacheSynchronization(); } @@ -272,8 +270,7 @@ public void testRemoveIndexedCacheKeysWithIndex() { public void testRemoveIndexedCacheKeysWithoutIndex() { _portalCache.put(_INDEX_1_KEY_1, _VALUE); - _portalCacheIndexer.removeIndexedCacheKeys( - _indexAccessor.getIndex(_INDEX_2_KEY_3)); + _portalCacheIndexer.removeKeys(_indexAccessor.getIndex(_INDEX_2_KEY_3)); assertIndexCacheSynchronization(); } @@ -309,8 +306,7 @@ protected void assertIndexCacheSynchronization() { Set actualTestKeys = new HashSet<>(); for (Long index : indexes) { - actualTestKeys.addAll( - _portalCacheIndexer.getIndexedCacheKeys(index)); + actualTestKeys.addAll(_portalCacheIndexer.getKeys(index)); } Assert.assertEquals(expectedTestKeys, actualTestKeys); @@ -328,8 +324,8 @@ protected void assertIndexCacheSynchronization() { new TestKeyIndexAccessor(); private CacheListener _cacheListener; - private MappedMethodNameCallableInvocationHandler - _mappedMethodNameCallableInvocationHandler; + private MappedMethodCallableInvocationHandler + _mappedMethodCallableInvocationHandler; private PortalCache _portalCache; private PortalCacheIndexer _portalCacheIndexer; diff --git a/portal-service/src/com/liferay/portal/kernel/cache/index/PortalCacheIndexer.java b/portal-service/src/com/liferay/portal/kernel/cache/index/PortalCacheIndexer.java index 7444e457f0fbce..f36fc9ea4705f2 100644 --- a/portal-service/src/com/liferay/portal/kernel/cache/index/PortalCacheIndexer.java +++ b/portal-service/src/com/liferay/portal/kernel/cache/index/PortalCacheIndexer.java @@ -45,64 +45,61 @@ public PortalCacheIndexer( } } - public Set getIndexedCacheKeys(I index) { - Set indexedCacheKeys = _indexedCacheKeys.get(index); + public Set getKeys(I index) { + Set keys = _indexedCacheKeys.get(index); - if (indexedCacheKeys == null) { + if (keys == null) { return Collections.emptySet(); } - return new HashSet<>(indexedCacheKeys); + return new HashSet<>(keys); } - public void removeIndexedCacheKeys(I index) { - Set indexedCacheKeys = _indexedCacheKeys.remove(index); + public void removeKeys(I index) { + Set keys = _indexedCacheKeys.remove(index); - if (indexedCacheKeys == null) { + if (keys == null) { return; } - for (K indexedCacheKey : indexedCacheKeys) { - _portalCache.remove(indexedCacheKey); + for (K key : keys) { + _portalCache.remove(key); } } - private void _addIndexedCacheKey(K indexedCacheKey) { - I index = _indexAccessor.getIndex(indexedCacheKey); + private void _addIndexedCacheKey(K key) { + I index = _indexAccessor.getIndex(key); - Set indexedCacheKeys = _indexedCacheKeys.get(index); + Set keys = _indexedCacheKeys.get(index); - if (indexedCacheKeys == null) { - Set newIndexedCacheKeys = new ConcurrentHashSet<>(); + if (keys == null) { + Set newKeys = new ConcurrentHashSet<>(); - newIndexedCacheKeys.add(indexedCacheKey); + newKeys.add(key); - indexedCacheKeys = _indexedCacheKeys.putIfAbsent( - index, newIndexedCacheKeys); + keys = _indexedCacheKeys.putIfAbsent(index, newKeys); - if (indexedCacheKeys == null) { + if (keys == null) { return; } } - indexedCacheKeys.add(indexedCacheKey); + keys.add(key); } - private void _removeIndexedCacheKey(K indexedCacheKey) { - I index = _indexAccessor.getIndex(indexedCacheKey); + private void _removeIndexedCacheKey(K key) { + I index = _indexAccessor.getIndex(key); - Set indexedCacheKeys = _indexedCacheKeys.get(index); + Set keys = _indexedCacheKeys.get(index); - if (indexedCacheKeys == null) { + if (keys == null) { return; } - indexedCacheKeys.remove(indexedCacheKey); + keys.remove(key); - if (indexedCacheKeys.isEmpty() && - _indexedCacheKeys.remove(index, indexedCacheKeys)) { - - for (K victimIndexedCacheKey : indexedCacheKeys) { + if (keys.isEmpty() && _indexedCacheKeys.remove(index, keys)) { + for (K victimIndexedCacheKey : keys) { _addIndexedCacheKey(victimIndexedCacheKey); } } @@ -122,40 +119,35 @@ public void dispose() { @Override public void notifyEntryEvicted( - PortalCache portalCache, K indexedCacheKey, V value, - int timeToLive) { + PortalCache portalCache, K key, V value, int timeToLive) { - _removeIndexedCacheKey(indexedCacheKey); + _removeIndexedCacheKey(key); } @Override public void notifyEntryExpired( - PortalCache portalCache, K indexedCacheKey, V value, - int timeToLive) { + PortalCache portalCache, K key, V value, int timeToLive) { - _removeIndexedCacheKey(indexedCacheKey); + _removeIndexedCacheKey(key); } @Override public void notifyEntryPut( - PortalCache portalCache, K indexedCacheKey, V value, - int timeToLive) { + PortalCache portalCache, K key, V value, int timeToLive) { - _addIndexedCacheKey(indexedCacheKey); + _addIndexedCacheKey(key); } @Override public void notifyEntryRemoved( - PortalCache portalCache, K indexedCacheKey, V value, - int timeToLive) { + PortalCache portalCache, K key, V value, int timeToLive) { - _removeIndexedCacheKey(indexedCacheKey); + _removeIndexedCacheKey(key); } @Override public void notifyEntryUpdated( - PortalCache portalCache, K indexedCacheKey, V value, - int timeToLive) { + PortalCache portalCache, K key, V value, int timeToLive) { } @Override diff --git a/portal-test/src/com/liferay/portal/kernel/concurrent/test/MappedMethodNameCallableInvocationHandler.java b/portal-test/src/com/liferay/portal/kernel/concurrent/test/MappedMethodCallableInvocationHandler.java similarity index 95% rename from portal-test/src/com/liferay/portal/kernel/concurrent/test/MappedMethodNameCallableInvocationHandler.java rename to portal-test/src/com/liferay/portal/kernel/concurrent/test/MappedMethodCallableInvocationHandler.java index f422f5eb060d87..415539b68c7f50 100644 --- a/portal-test/src/com/liferay/portal/kernel/concurrent/test/MappedMethodNameCallableInvocationHandler.java +++ b/portal-test/src/com/liferay/portal/kernel/concurrent/test/MappedMethodCallableInvocationHandler.java @@ -25,10 +25,10 @@ /** * @author Preston Crary */ -public class MappedMethodNameCallableInvocationHandler +public class MappedMethodCallableInvocationHandler implements InvocationHandler { - public MappedMethodNameCallableInvocationHandler( + public MappedMethodCallableInvocationHandler( Object instance, boolean removeOnCall) { _instance = instance;