Package io.meeds.appcenter.storage
Class PortletWindowStorage
java.lang.Object
io.meeds.appcenter.storage.PortletWindowStorage
The preferences of a portlet window as committed. A portal request reads a
window through an entity manager it keeps for its whole duration, which
returns the window as that request first loaded it, whatever another
request committed since; the layout service's preferences cache is filled
through the entity manager of the request that misses it, so it can hold
such a view too. This storage reads the window through the layout service's
reads of its row (
LayoutService.loadCommitted(String),
LayoutService.existsCommitted(String)), never through that cache,
on a thread of its own, in a request of its own, so that no
transaction of its caller decides what the read sees, and writes the
preferences column alone (LayoutService.saveCommitted(java.lang.String, org.exoplatform.portal.pom.spi.portlet.Portlet)), which
empties the window's cache entry and leaves the window's other columns as
committed. Each
read-modify-write holds a lock of this node per window on that thread,
from its read to its committed write, so that a caller who stops waiting
never lets another write run over it.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longLongest wait for a read or a write of a window's preferences, its time queued included. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TcallInRequest(Supplier<T> task) Runs a task in a request of its own: called on a thread of this storage, where no request is running, it gets its own entity manager.<T> TcallOnWindow(String storageId, Function<PortletWindow, T> task, Runnable onEnd) Runs a task on a window's preferences as one task of the storage thread, in a request of its own, holding the window's lock from its first read to its last write, and waits for it.booleangetOrSetPreference(String storageId, String name, String value) Reads a preference of a window, and sets it when the window holds no value for it, in one read-modify-write.getPreferences(String storageId) voidsavePreferences(String storageId, Map<String, String> values) Sets preferences of a window over its committed ones, the others kept.voidstop()
-
Field Details
-
TIMEOUT_SECONDS
public static final long TIMEOUT_SECONDSLongest wait for a read or a write of a window's preferences, its time queued included.- See Also:
-
-
Constructor Details
-
PortletWindowStorage
public PortletWindowStorage()
-
-
Method Details
-
getPreferences
- Parameters:
storageId- the window's storage id- Returns:
- the window's preferences as committed, by name, empty when the window does not exist
-
exists
- Parameters:
storageId- the window's storage id- Returns:
- true when the window exists as committed
-
savePreferences
Sets preferences of a window over its committed ones, the others kept. When the wait ends with aWindowPreferencesTimeoutException, the write still runs, and is committed unless it fails.- Parameters:
storageId- the window's storage idvalues- the preferences to set, by name
-
getOrSetPreference
Reads a preference of a window, and sets it when the window holds no value for it, in one read-modify-write.- Parameters:
storageId- the window's storage idname- the preference namevalue- the value to set when the window holds none- Returns:
- the value the window holds once done
-
callOnWindow
Runs a task on a window's preferences as one task of the storage thread, in a request of its own, holding the window's lock from its first read to its last write, and waits for it. The task runs to its end whether the caller still waits or not;onEndruns once it ended, whatever its outcome, or at once when it could not be queued.- Parameters:
storageId- the window's storage idtask- the task, given the window's committed preferencesonEnd- run once the task ended, null for nothing- Returns:
- what the task returns
- Throws:
WindowPreferencesTimeoutException- when the caller stops waiting, the task still running
-
callInRequest
Runs a task in a request of its own: called on a thread of this storage, where no request is running, it gets its own entity manager. -
stop
@PreDestroy public void stop()
-