Merge branch 'REPO-1259' into 'master'

Repo 1259

Part of fix for Repo1259.

* remove commented out code
* fix code formatting (CMISAbstractDictionaryService)
* fix up how the CMIS dictionary is refreshed after a dictionary refresh: dictionaryListener.afterDictionaryInit() is called _after_ the dictionary is made live (including changes to CompiledModelsCache to achieve this).

See merge request !3
This commit is contained in:
Stefan Kopf
2016-11-03 16:14:02 +00:00
9 changed files with 138 additions and 218 deletions

View File

@@ -145,7 +145,7 @@
<dependency>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-core</artifactId>
<version>6.5</version>
<version>6.8</version>
</dependency>
<!--
| provided dependencies (are not transitive and not included in webapps)

View File

@@ -73,20 +73,21 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
private final ReentrantReadWriteLock registryLock = new ReentrantReadWriteLock();
private final WriteLock registryWriteLock = registryLock.writeLock();
private final ReadLock registryReadLock = registryLock.readLock();
// note: cache is tenant-aware (if using TransctionalCache impl)
private SimpleCache<String, CMISDictionaryRegistry> singletonCache; // eg. for openCmisDictionaryRegistry
private SimpleCache<String, CMISDictionaryRegistry> cmisRegistryCache;
private final String KEY_OPENCMIS_DICTIONARY_REGISTRY = "key.openCmisDictionaryRegistry";
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
this.tenantService = tenantService;
}
/**
/**
* Set the mapping service
*
* @param cmisMapping CMISMapping
* @param cmisMapping
* CMISMapping
*/
public void setCmisMapping(CMISMapping cmisMapping)
{
@@ -96,7 +97,8 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
/**
* Set the property accessor mapping service
*
* @param accessorMapping mapping
* @param accessorMapping
* mapping
*/
public void setPropertyAccessorMapping(PropertyAccessorMapping accessorMapping)
{
@@ -106,7 +108,8 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
/**
* Set the property lucene mapping service
*
* @param luceneBuilderMapping mapping
* @param luceneBuilderMapping
* mapping
*/
public void setPropertyLuceneBuilderMapping(PropertyLuceneBuilderMapping luceneBuilderMapping)
{
@@ -116,7 +119,8 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
/**
* Set the dictionary Service
*
* @param dictionaryService DictionaryService
* @param dictionaryService
* DictionaryService
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
@@ -126,7 +130,8 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
/**
* Set the dictionary DAO
*
* @param dictionaryDAO DictionaryDAO
* @param dictionaryDAO
* DictionaryDAO
*/
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
{
@@ -135,63 +140,57 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
public void setSingletonCache(SimpleCache<String, CMISDictionaryRegistry> singletonCache)
{
this.singletonCache = singletonCache;
this.cmisRegistryCache = singletonCache;
}
protected interface DictionaryInitializer
{
Collection<AbstractTypeDefinitionWrapper> createDefinitions(CMISDictionaryRegistry cmisRegistry);
Collection<AbstractTypeDefinitionWrapper> createDefinitions(CMISDictionaryRegistry cmisRegistry, CompiledModel model);
Collection<AbstractTypeDefinitionWrapper> createDefinitions(CMISDictionaryRegistry cmisRegistry);
Collection<AbstractTypeDefinitionWrapper> createDefinitions(CMISDictionaryRegistry cmisRegistry,
CompiledModel model);
}
protected abstract DictionaryInitializer getCoreDictionaryInitializer();
protected abstract DictionaryInitializer getTenantDictionaryInitializer();
protected CMISDictionaryRegistry getRegistry()
{
String tenant = TenantUtil.getCurrentDomain();
return getRegistry(tenant);
String tenant = TenantUtil.getCurrentDomain();
return getRegistry(tenant);
}
CMISDictionaryRegistry getRegistry(String tenant)
{
CMISDictionaryRegistry cmisRegistry = null;
boolean readLockReleased = false;
//Make sure that DictionaryRegistry exist
dictionaryDAO.getDictionaryRegistry(tenant);
CMISDictionaryRegistry cmisRegistry = null;
registryReadLock.lock();
try
{
String cacheKey = getCacheKey(tenant);
cmisRegistry = singletonCache.get(cacheKey);
if(cmisRegistry == null)
{
registryReadLock.unlock();
readLockReleased = true;
String cacheKey = getCacheKey(tenant);
registryWriteLock.lock();
try
{
cmisRegistry = singletonCache.get(cacheKey);
if(cmisRegistry == null)
{
cmisRegistry = createDictionaryRegistry(tenant);
}
}
finally
{
registryWriteLock.unlock();
}
}
}
finally
{
if(!readLockReleased)
{
registryReadLock.unlock();
}
}
registryReadLock.lock();
try
{
cmisRegistry = cmisRegistryCache.get(cacheKey);
}
finally
{
registryReadLock.unlock();
}
if (cmisRegistry == null)
{
cmisRegistry = createDictionaryRegistry(tenant);
registryWriteLock.lock();
try
{
cmisRegistryCache.put(cacheKey, cmisRegistry);
}
finally
{
registryWriteLock.unlock();
}
}
return cmisRegistry;
}
@@ -199,9 +198,8 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
/*
* (non-Javadoc)
*
* @see
* org.springframework.extensions.surf.util.AbstractLifecycleBean#onBootstrap
* (org.springframework.context.ApplicationEvent)
* @see org.springframework.extensions.surf.util.AbstractLifecycleBean#
* onBootstrap (org.springframework.context.ApplicationEvent)
*/
@Override
protected void onBootstrap(ApplicationEvent event)
@@ -233,42 +231,45 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
private String getCacheKey()
{
String tenant = tenantService.getCurrentUserDomain();
return getCacheKey(tenant);
String tenant = tenantService.getCurrentUserDomain();
return getCacheKey(tenant);
}
private String getCacheKey(String tenant)
{
String cacheKey = KEY_OPENCMIS_DICTIONARY_REGISTRY + "." + tenant + "." + cmisMapping.getCmisVersion().toString();
return cacheKey;
String cacheKey = KEY_OPENCMIS_DICTIONARY_REGISTRY + "." + tenant + "."
+ cmisMapping.getCmisVersion().toString();
return cacheKey;
}
protected CMISDictionaryRegistry createCoreDictionaryRegistry()
{
CMISDictionaryRegistryImpl cmisRegistry = new CMISDictionaryRegistryImpl(this, cmisMapping, dictionaryService,
getCoreDictionaryInitializer());
CMISDictionaryRegistryImpl cmisRegistry = new CMISDictionaryRegistryImpl(this, cmisMapping, dictionaryService,
getCoreDictionaryInitializer());
cmisRegistry.init();
return cmisRegistry;
}
protected CMISDictionaryRegistry createTenantDictionaryRegistry(String tenant)
{
CMISDictionaryRegistryImpl cmisRegistry = new CMISDictionaryRegistryImpl(this, tenant, "",
cmisMapping, dictionaryService, getTenantDictionaryInitializer());
CMISDictionaryRegistryImpl cmisRegistry = new CMISDictionaryRegistryImpl(this, tenant, "", cmisMapping,
dictionaryService, getTenantDictionaryInitializer());
cmisRegistry.init();
return cmisRegistry;
}
protected CMISDictionaryRegistry createDictionaryRegistryWithWriteLock()
{
CMISDictionaryRegistry cmisRegistry = null;
String tenant = TenantUtil.getCurrentDomain();
String tenant = TenantUtil.getCurrentDomain();
CMISDictionaryRegistry cmisRegistry = createDictionaryRegistry(tenant);
String cacheKey = getCacheKey(tenant);
registryWriteLock.lock();
try
{
cmisRegistry = createDictionaryRegistry(tenant);
// publish new registry
cmisRegistryCache.put(cacheKey, cmisRegistry);
}
finally
{
@@ -280,20 +281,16 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
protected CMISDictionaryRegistry createDictionaryRegistry(String tenant)
{
CMISDictionaryRegistry cmisRegistry = null;
String cacheKey = getCacheKey(tenant);
CMISDictionaryRegistry cmisRegistry = null;
if(tenant.equals(TenantService.DEFAULT_DOMAIN))
{
cmisRegistry = createCoreDictionaryRegistry();
}
else
{
cmisRegistry = createTenantDictionaryRegistry(tenant);
}
// publish new registry
singletonCache.put(cacheKey, cmisRegistry);
if (tenant.equals(TenantService.DEFAULT_DOMAIN))
{
cmisRegistry = createCoreDictionaryRegistry();
}
else
{
cmisRegistry = createTenantDictionaryRegistry(tenant);
}
return cmisRegistry;
}
@@ -373,7 +370,7 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
{
return getRegistry().getAssocDefByQName(cmisMapping.getCmisType(clazz));
}
@Override
public TypeDefinitionWrapper findTypeByQueryName(String queryName)
{
@@ -418,15 +415,16 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
@Override
public List<TypeDefinitionWrapper> getAllTypes()
{
// TODO is there a way of not having to reconstruct this every time?
return Collections.unmodifiableList(new ArrayList<TypeDefinitionWrapper>(getRegistry().getTypeDefs()));
// TODO is there a way of not having to reconstruct this every time?
return Collections.unmodifiableList(new ArrayList<TypeDefinitionWrapper>(getRegistry().getTypeDefs()));
}
@Override
public List<TypeDefinitionWrapper> getAllTypes(boolean includeParent)
{
// TODO is there a way of not having to reconstruct this every time?
return Collections.unmodifiableList(new ArrayList<TypeDefinitionWrapper>(getRegistry().getTypeDefs(includeParent)));
// TODO is there a way of not having to reconstruct this every time?
return Collections
.unmodifiableList(new ArrayList<TypeDefinitionWrapper>(getRegistry().getTypeDefs(includeParent)));
}
@Override
@@ -454,7 +452,7 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
@Override
public void modelAdded(CompiledModel model, String tenantDomain)
{
getRegistry(tenantDomain).addModel(model);
getRegistry(tenantDomain).addModel(model);
}
/*
@@ -465,7 +463,7 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
@Override
public void afterDictionaryInit()
{
createDictionaryRegistryWithWriteLock();
createDictionaryRegistryWithWriteLock();
}
/*
@@ -480,8 +478,8 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
registryWriteLock.lock();
try
{
String cacheKey = getCacheKey();
singletonCache.remove(cacheKey);
String cacheKey = getCacheKey();
cmisRegistryCache.remove(cacheKey);
}
finally
{
@@ -493,7 +491,7 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
public List<TypeDefinitionWrapper> getChildren(String typeId)
{
List<TypeDefinitionWrapper> children = getRegistry().getChildren(typeId);
for (TypeDefinitionWrapper child : children)
{
if (child != null && child.getTypeDefinition(false).getDisplayName() == null)
@@ -501,7 +499,7 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea
child.updateDefinition(dictionaryService);
}
}
return children;
return children;
}
}

View File

@@ -33,7 +33,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.opencmis.dictionary.CMISAbstractDictionaryService.DictionaryInitializer;
import org.alfresco.opencmis.mapping.CMISMapping;
import org.alfresco.repo.dictionary.CompiledModel;

View File

@@ -1,77 +0,0 @@
/*
* #%L
* Alfresco Data model classes
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.opencmis.dictionary;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
/**
* Temporary workaround for:
* <ul>
* <li>ACE-5041: CLONE - google docs content cannot be accessed via cmis</li>
* </ul>
*
* TODO: Remove this bean when rework for MNT-14819 is complete.
*
* @author Matt Ward
*/
public final class CMISDictionaryReload extends AbstractLifecycleBean
{
private static final Log log = LogFactory.getLog(CMISDictionaryReload.class);
private final CMISAbstractDictionaryService cmisDictService;
private final boolean enabled;
public CMISDictionaryReload(CMISAbstractDictionaryService cmisDictService, boolean enabled)
{
this.cmisDictService = cmisDictService;
this.enabled = enabled;
}
public void reload()
{
if (enabled)
{
// Avoid deadlock by making sure we already have a registry present.
cmisDictService.getRegistry();
log.debug("Reloading CMIS dictionary.");
cmisDictService.afterDictionaryInit();
}
}
@Override
protected void onBootstrap(ApplicationEvent event)
{
reload();
}
@Override
protected void onShutdown(ApplicationEvent event)
{
// Do nothing.
}
}

View File

@@ -29,6 +29,9 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.util.cache.AbstractAsynchronouslyRefreshedCache;
import org.alfresco.util.cache.RefreshableCacheEvent;
import org.alfresco.util.cache.RefreshableCacheListener;
import org.alfresco.util.cache.RefreshableCacheRefreshedEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -103,4 +106,49 @@ public class CompiledModelsCache extends AbstractAsynchronouslyRefreshedCache<Di
{
this.tenantService = tenantService;
}
@Override
public void afterPropertiesSet() throws Exception
{
super.afterPropertiesSet();
// RefreshableCacheListener as anonymous class since CompileModelsCache already
// implements this interface, but expects to be invoked in different circumstances.
register(new RefreshableCacheListener()
{
@Override
public void onRefreshableCacheEvent(RefreshableCacheEvent event)
{
if (logger.isDebugEnabled())
{
logger.debug("Handling "+event.getClass().getSimpleName()+
", cache="+event.getCacheId()+
", key="+event.getKey());
}
if (event instanceof RefreshableCacheRefreshedEvent &&
event.getCacheId().equals(getCacheId()))
{
// notify registered listeners that dictionary has been initialised (population is complete).
// Note we do that here to ensure that the dictionary registry has been added to the cache,
// so that any dependencies (like the CMIS dictionary) will use the new dictionary.
for (DictionaryListener dictionaryListener : dictionaryDAO.getDictionaryListeners())
{
logger.debug("Calling afterDIctionaryInit ["+event.getClass().getSimpleName()+
", cache="+event.getCacheId()+
", key="+event.getKey()+
"] on "+
dictionaryListener.getClass().getSimpleName());
dictionaryListener.afterDictionaryInit();
}
}
}
@Override
public String getCacheId()
{
return CompiledModelsCache.this.getCacheId();
}
});
}
}

View File

@@ -59,12 +59,6 @@ public class CoreDictionaryRegistryImpl extends AbstractDictionaryRegistry
dictionaryDeployer.onDictionaryInit();
}
// notify registered listeners that dictionary has been initialised (population is complete)
for (DictionaryListener dictionaryListener : dictionaryDAO.getDictionaryListeners())
{
dictionaryListener.afterDictionaryInit();
}
// Done
if (logger.isInfoEnabled())
{
@@ -87,33 +81,7 @@ public class CoreDictionaryRegistryImpl extends AbstractDictionaryRegistry
protected QName putModelImpl(CompiledModel model)
{
// TODO disallow model overrides for the core dictionary
// if(compiledModels.get(model.getModelDefinition().getName()) != null)
// {
// throw new AlfrescoRuntimeException("Cannot override existing model " + model.getModelDefinition().getName());
// }
//
// for(M2Namespace namespace : model.getM2Model().getNamespaces())
// {
// if(uriToModels.get(namespace.getUri()) != null)
// {
// throw new AlfrescoRuntimeException("Cannot override existing namespace " + namespace.getUri());
// }
// }
QName qname = super.putModelImpl(model);
// if(dictionaryDAO.isContextRefreshed())
// {
// for(DictionaryListener listener : dictionaryDAO.getDictionaryListeners())
// {
// if(listener instanceof ExtendedDictionaryListener)
// {
// ((ExtendedDictionaryListener)listener).coreModelAdded(model);
// }
// }
// }
return qname;
}

View File

@@ -186,9 +186,6 @@ public class DictionaryDAOImpl implements DictionaryDAO, NamespaceDAO,
{
DictionaryRegistry dictionaryRegistry = new CoreDictionaryRegistryImpl(
this);
getThreadLocal().put("", dictionaryRegistry);
dictionaryRegistry.init();
getThreadLocal().remove("");
return dictionaryRegistry;
}
@@ -202,9 +199,6 @@ public class DictionaryDAOImpl implements DictionaryDAO, NamespaceDAO,
{
DictionaryRegistry dictionaryRegistry = new TenantDictionaryRegistryImpl(
DictionaryDAOImpl.this, tenant);
getThreadLocal().put(tenant, dictionaryRegistry);
dictionaryRegistry.init();
getThreadLocal().remove(tenant);
return dictionaryRegistry;
}
}, tenantService.getDomainUser(
@@ -233,7 +227,6 @@ public class DictionaryDAOImpl implements DictionaryDAO, NamespaceDAO,
// TODO Should be reworked when ACE-2001 will be implemented
dictionaryRegistryCache.remove(tenant);
dictionaryRegistryCache.refresh(tenant);
if (logger.isDebugEnabled())
{

View File

@@ -221,12 +221,6 @@ public class TenantDictionaryRegistryImpl extends AbstractDictionaryRegistry
dictionaryDeployer.onDictionaryInit();
}
// notify registered listeners that dictionary has been initialised (population is complete)
for (DictionaryListener dictionaryListener : dictionaryDAO.getDictionaryListeners())
{
dictionaryListener.afterDictionaryInit();
}
// Done
if (logger.isInfoEnabled())
{

View File

@@ -33,9 +33,6 @@ import org.alfresco.service.NotAuditable;
import org.alfresco.service.cmr.i18n.MessageLookup;
import org.alfresco.service.namespace.QName;
import com.sun.tools.xjc.outline.Aspect;
/**
* This interface represents the Repository Data Dictionary. The