Class ServiceLib

java.lang.Object
org.igniterealtime.jbosh.ServiceLib

final class ServiceLib extends 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 final Logger
    Logger.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Prevent construction.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static <T> T
    attemptLoad(Class<T> ofClass, String className)
    Attempts to load the specified implementation class.
    private static void
    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.
    private static List<String>
    Generates a list of implementation class names by using the Jar SPI technique.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOG

      private static final Logger LOG
      Logger.
  • Constructor Details

    • ServiceLib

      private ServiceLib()
      Prevent construction.
  • Method Details

    • loadService

      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. 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

      private static List<String> loadServicesImplementations(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(Class<T> ofClass, 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(Closeable closeMe)
      Check and close a closeable object, trapping and ignoring any exception that might result.
      Parameters:
      closeMe - the thing to close