Skip to main content



      Home
Home » Eclipse Projects » Eclipse Scout » ICacheRegistryService and CacheBuilder possible issue
ICacheRegistryService and CacheBuilder possible issue [message #1828732] Wed, 17 June 2020 17:22 Go to next message
Eclipse UserFriend
I was experimenting with concurrent access to the cache including its possible concurrent creation.
To my surprise creating twice the same cache did not caused an error.
I created custom CacheRegisteryService to log what is going on...

It appears that cache is successfuly created twice, but only one of them is referenced in Cache RegisteryService (the last one created).

If I understand it correctly ConcurrentHashMap.put() overwrites previous value if there was any and returns the previous value.

I see three solutions:
1. After building cache do not use that object, get it instead from CacheRegisteryService - the easiest to implement (Possible cached data loss?)
2. make CacheRegisteryService throw exceptio on second create
3. make CacheRegisteryService return existing cache on second create - the most convenient to use. (assuming the remaining cache parameters are the same). But that would require altering interface ICacheRegisteryService, and build() and register() methods in CacheBuilder class.

experiments:
...
		ICache<KeyContext, ScoutRole> c1 = createRolesCache();
		ICache<KeyContext, ScoutRole> c2 = getRolesCache();
		ICache<KeyContext, ScoutRole> c3 = createRolesCache();
		ICache<KeyContext, ScoutRole> c4 = getRolesCache();
		
		LOG.debug("c1: {}", c1);
		LOG.debug("c2: {}", c2);
		LOG.debug("c3: {}", c3);
		LOG.debug("c4: {}", c4);

...

	private ICache<KeyContext, ScoutRole> getRolesCache() {
		LOG.entry();
		ICache<KeyContext, ScoutRole> result = null;
		
		CacheRegistryService crs = BEANS.get(CacheRegistryService.class);
		result = crs.opt(ROLES_CACHE_ID);
		
		if (result == null) {
			result = createRolesCache();
		}
		
		return LOG.exit(result);
	}

	private ICache<KeyContext, ScoutRole> createRolesCache() {
		LOG.entry();
		ICache<KeyContext, ScoutRole> result = null;
		
		@SuppressWarnings("unchecked")
		ICacheBuilder<KeyContext, ScoutRole> cacheBuilder = BEANS.get(ICacheBuilder.class);
		result = cacheBuilder
				.withCacheId(ROLES_CACHE_ID)
				.withValueResolver(new PermissionCacheValueResolver())
				.withThreadSafe(true)
				.build();
		
		return LOG.exit(result);
	}

package io.poc.scout;

import org.eclipse.scout.rt.platform.Replace;
import org.eclipse.scout.rt.platform.cache.CacheRegistryService;
import org.eclipse.scout.rt.platform.cache.ICache;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;

@Replace
public class MyCacheRegistryService extends CacheRegistryService {
	
	private static final XLogger LOG = XLoggerFactory.getXLogger(MyCacheRegistryService.class);
	
	  
	public MyCacheRegistryService() {
		LOG.entry();
		LOG.exit();
	}
	
	
	@Override
	public <K, V> void register(ICache<K, V> cache) {
		LOG.entry(cache);
		
		if (getMap().get(cache.getCacheId()) != null) {
			LOG.debug("cache already registered: {}", cache.getCacheId());
		}
		
		getMap().put(cache.getCacheId(), cache);
		
		LOG.debug("keys: {}", getMap().keySet());
		
		LOG.exit();
	}
	
}


relevant logs:
22:03:54.040 T [qtp440938038-12] io.poc.scout.MyCacheRegistryService register(MyCacheRegistryService.java:23) - entry with (org.eclipse.scout.rt.platform.cache.BasicCache@5c933438)
22:03:54.041 D [qtp440938038-12] io.poc.scout.MyCacheRegistryService register(MyCacheRegistryService.java:31) - keys: [org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService.CACHE, org.eclipse.scout.rt.shared.services.common.code.CodeService]
22:03:54.042 T [qtp440938038-12] io.poc.scout.MyCacheRegistryService register(MyCacheRegistryService.java:33) - exit
22:03:54.043 T [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService createRolesCache(ServerAccessControlService.java:267) - exit with (org.eclipse.scout.rt.platform.cache.BasicCache@5c933438)
22:03:54.045 T [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService getRolesCache(ServerAccessControlService.java:242) - entry
22:03:54.048 T [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService getRolesCache(ServerAccessControlService.java:252) - exit with (org.eclipse.scout.rt.platform.cache.BasicCache@5c933438)
22:03:54.049 T [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService createRolesCache(ServerAccessControlService.java:256) - entry
22:03:54.058 T [qtp440938038-12] io.poc.scout.MyCacheRegistryService register(MyCacheRegistryService.java:23) - entry with (org.eclipse.scout.rt.platform.cache.BasicCache@113fed2c)
22:03:54.059 D [qtp440938038-12] io.poc.scout.MyCacheRegistryService register(MyCacheRegistryService.java:26) - cache already registered: org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService.CACHE
22:03:54.059 D [qtp440938038-12] io.poc.scout.MyCacheRegistryService register(MyCacheRegistryService.java:31) - keys: [org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService.CACHE, org.eclipse.scout.rt.shared.services.common.code.CodeService]
22:03:54.064 T [qtp440938038-12] io.poc.scout.MyCacheRegistryService register(MyCacheRegistryService.java:33) - exit
22:03:54.068 T [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService createRolesCache(ServerAccessControlService.java:267) - exit with (org.eclipse.scout.rt.platform.cache.BasicCache@113fed2c)
22:03:54.072 T [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService getRolesCache(ServerAccessControlService.java:242) - entry
22:03:54.073 T [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService getRolesCache(ServerAccessControlService.java:252) - exit with (org.eclipse.scout.rt.platform.cache.BasicCache@113fed2c)
22:03:54.074 D [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService <init>(ServerAccessControlService.java:56) - c1: org.eclipse.scout.rt.platform.cache.BasicCache@5c933438
22:03:54.075 D [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService <init>(ServerAccessControlService.java:57) - c2: org.eclipse.scout.rt.platform.cache.BasicCache@5c933438
22:03:54.076 D [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService <init>(ServerAccessControlService.java:58) - c3: org.eclipse.scout.rt.platform.cache.BasicCache@113fed2c
22:03:54.081 D [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService <init>(ServerAccessControlService.java:59) - c4: org.eclipse.scout.rt.platform.cache.BasicCache@113fed2c
22:03:54.083 T [qtp440938038-12] org.eclipse.scout.apps.helloworld.server.security.ServerAccessControlService <init>(ServerAccessControlService.java:61) - exit




Re: ICacheRegistryService and CacheBuilder possible issue [message #1828763 is a reply to message #1828732] Thu, 18 June 2020 04:21 Go to previous messageGo to next message
Eclipse UserFriend
I agree with you. Can you create a bug on
https://bugs.eclipse.org/bugs/buglist.cgi?component=Scout&product=Scout&resolution=---

In the comment field simply place a reference link to this topic .
Re: ICacheRegistryService and CacheBuilder possible issue [message #1828764 is a reply to message #1828763] Thu, 18 June 2020 04:51 Go to previous message
Eclipse UserFriend
Done.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=564402
Previous Topic:Scout + JPA. Where is good place to get EntityManager?
Next Topic:Scout Lazy Loading & Custom Themes
Goto Forum:
  


Current Time: Mon Jul 14 08:11:43 EDT 2025

Powered by FUDForum. Page generated in 0.03525 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top