Class PortletWindowStorage

java.lang.Object
io.meeds.appcenter.storage.PortletWindowStorage

@Component public class PortletWindowStorage extends Object
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 Details

    • TIMEOUT_SECONDS

      public static final long TIMEOUT_SECONDS
      Longest 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

      public Map<String,String> getPreferences(String storageId)
      Parameters:
      storageId - the window's storage id
      Returns:
      the window's preferences as committed, by name, empty when the window does not exist
    • exists

      public boolean exists(String storageId)
      Parameters:
      storageId - the window's storage id
      Returns:
      true when the window exists as committed
    • savePreferences

      public void savePreferences(String storageId, Map<String,String> values)
      Sets preferences of a window over its committed ones, the others kept. When the wait ends with a WindowPreferencesTimeoutException, the write still runs, and is committed unless it fails.
      Parameters:
      storageId - the window's storage id
      values - the preferences to set, by name
    • getOrSetPreference

      public String getOrSetPreference(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.
      Parameters:
      storageId - the window's storage id
      name - the preference name
      value - the value to set when the window holds none
      Returns:
      the value the window holds once done
    • callOnWindow

      public <T> T callOnWindow(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. The task runs to its end whether the caller still waits or not; onEnd runs once it ended, whatever its outcome, or at once when it could not be queued.
      Parameters:
      storageId - the window's storage id
      task - the task, given the window's committed preferences
      onEnd - 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

      public <T> T callInRequest(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.
    • stop

      @PreDestroy public void stop()