use of org.olat.core.util.coordinate.SyncerCallback in project openolat by klemens.
the class CoordinatorTest method testNestedAssertExceptionInDoInSync.
@Test(expected = AssertException.class)
public void testNestedAssertExceptionInDoInSync() {
final OLATResourceable ores = OresHelper.createOLATResourceableInstance("testNestedAssertExceptionInDoInSync", new Long("123"));
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<Boolean>() {
public Boolean execute() {
log.info("testNestedAssertExceptionInDoInSync: execute doInSync 1");
// Do agin in sync => nested => no allowed!
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<Boolean>() {
public Boolean execute() {
log.info("testNestedAssertExceptionInDoInSync: execute doInSync 2");
fail("No NestedAssertException thrown");
return Boolean.TRUE;
}
});
return Boolean.TRUE;
}
});
// end syncerCallback
}
use of org.olat.core.util.coordinate.SyncerCallback in project openolat by klemens.
the class FileResourceManager method unzipFileResource.
private final File unzipFileResource(final OLATResourceable res, final File dir) {
if (!dir.exists()) {
return null;
}
File zipTargetDir = new File(dir, ZIPDIR);
if (!zipTargetDir.exists()) {
// if not unzipped yet, synchronize all unzipping processes
// o_clusterOK by:ld
zipTargetDir = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(res, new SyncerCallback<File>() {
public File execute() {
File targetDir = null;
// now we are the only one unzipping. We
// only need to unzip when the previous
// threads that aquired this lock have not unzipped "our" version's
// resources yet
targetDir = new File(dir, ZIPDIR);
if (!targetDir.exists()) {
// means I am the first to unzip this
// version's resource
targetDir.mkdir();
File zipFile = getFileResource(res);
if (!ZipUtil.unzip(zipFile, targetDir)) {
return null;
}
}
return targetDir;
}
});
}
return zipTargetDir;
}
use of org.olat.core.util.coordinate.SyncerCallback in project OpenOLAT by OpenOLAT.
the class CollaborationTools method getForum.
public Forum getForum() {
final ForumManager fom = ForumManager.getInstance();
final NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
Property forumProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
Forum forum;
if (forumProperty != null) {
forum = fom.loadForum(forumProperty.getLongValue());
} else {
forum = coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<Forum>() {
@Override
public Forum execute() {
Forum aforum;
Long forumKey;
Property forumKeyProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
if (forumKeyProperty == null) {
// First call of forum, create new forum and save
aforum = fom.addAForum();
forumKey = aforum.getKey();
if (log.isDebug()) {
log.debug("created new forum in collab tools: foid::" + forumKey.longValue() + " for ores::" + ores.getResourceableTypeName() + "/" + ores.getResourceableId());
}
forumKeyProperty = npm.createPropertyInstance(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM, null, forumKey, null, null);
npm.saveProperty(forumKeyProperty);
} else {
// Forum does already exist, load forum with key from properties
forumKey = forumKeyProperty.getLongValue();
aforum = fom.loadForum(forumKey);
if (aforum == null) {
throw new AssertException("Unable to load forum with key " + forumKey.longValue() + " for ores " + ores.getResourceableTypeName() + " with key " + ores.getResourceableId());
}
if (log.isDebug()) {
log.debug("loading forum in collab tools from properties: foid::" + forumKey.longValue() + " for ores::" + ores.getResourceableTypeName() + "/" + ores.getResourceableId());
}
}
return aforum;
}
});
}
return forum;
}
Aggregations