Skip to content

Commit 83603ff

Browse files
Lock the checked out page instance during component action handling
1 parent 64731f8 commit 83603ff

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

ng-appserver/src/main/java/ng/appserver/NGComponentRequestHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ else if( actionInvocationResults instanceof NGComponent newPage ) {
121121
throw new IllegalStateException( "Response is null. This should never happen" );
122122
}
123123

124+
// FIXME: If we have a checked out page instance, we probably need to release the lock in a finally clause // Hugi 2025-04-06
125+
session.pageCache().releaseLock( originatingContextID );
126+
124127
return response;
125128
}
126129

ng-appserver/src/main/java/ng/appserver/NGPageCache.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.HashMap;
44
import java.util.LinkedHashMap;
55
import java.util.Map;
6+
import java.util.concurrent.locks.Lock;
7+
import java.util.concurrent.locks.ReentrantLock;
68

79
import org.slf4j.Logger;
810
import org.slf4j.LoggerFactory;
@@ -24,10 +26,10 @@ public class NGPageCache {
2426
* Represents a single entry in the page cache, along with it's "child entries"
2527
* "Child entries" currently means entries generated for update containers within the same page, meaning they can be thrown out with their parent.
2628
*/
27-
public record NGPageCacheEntry( String contextID, NGComponent page, String originatingContextID, String updateContainerID, NGPageCacheEntry parent, Map<String, NGPageCacheEntry> children ) {
29+
public record NGPageCacheEntry( String contextID, NGComponent page, String originatingContextID, String updateContainerID, NGPageCacheEntry parent, Map<String, NGPageCacheEntry> children, Lock lock ) {
2830

2931
public NGPageCacheEntry( String contextID, NGComponent page, String originatingContextID, NGPageCacheEntry parent, String updateContainerID ) {
30-
this( contextID, page, originatingContextID, updateContainerID, parent, new LinkedHashMap<>() );
32+
this( contextID, page, originatingContextID, updateContainerID, parent, new LinkedHashMap<>(), new ReentrantLock() );
3133
}
3234

3335
/**
@@ -146,9 +148,19 @@ public NGComponent restorePageFromCache( final String contextID ) {
146148
throw new NGPageRestorationException( "No page found in the page cache for contextID '%s'. The page has probably been pushed out of the session's page cache".formatted( contextID ) );
147149
}
148150

151+
cacheEntry.lock().lock();
149152
return cacheEntry.page();
150153
}
151154

155+
/**
156+
* Release the lock on the context.
157+
*
158+
* FIXME: Locking in the page cache is still very experimental functionality. Needs testing // Hugi 2025-04-06
159+
*/
160+
public void releaseLock( final String contextID ) {
161+
_allEntries.get( contextID ).lock().unlock();
162+
}
163+
152164
/**
153165
* In the case of a full page update, moves the entry to the top of the page cache.
154166
* In the case of a partial update, moves the parent entry to the top of the page cache.

0 commit comments

Comments
 (0)