Skip to content
Snippets Groups Projects
Commit 15f4f75a authored by srosse's avatar srosse
Browse files

OO-1873: use putIfabsent to add collaboration tools in cache instead of doInSync

parent 8cc4cecc
No related branches found
No related tags found
No related merge requests found
......@@ -57,12 +57,13 @@ public class CollaborationManagerImpl extends BasicManager implements Collaborat
private CalendarManager calendarManager;
@Autowired
private BusinessGroupService businessGroupService;
@Override
public String getFolderRelPath(OLATResourceable ores) {
return "/cts/folders/" + ores.getResourceableTypeName() + "/" + ores.getResourceableId();
}
//fxdiff VCRP-8: collaboration tools folder access control
@Override
public Long lookupFolderAccess(OLATResourceable ores) {
StringBuilder query = new StringBuilder();
query.append("select prop.longValue from ").append(Property.class.getName()).append(" as prop where ")
......
......@@ -864,18 +864,18 @@ public class CollaborationTools implements Serializable {
*/
public void archive(String archivFilePath) {
if (isToolEnabled(CollaborationTools.TOOL_FORUM)) {
archiveForum(this.ores, archivFilePath);
archiveForum(archivFilePath);
}
if (isToolEnabled(CollaborationTools.TOOL_WIKI)) {
archiveWiki(this.ores, archivFilePath);
archiveWiki(archivFilePath);
}
if (isToolEnabled(CollaborationTools.TOOL_FOLDER)) {
archiveFolder(this.ores, archivFilePath);
archiveFolder(archivFilePath);
}
}
private void archiveForum(OLATResourceable formRes, String archivFilePath) {
Property forumKeyProperty = NarrowedPropertyManager.getInstance(formRes).findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
private void archiveForum(String archivFilePath) {
Property forumKeyProperty = NarrowedPropertyManager.getInstance(ores).findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
if (forumKeyProperty != null) {
VFSContainer archiveContainer = new LocalFolderImpl(new File(archivFilePath));
String archiveForumName = "del_forum_" + forumKeyProperty.getLongValue();
......@@ -885,10 +885,10 @@ public class CollaborationTools implements Serializable {
}
}
private void archiveWiki(OLATResourceable wikiRes, String archivFilePath) {
VFSContainer wikiContainer = WikiManager.getInstance().getWikiRootContainer(wikiRes);
private void archiveWiki(String archivFilePath) {
VFSContainer wikiContainer = WikiManager.getInstance().getWikiRootContainer(ores);
VFSLeaf wikiZip = WikiToZipUtils.getWikiAsZip(wikiContainer);
String exportFileName = "del_wiki_" + wikiRes.getResourceableId() + ".zip";
String exportFileName = "del_wiki_" + ores.getResourceableId() + ".zip";
File archiveDir = new File(archivFilePath);
if (!archiveDir.exists()) {
archiveDir.mkdir();
......@@ -898,17 +898,17 @@ public class CollaborationTools implements Serializable {
try {
FileUtils.bcopy(wikiZip.getInputStream(), new File(fullFilePath), "archive wiki");
} catch (FileNotFoundException e) {
log.warn("Can not archive wiki repoEntry=" + wikiRes.getResourceableId());
log.warn("Can not archive wiki repoEntry=" + ores.getResourceableId());
} catch (IOException ioe) {
log.warn("Can not archive wiki repoEntry=" + wikiRes.getResourceableId());
log.warn("Can not archive wiki repoEntry=" + ores.getResourceableId());
}
}
private void archiveFolder(OLATResourceable folderRes, String archiveFilePath) {
private void archiveFolder(String archiveFilePath) {
OlatRootFolderImpl folderContainer = new OlatRootFolderImpl(getFolderRelPath(), null);
File fFolderRoot = folderContainer.getBasefile();
if (fFolderRoot.exists()) {
String zipFileName = "del_folder_" + folderRes.getResourceableId() + ".zip";
String zipFileName = "del_folder_" + ores.getResourceableId() + ".zip";
String fullZipFilePath = archiveFilePath + File.separator + zipFileName;
ZipUtil.zipAll(fFolderRoot, new File(fullZipFilePath), true);
}
......
......@@ -37,7 +37,6 @@ import org.olat.core.logging.Tracing;
import org.olat.core.util.ArrayHelper;
import org.olat.core.util.cache.CacheWrapper;
import org.olat.core.util.coordinate.CoordinatorManager;
import org.olat.core.util.coordinate.SyncerCallback;
import org.olat.group.BusinessGroup;
import org.olat.instantMessaging.InstantMessagingModule;
import org.olat.modules.openmeetings.OpenMeetingsModule;
......@@ -72,6 +71,7 @@ public class CollaborationToolsFactory {
*/
private CollaborationToolsFactory(CoordinatorManager coordinatorManager) {
this.coordinatorManager = coordinatorManager;
cache = coordinatorManager.getCoordinator().getCacher().getCache(CollaborationToolsFactory.class.getSimpleName(), "tools");
instance = this;
}
......@@ -135,37 +135,33 @@ public class CollaborationToolsFactory {
*/
public CollaborationTools getOrCreateCollaborationTools(final BusinessGroup ores) {
if (ores == null) throw new AssertException("Null is not allowed here, you have to provide an existing ores here!");
final String cacheKey = Long.valueOf(ores.getResourceableId()).toString();
boolean debug = log.isDebug();
//sync operation cluster wide
//TODO gsync
return coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<CollaborationTools>() {
public CollaborationTools execute() {
if (cache == null) {
cache = coordinatorManager.getCoordinator().getCacher().getCache(CollaborationToolsFactory.class.getSimpleName(), "tools");
}
CollaborationTools collabTools = cache.get(cacheKey);
if (collabTools != null) {
if (log.isDebug()) log .debug("loading collabTool from cache. Ores: " + ores.getResourceableId());
if (collabTools.isDirty()) {
if (log.isDebug()) log .debug("CollabTools were in cache but dirty. Creating new ones. Ores: " + ores.getResourceableId());
CollaborationTools tools = new CollaborationTools(coordinatorManager, ores);
//update forces clusterwide invalidation of this object
cache.update(cacheKey, tools);
return tools;
}
return collabTools;
}
if (log.isDebug()) log .debug("collabTool not in cache. Creating new ones. Ores: " + ores.getResourceableId());
CollaborationTools collabTools = cache.get(cacheKey);
if (collabTools != null) {
if (debug) log .debug("loading collabTool from cache. Ores: " + ores.getResourceableId());
if (collabTools.isDirty()) {
if (debug) log .debug("CollabTools were in cache but dirty. Creating new ones. Ores: " + ores.getResourceableId());
CollaborationTools tools = new CollaborationTools(coordinatorManager, ores);
cache.put(cacheKey, tools);
return tools;
//update forces clusterwide invalidation of this object
cache.update(cacheKey, tools);
collabTools = tools;
}
} else {
if (debug) log .debug("collabTool not in cache. Creating new ones. Ores: " + ores.getResourceableId());
CollaborationTools tools = new CollaborationTools(coordinatorManager, ores);
CollaborationTools cachedTools = cache.putIfAbsent(cacheKey, tools);
if(cachedTools != null) {
collabTools = cachedTools;
} else {
collabTools = tools;
}
});
}
return collabTools;
}
/**
......
......@@ -3,15 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="collaborationToolsFactory" class="org.olat.collaboration.CollaborationToolsFactory"
depends-on="instantMessagingModule,baseSecurityModule,portfolioModule,openmeetingsModule">
<constructor-arg ref="coordinatorManager" />
</bean>
<bean id="collaborationToolsFactory" class="org.olat.collaboration.CollaborationToolsFactory"
depends-on="instantMessagingModule,baseSecurityModule,portfolioModule,openmeetingsModule">
<constructor-arg ref="coordinatorManager" />
</bean>
<bean id="collaborationManager" class="org.olat.collaboration.CollaborationManagerImpl"/>
<!-- TODO: add im property enabled here -->
<bean id="collaborationManager" class="org.olat.collaboration.CollaborationManagerImpl"/>
</beans>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment