Package com.j_spaces.kernel
Class JSpaceUtilities
java.lang.Object
com.j_spaces.kernel.JSpaceUtilities
JSpaceUtility class provides useful GigaSpaces utility functions.
- Version:
- 1.0
- Author:
- Igor Goldenbeg
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareAllArrayElementsNull(Object[] array) Returns true if all elements of array are null,otherwise false returnedstatic DocumentbuildClusterXMLDom(int _totalMembers, int _backupMembers, String _clusterSchemaName, String _clusterName, String _distCacheConfigName, String _groups) Builds a schema cluster config xml file on the fly, using several inputs.static voidConverts recursively entire DOM tree values from System Property to value.static DocumentconvertToClusterConfiguration(Document clusterXMLDomElement, InputStream clusterXSLPolicy) Method which gets cluster xml Dom element and cluster xsl schema input stream.static longstatic StringcreateContainerId(String hostName, long pid) static StringcreateContainerPresentName(String hostName, String containerName) This method constructs name for container representation.static StringcreateFullSpaceName(String containerName, String spaceName) Create full space name based on container nadm and space namestatic LookupLocatorcreateLookupLocator(String loookupLocatorStr) static ProxyInternalSpaceExceptionstatic StringcreateServiceName(String serviceType, int agentID, long pid) static StringcreateServiceName(String serviceType, int agentID, long pid, String[] zones) static booleandomWriter(Node node, PrintStream ps, String prefix) Order all XML tags of DOM tree and writes XML DOM tree to OutputStream.static StringformatMillis(long millis) Format ms interval to min/sec/msstatic Integer[]getArrayValuesIndexes(short[] array, Short... checkedValues) This method returns indexes of (checkedValues) in (array), if such values not found in (array) then empty array returnedstatic ThrowablegetAssignableCauseExceptionFromHierarchy(Exception sourceException, Class checkCauseExceptionClass) static StringgetCallStackTraces(int deep) static ThrowablegetCauseExceptionFromHierarchy(Throwable sourceException, Class checkCauseExceptionClass) This method checks whole hierarchy for the exception cause.static StringgetCauseExceptionMessageFromHierarchy(Exception sourceException, Class checkCauseExceptionClass) This method checks whole hierarchy for the exception cause.static Map<String,ClusterMemberInfo> getClusterMembersInfoMap(ClusterPolicy clusterPolicy) Keys in this map are cluster member names.static Set<ClusterMemberInfo>getClusterMembersInfoSet(ClusterPolicy clusterPolicy) static StringgetExportCodebase(Object service) Get the codebase for the service by getting the service's classloader and extracting only the http: adress and port numbergetExportCodebasesSet(Object service) Get the codebase for the service by getting the service's classloader and extracting only the http: adress and port numberstatic StringgetJiniGroupRepresentation(IRemoteJSpaceAdmin spaceAdmin) static StringgetJMXConnectionUrl(ServiceItem serviceItem) Get the String value found in the JMXConnection entry, or null if the attribute set does not include a JMXConnectionstatic StringgetLookupGroupsStringRepresentation(String[] lookupGroups) static StringgetLookupLocatorsStringRepresentation(LookupLocator[] lookupLocators) static ObjectgetObjectFromSpaceByUid(IJSpace spaceProxy, String uid) static Stringstatic ThrowablegetRootCauseException(Throwable sourceException) static ServiceIDgetServiceID(ReferentUuid service) static EntrygetServiceItemLookupAttributeName(ServiceItem serviceItem, Class<? extends Entry> entryClass) static ServiceIDgetSpaceServiceID(IJSpace space) static StringConverts the stack trace of the specified exception to a string.static StringgetTransactionLockOperationTypeName(UnderTxnLockedObject lockedObject) static StringgetTransactionLockTypeName(UnderTxnLockedObject lockedObject) static StringgetTransactionStatusName(int transactionStatus) static StringgetTransactionTypeName(int transactionType) static StringgetZonesStringRepresentation(String[] zones) static booleanCheck if the given string is empty or null.static booleanstatic booleanstatic booleanstatic booleanisJMXEnabled(JVMDetails jvmDetails) static booleanisJMXRemotePortDefined(ServiceItem serviceItem) static booleanisObjectEquals(Object obj1, Object obj2) static booleanisSameException(Throwable exception1, Throwable exception2) static booleanisStringEquals(String s1, String s2) static booleanisStringEqualsIgnoreCase(String s1, String s2) static voidNormalize DOM tree.static DocumentoverrideClusterConfigWithXPath(String xpath, String newValue, Document clusterConfigRootDoc) A method which overrides cluster configuration xml using a XPath key/value pair passed through custom properties.static DocumentoverrideClusterConfigWithXPath(Properties customProps, Document clusterConfigRootDoc) static booleanparseBooleanTag(String tag, String s) Parses the string argument as a boolean.static booleanparseBooleanTag(String tag, String s, boolean defaultValue) Parses the string argument as a boolean.static String[]parseLookupGroups(String lookupGroups) static PropertiesparsePropertiesParam(String argsStr) static StringremoveDelimiter(String s, char delim) Removes Inverted Commas from the string.static StringremoveDelimiter(String s, char delim, char openEscape, char closeEscape) Removes delimiter from the string ignores parts in the escapes.static StringRemoves Inverted Commas from the string.static StringreplaceInString(String content, String oldStr, String newStr, boolean replaceAll) Replace the desired string in allcontentstring.static StringretrieveName(Entry[] attrs) static StringretriveClusterName(Entry[] attrs) static StringretriveHostAddress(NIOInfoProvider nioInfoProvider) static StringretriveHostName(NIOInfoProvider nioInfoProvider) static voidSetting the XML parser and converter implementations.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.static voidthrowEngineInternalSpaceException(String msg, Exception cause) static voidthrowInternalSpaceException(String msg, Exception cause) static voidthrowLeaseInternalSpaceException(String msg, Exception cause) static voidthrowReplicationInternalSpaceException(String msg, Exception cause)
-
Field Details
-
DEBUG_LOGGER
public static final org.slf4j.Logger DEBUG_LOGGER -
BLANK_VALUE
- See Also:
-
YES_VAL
- See Also:
-
NO_VAL
- See Also:
-
SECURED_HIDDEN_VALUE
- See Also:
-
NOT_AVAILABLE_STR
- See Also:
-
LINE_SEPARATOR
-
-
Constructor Details
-
JSpaceUtilities
public JSpaceUtilities()
-
-
Method Details
-
domWriter
Order all XML tags of DOM tree and writes XML DOM tree to OutputStream. For example DOM tree looks like this: value AfterdomWriterfunction DOM tree will look like this: value- Parameters:
node- XML DOM tree.ps- OutputStream it's can be FileOutputStream, System.outprefix- Number of space between tags- Returns:
trueif the node is a value node,falseotherwisetrue- See Also:
-
createContainerPresentName
This method constructs name for container representation. Actually it concatenates host name with container name.- Parameters:
hostName- host namecontainerName- container name- Returns:
- representation name
-
parseBooleanTag
Parses the string argument as a boolean. Thebooleanreturned represents the valuetrueif the string argument is notnull, is not a sys-property, and is equal, ignoring case, to the string"true".- Parameters:
tag- thexml-tagcontaining the booleans- theStringcontaining 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
Parses the string argument as a boolean. Thebooleanreturned represents the valuetrueif the string argument is notnull, is not a sys-property, and is equal, ignoring case, to the string"true".- Parameters:
tag- thexml-tagcontaining the booleans- theStringcontaining the boolean representation to be parseddefaultValue- 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
- Parameters:
node- Dom tree.- See Also:
-
convertDOMTreeFromSystemProperty
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 reasonIOExceptionTransformerConfigurationExceptionTransformerExceptionParserConfigurationException
-
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.XSLTConvertercom.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 allcontentstring. 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 incontentand replace.newStr- The string which will be replaced witholdstring.replaceAll-trueif replace in allcontent,falsethe replace will be executed only one time.- Returns:
- Returns the replaced content or the original content if was nothing replaced.
-
getStackTrace
Converts the stack trace of the specified exception to a string. NOTE: Pass the exception as an argument to the external exception -
getCallStackTraces
-
getPropertiesPresentation
-
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 checkedcheckCauseExceptionClass- 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 checkedcheckCauseExceptionClass- Class instance- Returns:
- if there is exception of specific class in exception hierarchy it will be returned, otherwise null returned
-
getAssignableCauseExceptionFromHierarchy
-
getRootCauseException
-
isSameException
-
isEmpty
Check if the given string is empty or null.- Parameters:
s- String to check- Returns:
- True if string is empty or null
-
isEmpty
-
isObjectEquals
-
isStringEquals
-
isStringEqualsIgnoreCase
-
getSpaceServiceID
-
getServiceID
-
removeInvertedCommas
Removes Inverted Commas from the string.- Returns:
- same string without Inverted Commas
-
removeDelimiter
Removes Inverted Commas from the string.- Parameters:
delim- the delimiters.- Returns:
- same string without Inverted Commas
-
removeDelimiter
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
- 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
- Returns:
- countSpaceObjects objects count calculated from passed SpaceRuntimeInfo instance
-
splitString
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 characterdelimeter- delimeter character- Returns:
- array of split strings
-
createFullSpaceName
Create full space name based on container nadm and space name- Returns:
- full space name: <ContainerName:SpaceName>
-
formatMillis
Format ms interval to min/sec/ms -
parseLookupGroups
-
getClusterMembersInfoMap
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
-
retriveHostName
- Throws:
RemoteException
-
retriveHostAddress
- Throws:
RemoteException
-
getJMXConnectionUrl
Get the String value found in the JMXConnection entry, or null if the attribute set does not include a JMXConnection -
isJMXRemotePortDefined
-
isJMXEnabled
-
retriveClusterName
-
retrieveName
-
isJDK_1_4Runtime
public static boolean isJDK_1_4Runtime() -
createServiceName
-
createServiceName
-
getLookupGroupsStringRepresentation
-
getLookupLocatorsStringRepresentation
-
createLookupLocator
-
getZonesStringRepresentation
-
getServiceItemLookupAttributeName
public static Entry getServiceItemLookupAttributeName(ServiceItem serviceItem, Class<? extends Entry> entryClass) -
getTransactionTypeName
-
getTransactionStatusName
-
getTransactionLockTypeName
-
getTransactionLockOperationTypeName
-
parsePropertiesParam
-
getExportCodebasesSet
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
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
-
getArrayValuesIndexes
This method returns indexes of (checkedValues) in (array), if such values not found in (array) then empty array returned- Parameters:
array- where to find elementscheckedValues- which elements to find- Returns:
- indexes of found array elements
-
areAllArrayElementsNull
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
-