Package org.igniterealtime.jbosh
Class ServiceLib
- java.lang.Object
-
- org.igniterealtime.jbosh.ServiceLib
-
final class ServiceLib extends java.lang.Object
Utility library for use in loading services using the Jar Service Provider Interface (Jar SPI). This can be replaced once the minimum java rev moves beyond Java 5.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Logger
LOG
Logger.
-
Constructor Summary
Constructors Modifier Constructor Description private
ServiceLib()
Prevent construction.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static <T> T
attemptLoad(java.lang.Class<T> ofClass, java.lang.String className)
Attempts to load the specified implementation class.private static void
finalClose(java.io.Closeable closeMe)
Check and close a closeable object, trapping and ignoring any exception that might result.(package private) static <T> T
loadService(java.lang.Class<T> ofType)
Probe for and select an implementation of the specified service type by using the a modified Jar SPI mechanism.private static java.util.List<java.lang.String>
loadServicesImplementations(java.lang.Class ofClass)
Generates a list of implementation class names by using the Jar SPI technique.
-
-
-
Method Detail
-
loadService
static <T> T loadService(java.lang.Class<T> ofType)
Probe for and select an implementation of the specified service type by using the a modified Jar SPI mechanism. Modified in that the system properties will be checked to see if there is a value set for the naem of the class to be loaded. If so, that value is treated as the class name of the first implementation class to be attempted to be loaded. This provides a (unsupported) mechanism to insert other implementations. Note that the supported mechanism is by properly ordering the classpath.- Returns:
- service instance
- Throws:
java.lang.IllegalStateException
- is no service implementations could be instantiated
-
loadServicesImplementations
private static java.util.List<java.lang.String> loadServicesImplementations(java.lang.Class ofClass)
Generates a list of implementation class names by using the Jar SPI technique. The order in which the class names occur in the service manifest is significant.- Returns:
- list of all declared implementation class names
-
attemptLoad
private static <T> T attemptLoad(java.lang.Class<T> ofClass, java.lang.String className)
Attempts to load the specified implementation class. Attempts will fail if - for example - the implementation depends on a class not found on the classpath.- Parameters:
className
- implementation class to attempt to load- Returns:
- service instance, or
null
if the instance could not be loaded
-
finalClose
private static void finalClose(java.io.Closeable closeMe)
Check and close a closeable object, trapping and ignoring any exception that might result.- Parameters:
closeMe
- the thing to close
-
-