Package org.igniterealtime.jbosh
Class ServiceLib
java.lang.Object
org.igniterealtime.jbosh.ServiceLib
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> T
attemptLoad
(Class<T> ofClass, String className) Attempts to load the specified implementation class.private static void
finalClose
(Closeable closeMe) Check and close a closeable object, trapping and ignoring any exception that might result.(package private) static <T> T
loadService
(Class<T> ofType) Probe for and select an implementation of the specified service type by using the a modified Jar SPI mechanism.loadServicesImplementations
(Class ofClass) Generates a list of implementation class names by using the Jar SPI technique.
-
Field Details
-
LOG
Logger.
-
-
Constructor Details
-
ServiceLib
private ServiceLib()Prevent construction.
-
-
Method Details
-
loadService
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:
IllegalStateException
- is no service implementations could be instantiated
-
loadServicesImplementations
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
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
Check and close a closeable object, trapping and ignoring any exception that might result.- Parameters:
closeMe
- the thing to close
-