Class CloudBasedIdGenerator

java.lang.Object
org.zkoss.stateless.ui.http.CloudBasedIdGenerator
All Implemented Interfaces:
IdGenerator

public class CloudBasedIdGenerator extends Object implements IdGenerator
A cloud based ID generator to avoid duplication uuid issue in a cloud mode.
Author:
jumperchen
  • Constructor Details

    • CloudBasedIdGenerator

      public CloudBasedIdGenerator(IdGenerator delegator)
  • Method Details

    • nextComponentUuid

      public String nextComponentUuid(Desktop desktop, Component comp, ComponentInfo compInfo)
      Description copied from interface: IdGenerator
      Returns the next component UUID for the specified component, or null to generate the default UUID.

      Default (if null is returned): UUID is generated by prefixing a portion of the desktop's ID with a number starting from 0.

      Notice that UUID cannot be empty and can only have alphanumeric characters or underscore (i.e., a-z, A-Z, 0-9, and _).

      This method is called when Component.getUuid() is called at the first time. It is usually when the component is attached to a page, unless the application invokes Component.getUuid() earlier.

      Specified by:
      nextComponentUuid in interface IdGenerator
      Parameters:
      desktop - the current desktop (never null)
      comp - the component (never null)
      compInfo - the information about the properties specified in the ZUML document, null if the component is instantiated manually.
      Returns:
      the next component UUID, or null to generate the
    • nextAnonymousComponentUuid

      public String nextAnonymousComponentUuid(Component comp, ComponentInfo compInfo)
      Description copied from interface: IdGenerator
      Returns the next anonymous component UUID for the specified component, or null to generate the default UUID.

      Unlike IdGenerator.nextComponentUuid(Desktop, Component, ComponentInfo), this uuid is not belonged to any desktop scope, but application or clustering environment scope. A typical usage is for Stateless component application in Cloud mode and the generated uuid must be an unique id among the clustering servers environment.

      Default (if null is returned): UUID is generated by prefixing a portion of the "z__i" ID with a number starting from 0. (The implementation is the same as before ZK 10.)

      Specified by:
      nextAnonymousComponentUuid in interface IdGenerator
      Parameters:
      comp - the component (never null)
      compInfo - the information about the properties specified in the ZUML document, null if the component is instantiated manually.
      Returns:
      the next component UUID, or null to generate the
    • nextPageUuid

      public String nextPageUuid(Page page)
      Description copied from interface: IdGenerator
      Returns the next page UUID for the specified page, or null to generate the default UUID.

      Default (if null is returned): UUID is generated by prefixing a portion of the desktop's ID with a number starting from 0.

      Notice that UUID cannot be empty and can only have alphanumeric characters or underscore (i.e., a-z, A-Z, 0-9, and _). In additions, UUID for pages cannot be the same as UUID for components.

      Also notice that the execution can be retrieved by use of Executions.getCurrent().

      Specified by:
      nextPageUuid in interface IdGenerator
      Returns:
      the next page UUID, or null to generate the default UUID.
    • nextDesktopId

      public String nextDesktopId(Desktop desktop)
      Description copied from interface: IdGenerator
      Returns the next desktop ID for the specified desktop, or null to generate the default ID.

      Default (if null is returned): ID is generated randomly. In other words, the desktop's ID, by default, is not deterministic. To have a deterministic value, you have to implement this method.

      Notice that UUID cannot be empty and can only have alphanumeric characters or underscore (i.e., a-z, A-Z, 0-9, and _).

      Also notice that we can retrieve the execution by use of Desktop.getExecution(), or Executions.getCurrent().

      Specified by:
      nextDesktopId in interface IdGenerator
      Returns:
      the next desktop ID, or null to generate the default ID.