Class GUIDHelper

java.lang.Object
com.tangosol.persistence.GUIDHelper

public class GUIDHelper extends Object
Static helper methods to encode and decode the attributes related to the storage of a persistent form of a partition.

A persistence GUID must at minimum reflect the partition-id and a monotonically increasing partition-version that could be used to determine, given a set of GUIDs representing the same partition, a total ordering of the GUIDs over time.

Author:
rhl/jh 2012.07.06
  • Constructor Details

    • GUIDHelper

      public GUIDHelper()
  • Method Details

    • generateGUID

      public static String generateGUID(int nPartition, long lVersion, long ldt, Member member)
      Generate and return a new GUID for the specified partition.
      Parameters:
      nPartition - the partition to return a GUID for
      lVersion - the creation version of the partition
      ldt - the creation timestamp; informational only
      member - the member generating the GUID; informational only
      Returns:
      a new GUID for the specified partition
    • validateGUID

      public static boolean validateGUID(String sGUID)
      Validate the given GUID.
      Parameters:
      sGUID - the GUID to validate
      Returns:
      true if the specified GUID is valid; false otherwise
    • getPartition

      public static int getPartition(String sGUID)
      Parse the specified GUID and return the partition-id.
      Parameters:
      sGUID - the GUID to return the partition-id for
      Returns:
      the partition-id
    • getVersion

      public static long getVersion(String sGUID)
      Parse the specified GUID and return the partition-version.
      Parameters:
      sGUID - the GUID to return the partition-version for
      Returns:
      the partition-version
    • getServiceJoinTime

      public static long getServiceJoinTime(String sGUID)
      Parse the specified GUID and return the service join time.
      Parameters:
      sGUID - the GUID used to return the service join time
      Returns:
      the service join
    • getMemberId

      public static int getMemberId(String sGUID)
      Parse the specified GUID and return the originating member-id.
      Parameters:
      sGUID - the GUID to return the originating member-id for
      Returns:
      the originating member-id
    • getGUID

      public static String getGUID(List<String> listGUID, int nPartition)
      Return GUID in the specified list of GUIDs for the specified partition.
      Parameters:
      listGUID - the list of GUIDs
      nPartition - the partition
      Returns:
      GUID for the specified partition
    • resolveNewest

      @Deprecated public static String[] resolveNewest(Collection<String> colGUID, int cPartitions)
      Deprecated.
      Return a list of the newest GUID for each partition, indexed by the partition-id.
      Parameters:
      colGUID - the collection of GUIDs to resolve
      cPartitions - the partition-count
      Returns:
      a list of the newest GUID for each partition
    • resolveNewest

      protected static String[] resolveNewest(Map<Member,String[]> mapGUID, Set<String> setPrevGUIDs, int cPartitions)
      Return an array of the newest GUID for each partition, indexed by the partition-id and collect previous GUIDs into the provided set.
      Parameters:
      mapGUID - the map of GUIDs to resolve
      setPrevGUIDs - the set that holds old GUIDs
      cPartitions - the partition-count
      Returns:
      an array of the newest GUID for each partition
    • evaluateGUID

      protected static void evaluateGUID(String sGUID, String[] asGUIDNewest, Set<String> setPrevGUIDs, int cPartitions)
      Evaluate the provided GUID ensuring asGUIDNewest references the latest and setPrevGUIDs references previous GUIDs.
      Parameters:
      sGUID - the GUID to be evaluated
      asGUIDNewest - the array that contains the newest GUIDs
      setPrevGUIDs - the set that contains the old GUIDs
      cPartitions - the partition-count
    • assignStores

      public static Map<Integer,String[]> assignStores(Map<Integer,Object[]> mapConstraints, int cDistinctStores)
      Return a Map containing assignments of member id to stores based on the given constraints.

      The algorithm will attempt to fairly distribute assignment of stores across members while abiding to the given constraints. For example:

      Member constraints and assignments
      Member IdConstraintsAssignments
      1{a,b,c,d}{a,c}
      2{a,b,c,d}{b,d}
      3{e,f,g,h}{e,g}
      4{e,f,g,h}{f,h}
      Parameters:
      mapConstraints - the constraints to perform assignments within
      cDistinctStores - the number of expected distinct stores
      Returns:
      a Map containing assignments of member id to stores based on the given constraints
    • getPartitions

      public static PartitionSet getPartitions(Map<Integer,Object[]> mapStores, int cParts)
      Return a PartitionSet with all partitions present in the provided mapStores.
      Parameters:
      mapStores - a Map of member id to stores
      cParts - the partition count
      Returns:
      a PartitionSet with all partitions present in the provided mapStores
    • parseAttribute

      protected static String parseAttribute(String sGUID, int id)
      Return the specified (0-based) attribute from the GUID.
      Parameters:
      sGUID - the GUID
      id - the (0-based) attribute index
      Returns:
      the GUID attribute
    • intersects

      protected static List<String> intersects(Object[] aoLHS, Object[] aoRHS)
      Return a List of stores (GUIDs) that allows the caller to derive whether the provided sets are disjoint, intersect or equal. These three states can be derived as follows:
      States
      ResultReason
      nulldisjoint sets
      listReturnshared elements across LHS and RHS
      listReturn.size() == aoLHS.length == aoRHS.lengthLHS and RHS are equal
      Parameters:
      aoLHS - the first set in the comparison
      aoRHS - the second set in the comparison
      Returns:
      a List of stores that allows the caller to derive whether the provided sets are disjoint, intersect or equal
    • createSortedEntries

      protected static <K> Map.Entry<K,Object[]>[] createSortedEntries(Map<K,Object[]> map)
      Return an array of entries based on the provided map ensuring the value (Object array) is sorted.
      Type Parameters:
      K - - the key type
      Parameters:
      map - a map to base the Entry[] on
      Returns:
      an array of entries ensuring the value (Object array) is sorted
    • main

      public static void main(String[] asArg)
      Utility that outputs information about a given GUID.
      Usage: com.tangosol.persistence.GUIDHelper <GUID>
      Parameters:
      asArg - command line arguments