Class JSpaceUtilities

java.lang.Object
com.j_spaces.kernel.JSpaceUtilities

public class JSpaceUtilities extends Object
JSpaceUtility class provides useful GigaSpaces utility functions.
Version:
1.0
Author:
Igor Goldenbeg
  • Field Details

  • Constructor Details

    • JSpaceUtilities

      public JSpaceUtilities()
  • Method Details

    • domWriter

      public static boolean domWriter(Node node, PrintStream ps, String prefix)
      Order all XML tags of DOM tree and writes XML DOM tree to OutputStream. For example DOM tree looks like this: value After domWriter function DOM tree will look like this: value
      Parameters:
      node - XML DOM tree.
      ps - OutputStream it's can be FileOutputStream, System.out
      prefix - Number of space between tags
      Returns:
      true if the node is a value node, false otherwise true
      See Also:
    • createContainerPresentName

      public static String createContainerPresentName(String hostName, String containerName)
      This method constructs name for container representation. Actually it concatenates host name with container name.
      Parameters:
      hostName - host name
      containerName - container name
      Returns:
      representation name
    • parseBooleanTag

      public static boolean parseBooleanTag(String tag, String s)
      Parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null, is not a sys-property, and is equal, ignoring case, to the string "true".
      Parameters:
      tag - the xml-tag containing the boolean
      s - the String containing the boolean representation to be parsed
      Returns:
      the boolean represented by the string argument
      Throws:
      IllegalArgumentException - if the string does not contain a parsable boolean.
    • parseBooleanTag

      public static boolean parseBooleanTag(String tag, String s, boolean defaultValue)
      Parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null, is not a sys-property, and is equal, ignoring case, to the string "true".
      Parameters:
      tag - the xml-tag containing the boolean
      s - the String containing the boolean representation to be parsed
      defaultValue - the default value if property is not defined
      Returns:
      the boolean represented by the string argument
      Throws:
      IllegalArgumentException - if the string does not contain a parsable boolean.
    • normalize

      public static void normalize(Node node)
      Normalize DOM tree. Remove all white spaces between tags. for example: value Normalize to value
      Parameters:
      node - Dom tree.
      See Also:
    • convertDOMTreeFromSystemProperty

      public static void convertDOMTreeFromSystemProperty(Node node)
      Converts recursively entire DOM tree values from System Property to value. For example let's assume that defined the following System Property: System.setProperty("com.gs.home", "d:/GigaSpaces4.0"); ${com.gs.home}/igor/logs After invoking this method: d:/GigaSpaces4.0/igor/logs if no System Property defined as part of Node value, the value stay untouchable.
      Parameters:
      node - Dom tree.
      See Also:
    • convertToClusterConfiguration

      public static Document convertToClusterConfiguration(Document clusterXMLDomElement, InputStream clusterXSLPolicy) throws IOException, TransformerConfigurationException, TransformerException, ParserConfigurationException, SAXException
      Method which gets cluster xml Dom element and cluster xsl schema input stream. It calls the XSLT converter which produces a full cluster configuration Dom document.
      Returns:
      a full cluster configuration Dom document.
      Throws:
      SAXException - in case an xsd validation fails for some reason
      IOException
      TransformerConfigurationException
      TransformerException
      ParserConfigurationException
    • overrideClusterConfigWithXPath

      public static Document overrideClusterConfigWithXPath(String xpath, String newValue, Document clusterConfigRootDoc) throws Exception
      A method which overrides cluster configuration xml using a XPath key/value pair passed through custom properties. It gets an xml XPath key and using an XPathAPI it attempts to find the relevant DOM node. If it was found it sets a new value. Although its a general method, its used in the context of the cluster configuration override. Supporting both the standard XPath using / as well as "our" XPath standard using dots: -------------------------------------------------------------------------------------- If user passed "real" full XPath, starting with / we pass it as is to the XPathAPI That enables also to support advanced XPath queries according to the spec If user passed a dot ("our" XPath like), e.g. cluster-config.groups.group etc. then we change it to be a standard xpath replacing dots with /
      Parameters:
      xpath - a XPath string such as /cluster-config/groups/group/load-bal-policy/proxy-broadcast-threadpool-min-size while in the custom properties we pass it using a dot e.g.: cluster-config.groups.group.load-bal-policy.proxy-broadcast-threadpool-min-size=33
      Returns:
      same xml DOM but after overwriting all elements using the XPaths new values
      Throws:
      Exception - in case org.apache.xpath.XPathAPI is not found or TransformerException in case error during transformation process.
    • overrideClusterConfigWithXPath

      public static Document overrideClusterConfigWithXPath(Properties customProps, Document clusterConfigRootDoc) throws Exception
      Returns:
      same xml DOM but after overwriting all elements using the XPaths new values
      Throws:
      Exception
    • buildClusterXMLDom

      public static Document buildClusterXMLDom(int _totalMembers, int _backupMembers, String _clusterSchemaName, String _clusterName, String _distCacheConfigName, String _groups) throws ParserConfigurationException
      Builds a schema cluster config xml file on the fly, using several inputs. The xml Dom file which is built, is later used as input to the XSLT processor (which is using it, together with cluster xsl schema file, and produces xml config file full structure, used in the ClusterXML.java)
      Parameters:
      _totalMembers - The number of space/cache nodes/spaces in this cluster. The format of the total_members={number of primary instances, number of backup instances per primary} If ?total_members=4,2 the value is 4,2 means that this cluster contains up to 4 primary instances each containing 2 backup instances.
      _backupMembers - stands for the SpaceURL backups part of the ?total_numbers option, total_members={number of primary instances, number of backup instances per primary} In this example the value is 4,2 which means that this cluster contains up to 4 primary instances each containing 2 backup instances..
      _clusterSchemaName - The cluster schema XSL file to be used to be build the cluster XML Dom.
      _clusterName - Used also as the cache name.
      Returns:
      a DOM Document object of the cluster-config sub tree
      Throws:
      ParserConfigurationException
      See Also:
      • com.j_spaces.tools.xslt.XSLTConverter
      • com.j_spaces.core.cluster.ClusterXML
    • setXMLImplSystemProps

      public static void setXMLImplSystemProps()
      Setting the XML parser and converter implementations. We use xerces parser and xalan XSLT transformer implementations Make sure the xercesImpl.jar and xalan.jar files are defined in the classpath. We check if this setting needs to be forcibly executed. If sys prop -Dcom.gs.dont-use-default-xml-parser=true it forces setting these implementations. In such case the system will use the fallback implementation of the JDK. 19.12.05 - Gershon: We no longer force by DEFAULT the xerces and xalan implementations and this sys prop setting is kept only for specific scenarios where the currently used implementation does not support the Transformation and parsing needs. In such case you may pass the -Dcom.gs.dont-use-default-xml-parser=true system property to force setting these implementations. In such case the system will use the fallback implementation of the JDK (if no -Xbootclasspath was set either). NOTE that sys prop was initially called com.gs.use-default-xml-parser.
    • replaceInString

      public static String replaceInString(String content, String oldStr, String newStr, boolean replaceAll)
      Replace the desired string in all content string. This method ignoring Case Sensitive. For example: String content = "Hello World Hello World say Igor 1000 times"; String replStr = replaceInString(content,"Hello", "I Love", true); Output ==> "I Love I Love say Igor 1000 times"
      Parameters:
      content - The content string where will be executing replacing.
      oldStr - The string which should find in content and replace.
      newStr - The string which will be replaced with old string.
      replaceAll - true if replace in all content, false the replace will be executed only one time.
      Returns:
      Returns the replaced content or the original content if was nothing replaced.
    • getStackTrace

      public static String getStackTrace(Throwable t)
      Converts the stack trace of the specified exception to a string. NOTE: Pass the exception as an argument to the external exception
    • getCallStackTraces

      public static String getCallStackTraces(int deep)
    • getPropertiesPresentation

      public static String getPropertiesPresentation(Properties props)
    • getCauseExceptionMessageFromHierarchy

      public static String getCauseExceptionMessageFromHierarchy(Exception sourceException, Class checkCauseExceptionClass)
      This method checks whole hierarchy for the exception cause. If it finds the exception of specific class, method returns exception message if exists such one otherwise null returned.
      Parameters:
      sourceException - hierarchy of cause exception belongs to this exception will be checked
      checkCauseExceptionClass - Class instance
      Returns:
      if there is exception of specific class in exception hierarchy its message will be returned, otherwise null returned
    • getCauseExceptionFromHierarchy

      public static Throwable getCauseExceptionFromHierarchy(Throwable sourceException, Class checkCauseExceptionClass)
      This method checks whole hierarchy for the exception cause. If it finds the exception of specific class, method returns this exception if exists such one otherwise null returned.
      Parameters:
      sourceException - hierarchy of cause exception belongs to this exception will be checked
      checkCauseExceptionClass - Class instance
      Returns:
      if there is exception of specific class in exception hierarchy it will be returned, otherwise null returned
    • getAssignableCauseExceptionFromHierarchy

      public static Throwable getAssignableCauseExceptionFromHierarchy(Exception sourceException, Class checkCauseExceptionClass)
    • getRootCauseException

      public static Throwable getRootCauseException(Throwable sourceException)
    • isSameException

      public static boolean isSameException(Throwable exception1, Throwable exception2)
    • isEmpty

      public static boolean isEmpty(String s)
      Check if the given string is empty or null.
      Parameters:
      s - String to check
      Returns:
      True if string is empty or null
    • isEmpty

      public static boolean isEmpty(String s, boolean isWithTrim)
    • isObjectEquals

      public static boolean isObjectEquals(Object obj1, Object obj2)
    • isStringEquals

      public static boolean isStringEquals(String s1, String s2)
    • isStringEqualsIgnoreCase

      public static boolean isStringEqualsIgnoreCase(String s1, String s2)
    • getSpaceServiceID

      public static ServiceID getSpaceServiceID(IJSpace space)
    • getServiceID

      public static ServiceID getServiceID(ReferentUuid service)
    • removeInvertedCommas

      public static String removeInvertedCommas(String s)
      Removes Inverted Commas from the string.
      Returns:
      same string without Inverted Commas
    • removeDelimiter

      public static String removeDelimiter(String s, char delim)
      Removes Inverted Commas from the string.
      Parameters:
      delim - the delimiters.
      Returns:
      same string without Inverted Commas
    • removeDelimiter

      public static String removeDelimiter(String s, char delim, char openEscape, char closeEscape)
      Removes delimiter from the string ignores parts in the escapes.
      Parameters:
      delim - the delimiters.
      Returns:
      same string without Delimiters and escape chars
    • getJiniGroupRepresentation

      public static String getJiniGroupRepresentation(IRemoteJSpaceAdmin spaceAdmin) throws RemoteException
      Throws:
      RemoteException
    • getObjectFromSpaceByUid

      public static Object getObjectFromSpaceByUid(IJSpace spaceProxy, String uid) throws Exception
      Throws:
      Exception
    • throwInternalSpaceException

      public static void throwInternalSpaceException(String msg, Exception cause) throws InternalSpaceException
      Throws:
      InternalSpaceException
    • throwLeaseInternalSpaceException

      public static void throwLeaseInternalSpaceException(String msg, Exception cause) throws InternalSpaceException
      Throws:
      InternalSpaceException
    • throwEngineInternalSpaceException

      public static void throwEngineInternalSpaceException(String msg, Exception cause) throws InternalSpaceException
      Throws:
      InternalSpaceException
    • createProxyInternalSpaceException

      public static ProxyInternalSpaceException createProxyInternalSpaceException(Exception e) throws InternalSpaceException
      Throws:
      InternalSpaceException
    • throwReplicationInternalSpaceException

      public static void throwReplicationInternalSpaceException(String msg, Exception cause) throws InternalSpaceException
      Throws:
      InternalSpaceException
    • countSpaceObjects

      public static long countSpaceObjects(SpaceRuntimeInfo info)
      Returns:
      countSpaceObjects objects count calculated from passed SpaceRuntimeInfo instance
    • splitString

      public static String[] splitString(String source, char delimeter)
      Returns pair of String objects ( packed in as String array ) that are deparated by one delimeter character in passed source String object. If delimeter is not found array with one source String object is returned.
      Parameters:
      source - string with only one delimeter character
      delimeter - delimeter character
      Returns:
      array of split strings
    • createFullSpaceName

      public static String createFullSpaceName(String containerName, String spaceName)
      Create full space name based on container nadm and space name
      Returns:
      full space name: <ContainerName:SpaceName>
    • formatMillis

      public static String formatMillis(long millis)
      Format ms interval to min/sec/ms
    • parseLookupGroups

      public static String[] parseLookupGroups(String lookupGroups)
    • getClusterMembersInfoMap

      public static Map<String,ClusterMemberInfo> getClusterMembersInfoMap(ClusterPolicy clusterPolicy)
      Keys in this map are cluster member names.
      Parameters:
      clusterPolicy - clusterPolicy instance that represents cluster
      Returns:
      mmap of CLusterMemberInfo class instances per specific ClusterPolicy instance.
    • getClusterMembersInfoSet

      public static Set<ClusterMemberInfo> getClusterMembersInfoSet(ClusterPolicy clusterPolicy)
    • retriveHostName

      public static String retriveHostName(NIOInfoProvider nioInfoProvider) throws RemoteException
      Throws:
      RemoteException
    • retriveHostAddress

      public static String retriveHostAddress(NIOInfoProvider nioInfoProvider) throws RemoteException
      Throws:
      RemoteException
    • getJMXConnectionUrl

      public static String getJMXConnectionUrl(ServiceItem serviceItem)
      Get the String value found in the JMXConnection entry, or null if the attribute set does not include a JMXConnection
    • isJMXRemotePortDefined

      public static boolean isJMXRemotePortDefined(ServiceItem serviceItem)
    • isJMXEnabled

      public static boolean isJMXEnabled(JVMDetails jvmDetails)
    • retriveClusterName

      public static String retriveClusterName(Entry[] attrs)
    • retrieveName

      public static String retrieveName(Entry[] attrs)
    • isJDK_1_4Runtime

      public static boolean isJDK_1_4Runtime()
    • createServiceName

      public static String createServiceName(String serviceType, int agentID, long pid)
    • createServiceName

      public static String createServiceName(String serviceType, int agentID, long pid, String[] zones)
    • getLookupGroupsStringRepresentation

      public static String getLookupGroupsStringRepresentation(String[] lookupGroups)
    • getLookupLocatorsStringRepresentation

      public static String getLookupLocatorsStringRepresentation(LookupLocator[] lookupLocators)
    • createLookupLocator

      public static LookupLocator createLookupLocator(String loookupLocatorStr)
    • getZonesStringRepresentation

      public static String getZonesStringRepresentation(String[] zones)
    • getServiceItemLookupAttributeName

      public static Entry getServiceItemLookupAttributeName(ServiceItem serviceItem, Class<? extends Entry> entryClass)
    • getTransactionTypeName

      public static String getTransactionTypeName(int transactionType)
    • getTransactionStatusName

      public static String getTransactionStatusName(int transactionStatus)
    • getTransactionLockTypeName

      public static String getTransactionLockTypeName(UnderTxnLockedObject lockedObject)
    • getTransactionLockOperationTypeName

      public static String getTransactionLockOperationTypeName(UnderTxnLockedObject lockedObject)
    • parsePropertiesParam

      public static Properties parsePropertiesParam(String argsStr)
    • getExportCodebasesSet

      public static Set<String> getExportCodebasesSet(Object service)
      Get the codebase for the service by getting the service's classloader and extracting only the http: adress and port number
      Returns:
      A String codebase
    • getExportCodebase

      public static String getExportCodebase(Object service)
      Get the codebase for the service by getting the service's classloader and extracting only the http: adress and port number
      Returns:
      A String codebase
    • getSpaceSchemas

      public static Set<String> getSpaceSchemas()
    • getArrayValuesIndexes

      public static Integer[] getArrayValuesIndexes(short[] array, Short... checkedValues)
      This method returns indexes of (checkedValues) in (array), if such values not found in (array) then empty array returned
      Parameters:
      array - where to find elements
      checkedValues - which elements to find
      Returns:
      indexes of found array elements
    • areAllArrayElementsNull

      public static boolean areAllArrayElementsNull(Object[] array)
      Returns true if all elements of array are null,otherwise false returned
      Parameters:
      array - array to check
      Returns:
      true returned if all array's elements are null
    • isJdbcDriverV3Enabled

      public static boolean isJdbcDriverV3Enabled()
    • createContainerId

      public static String createContainerId(String hostName, long pid)