Package host.anzo.simon.utils
Class Utils
java.lang.Object
host.anzo.simon.utils.Utils
A class with some static helper-methods
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanDeprecated.use JVM argument "java.util.logging.config.file=./log/mylogconfig.properties" -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic bytebooleanToByte(boolean bool) Converts a boolean value to a byte value.static booleanbyteToBoolean(byte b) Converts a byte value to a boolean value.static longCompute the "method hash" of a remote method.static Class<?> @NotNull []findAllRemoteInterfaces(Class<?> clazz) Method that returns an Class array containing all remote interfaces of a given classstatic SimonRemoteMarkerReturns the related instance ofSimonRemoteMarkerof the given object.static SimonProtocolCodecFactorygetProtocolFactoryInstance(String protocolFactory) Loads a protocol codec factory by a given classnamestatic Class<?>[]getRemoteAnnotationValue(Object remoteObject) Returns the value of theSimonRemoteannotation.static ThrowableLooks up and returns the root cause of an exception.static StringReturns the stacktrace of the given throwable as a string.static final intRetrieve object hash code and applies a supplemental hash function to the result hash, which defends against poor quality hash functions.static booleanisRemoteAnnotated(Object remoteObject) Checks whether the object is annotated withSimonRemoteor notstatic booleanChecks if given object is a simon proxy.static booleanisValidRemote(Object remoteObject) Checks if the given remote object is a valid remote object.static StringlongToHexString(long l) Converts a long value to a hex string, i.e.static voidputAllInterfaceNames(@NotNull Object object, List<String> interfaceNames) Reads all interfaces and subinterfaces of the given object and add the names to the provided interface name liststatic booleanregisterMBean(Object o, String objectNameOfMBean) see MBeanServer#registerMBean(Object, ObjectName) This is a workaround to be able to run the code also on android, where the MBeanServer is not available
-
Field Details
-
DEBUG
Deprecated.use JVM argument "java.util.logging.config.file=./log/mylogconfig.properties"if this flag is set to TRUE, SIMON tries to load the java.util.logging properties and enabled the debug-mode
-
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
computeMethodHash
Compute the "method hash" of a remote method. The method hash is a long containing the first 64 bits of the SHA digest from the bytes representing the complete method signature.- Parameters:
m- the method for which the hash has to be computed- Returns:
- the computed hash
-
getProtocolFactoryInstance
public static SimonProtocolCodecFactory getProtocolFactoryInstance(String protocolFactory) throws ClassNotFoundException, InstantiationException, IllegalAccessException Loads a protocol codec factory by a given classname- Parameters:
protocolFactory- a class name like "com.mydomain.myproject.codec.mySimonProtocolCodecFactory" which points to a class, that extendsSimonProtocolCodecFactory. The important thing is, that this class correctly overridesSimonProtocolCodecFactory.setup(boolean). For further details, look atSimonProtocolCodecFactory!- Returns:
- the protocolcodecfactory instance according to the given protocol factory class name
- Throws:
IllegalAccessException- if the class or its nullary constructor is not accessible.InstantiationException- if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.ClassNotFoundException- if the class is not found by the classloader. if so, please check your classpath.ClassCastException- if the given class is no instance ofSimonProtocolCodecFactory
-
longToHexString
Converts a long value to a hex string, i.e. 0xF923- Parameters:
l-- Returns:
- return a string showing the hex value of parameter l
-
booleanToByte
public static byte booleanToByte(boolean bool) Converts a boolean value to a byte value.- Parameters:
bool-- Returns:
- 0xFF if true, 0x00 if false
-
byteToBoolean
Converts a byte value to a boolean value.- Parameters:
b-- Returns:
- 0xFF if true, 0x00 if false
- Throws:
IllegalArgumentException- if byte value not 0xFF or 0x00
-
findAllRemoteInterfaces
Method that returns an Class array containing all remote interfaces of a given class- Parameters:
clazz- the class to analyze for remote interfaces- Returns:
- the array with all known remote interfaces
-
isRemoteAnnotated
Checks whether the object is annotated withSimonRemoteor not- Parameters:
remoteObject- the object to check- Returns:
- true, if object is annotated, false if not
-
getRemoteAnnotationValue
Returns the value of theSimonRemoteannotation.- Parameters:
remoteObject- the object to query- Returns:
- the annotation value
- Throws:
IllegalArgumentException- in case of remoteObject==null
-
isValidRemote
Checks if the given remote object is a valid remote object. Checks for:- SimonRemote annotation
- SimonRemoteMarker proxy
- implements SimonRemote
- Parameters:
remoteObject- the object to check- Returns:
- true, if remote object is valid, false if not
- Throws:
IllegalRemoteObjectException- thrown in case of a faulty remote object (ie. missing interfaces)
-
isSimonProxy
Checks if given object is a simon proxy.- Parameters:
o- object to check- Returns:
- true, if object is a simon proxy, false if not
-
getMarker
Returns the related instance ofSimonRemoteMarkerof the given object. if the specified object isn't marked, null is returned.- Parameters:
o-- Returns:
- the related instance of
SimonRemoteMarker, or null if given object is not marked
-
putAllInterfaceNames
public static void putAllInterfaceNames(@NotNull @NotNull Object object, List<String> interfaceNames) Reads all interfaces and subinterfaces of the given object and add the names to the provided interface name list- Parameters:
object- the object to search for interfacesinterfaceNames- the list to which found interfaces names are added
-
getStackTraceAsString
Returns the stacktrace of the given throwable as a string. String will be the same as "e.printStackTrace();" woulld print to console- Parameters:
e-- Returns:
- the exceptions stacktrace as a string
-
getRootCause
Looks up and returns the root cause of an exception. If none is found, returns supplied Throwable object unchanged. If root is found, recursively "unwraps" it, and returns the result to the caller.- Parameters:
th-- Returns:
- the exceptions root-cause, if available, otherwise th will be returned unchanged
-
hash
Retrieve object hash code and applies a supplemental hash function to the result hash, which defends against poor quality hash functions. This is critical because HashMap uses power-of-two length hash tables, that otherwise encounter collisions for hashCodes that do not differ in lower bits. Note: Null keys always map to hash 0, thus index 0. -
registerMBean
see MBeanServer#registerMBean(Object, ObjectName) This is a workaround to be able to run the code also on android, where the MBeanServer is not available- Returns:
- true, if registration succeeds, false if not
-