Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
e728798a
Commit
e728798a
authored
10 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-990: use putIfAbsent to fill the course cache instead of doInSync
parent
344b0d45
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/olat/course/CourseFactory.java
+20
-46
20 additions, 46 deletions
src/main/java/org/olat/course/CourseFactory.java
with
20 additions
and
46 deletions
src/main/java/org/olat/course/CourseFactory.java
+
20
−
46
View file @
e728798a
...
@@ -88,7 +88,6 @@ import org.olat.core.util.WebappHelper;
...
@@ -88,7 +88,6 @@ import org.olat.core.util.WebappHelper;
import
org.olat.core.util.ZipUtil
;
import
org.olat.core.util.ZipUtil
;
import
org.olat.core.util.cache.CacheWrapper
;
import
org.olat.core.util.cache.CacheWrapper
;
import
org.olat.core.util.coordinate.CoordinatorManager
;
import
org.olat.core.util.coordinate.CoordinatorManager
;
import
org.olat.core.util.coordinate.SyncerCallback
;
import
org.olat.core.util.coordinate.SyncerExecutor
;
import
org.olat.core.util.coordinate.SyncerExecutor
;
import
org.olat.core.util.event.MultiUserEvent
;
import
org.olat.core.util.event.MultiUserEvent
;
import
org.olat.core.util.nodes.INode
;
import
org.olat.core.util.nodes.INode
;
...
@@ -257,7 +256,7 @@ public class CourseFactory extends BasicManager {
...
@@ -257,7 +256,7 @@ public class CourseFactory extends BasicManager {
public
static
ICourse
createEmptyCourse
(
OLATResourceable
ores
,
String
shortTitle
,
String
longTitle
,
String
learningObjectives
)
{
public
static
ICourse
createEmptyCourse
(
OLATResourceable
ores
,
String
shortTitle
,
String
longTitle
,
String
learningObjectives
)
{
PersistingCourseImpl
newCourse
=
new
PersistingCourseImpl
(
ores
.
getResourceableId
());
PersistingCourseImpl
newCourse
=
new
PersistingCourseImpl
(
ores
.
getResourceableId
());
// Put new course in course cache
// Put new course in course cache
putCourseInCache
(
newCourse
.
getResourceableId
()
,
newCourse
);
loadedCourses
.
put
(
newCourse
.
getResourceableId
()
,
newCourse
);
Structure
initialStructure
=
new
Structure
();
Structure
initialStructure
=
new
Structure
();
CourseNode
runRootNode
=
new
STCourseNode
();
CourseNode
runRootNode
=
new
STCourseNode
();
...
@@ -286,25 +285,20 @@ public class CourseFactory extends BasicManager {
...
@@ -286,25 +285,20 @@ public class CourseFactory extends BasicManager {
*/
*/
public
static
ICourse
loadCourse
(
final
Long
resourceableId
)
{
public
static
ICourse
loadCourse
(
final
Long
resourceableId
)
{
if
(
resourceableId
==
null
)
throw
new
AssertException
(
"No resourceable ID found."
);
if
(
resourceableId
==
null
)
throw
new
AssertException
(
"No resourceable ID found."
);
PersistingCourseImpl
course
=
getCourseFromCache
(
resourceableId
);
PersistingCourseImpl
course
=
loadedCourses
.
get
(
resourceableId
);
if
(
course
==
null
)
{
if
(
course
==
null
)
{
// o_clusterOK by:ld - load and put in cache in doInSync block to ensure
// o_clusterOK by:ld - load and put in cache in doInSync block to ensure
// that no invalidate cache event was missed
// that no invalidate cache event was missed
if
(
log
.
isDebug
())
log
.
debug
(
"try to load course with resourceableId="
+
resourceableId
);
PersistingCourseImpl
theCourse
=
new
PersistingCourseImpl
(
resourceableId
);
OLATResourceable
courseResourceable
=
OresHelper
.
createOLATResourceableInstance
(
PersistingCourseImpl
.
class
,
resourceableId
);
theCourse
.
load
();
course
=
CoordinatorManager
.
getInstance
().
getCoordinator
().
getSyncer
().
doInSync
(
courseResourceable
,
new
SyncerCallback
<
PersistingCourseImpl
>()
{
public
PersistingCourseImpl
execute
()
{
PersistingCourseImpl
cachedCourse
=
loadedCourses
.
putIfAbsent
(
resourceableId
,
theCourse
);
PersistingCourseImpl
theCourse
=
getCourseFromCache
(
resourceableId
);
if
(
cachedCourse
!=
null
)
{
if
(
theCourse
==
null
)
{
course
=
cachedCourse
;
theCourse
=
new
PersistingCourseImpl
(
resourceableId
);
}
else
{
theCourse
.
load
();
course
=
theCourse
;
putCourseInCache
(
resourceableId
,
theCourse
);
}
}
return
theCourse
;
}
});
}
}
return
course
;
return
course
;
}
}
...
@@ -318,25 +312,6 @@ public class CourseFactory extends BasicManager {
...
@@ -318,25 +312,6 @@ public class CourseFactory extends BasicManager {
Long
resourceableId
=
olatResource
.
getResourceableId
();
Long
resourceableId
=
olatResource
.
getResourceableId
();
return
loadCourse
(
resourceableId
);
return
loadCourse
(
resourceableId
);
}
}
/**
*
* @param resourceableId
* @return the PersistingCourseImpl instance for the input key.
*/
static
PersistingCourseImpl
getCourseFromCache
(
Long
resourceableId
)
{
//o_clusterOK by:ld
return
loadedCourses
.
get
(
resourceableId
);
}
/**
* Puts silent.
* @param resourceableId
* @param course
*/
static
void
putCourseInCache
(
Long
resourceableId
,
PersistingCourseImpl
course
)
{
//o_clusterOK by:ld
loadedCourses
.
put
(
resourceableId
,
course
);
log
.
debug
(
"putCourseInCache "
);
}
/**
/**
*
*
...
@@ -584,7 +559,7 @@ public class CourseFactory extends BasicManager {
...
@@ -584,7 +559,7 @@ public class CourseFactory extends BasicManager {
CourseConfig
cc
=
CourseConfigManagerImpl
.
getInstance
().
loadConfigFor
(
newCourse
);
CourseConfig
cc
=
CourseConfigManagerImpl
.
getInstance
().
loadConfigFor
(
newCourse
);
//newCourse is not in cache yet, so we cannot call setCourseConfig()
//newCourse is not in cache yet, so we cannot call setCourseConfig()
newCourse
.
setCourseConfig
(
cc
);
newCourse
.
setCourseConfig
(
cc
);
putCourseInCache
(
newCourse
.
getResourceableId
(),
newCourse
);
loadedCourses
.
put
(
newCourse
.
getResourceableId
(),
newCourse
);
return
newCourse
;
return
newCourse
;
}
catch
(
AssertException
ae
)
{
}
catch
(
AssertException
ae
)
{
// ok failed, cleanup below
// ok failed, cleanup below
...
@@ -968,13 +943,13 @@ public class CourseFactory extends BasicManager {
...
@@ -968,13 +943,13 @@ public class CourseFactory extends BasicManager {
public
void
execute
()
{
public
void
execute
()
{
final
PersistingCourseImpl
course
=
getCourseEditSession
(
resourceableId
);
final
PersistingCourseImpl
course
=
getCourseEditSession
(
resourceableId
);
if
(
course
!=
null
&&
course
.
isReadAndWrite
())
{
if
(
course
!=
null
&&
course
.
isReadAndWrite
())
{
course
.
initHasAssessableNodes
();
course
.
initHasAssessableNodes
();
course
.
saveRunStructure
();
course
.
saveRunStructure
();
course
.
saveEditorTreeModel
();
course
.
saveEditorTreeModel
();
//clear modifyCourseEvents at publish, since the updateCourseInCache is called anyway
//clear modifyCourseEvents at publish, since the updateCourseInCache is called anyway
modifyCourseEvents
.
remove
(
resourceableId
);
modifyCourseEvents
.
remove
(
resourceableId
);
updateCourseInCache
(
resourceableId
,
course
);
updateCourseInCache
(
resourceableId
,
course
);
}
else
if
(!
course
.
isReadAndWrite
())
{
}
else
if
(!
course
.
isReadAndWrite
())
{
throw
new
AssertException
(
"Cannot saveCourse because theCourse is readOnly! You have to open an courseEditSession first!"
);
throw
new
AssertException
(
"Cannot saveCourse because theCourse is readOnly! You have to open an courseEditSession first!"
);
}
}
...
@@ -1083,9 +1058,8 @@ public class CourseFactory extends BasicManager {
...
@@ -1083,9 +1058,8 @@ public class CourseFactory extends BasicManager {
public
void
execute
()
{
public
void
execute
()
{
PersistingCourseImpl
course
=
getCourseEditSession
(
resourceableId
);
PersistingCourseImpl
course
=
getCourseEditSession
(
resourceableId
);
if
(
course
!=
null
)
{
if
(
course
!=
null
)
{
course
.
setCourseConfig
(
cc
);
course
.
setCourseConfig
(
cc
);
updateCourseInCache
(
resourceableId
,
course
);
updateCourseInCache
(
resourceableId
,
course
);
}
}
}
}
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment