Discussions

News: Ethan Nicholas: Creating a Service Provider Interface

  1. Ethan Nicholas, with "Creating a Service Provider Interface," provides a short-and-simple discussion of using the Service Provider Interface, a feature documented as a feature of the Jar file specification. It's used in a number of places in the JVM, in various capabilities, and is useful for low-level pluggable services.
    In case you aren't familiar with SPIs, they have a tantalizing proposition: just put a special JAR file somewhere on your class path, and the features in the JAR file will be found and made available. Many of Java's internal APIs, such as JNDI and javax.imageio, have SPIs, which makes it a snap to plug in new features.
    One thing Ethan doesn't mention is that JAXP also uses SPI, but a custom version, so that it provides features that the SPI interface itself doesn't - such as control from the command line.
  2. Could this technique be used alongside OSGi or is it a different approach to pluggability? What would the advantages of one over the other be?
  3. I have seen whole development teams and features cut because they couldn't figure out how to disentangle the relationship between jar files, SPI override mechanisms and classloader hierarchies. Frankly, this technique works best in simple scenarios.

    Overriding the default SPI *once* for the entire system is easy. But that's the simple, trivial case. A more realistic and complex scenario is when you have multiple components, such as multiple Web apps, a server container, etc.

    See Mustang (Java 6) for Sun's move to promote their internal Factory Finder implementation to the java.util package. Here's the RFE from Bug Parade:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4640520
  4. I have seen whole development teams foiled and features cut because they couldn't figure out how to disentangle the relationship between jar files, SPI override mechanisms and classloader hierarchies. Frankly, this technique works best in simple scenarios.

    Overriding the default SPI *once* for the entire system is easy. But that's the simple, trivial case. A more realistic and complex scenario is when you have multiple components, such as multiple Web apps, a server container, etc.

    See Mustang (Java 6) for Sun's move to promote their internal Factory Finder implementation to the java.util package. Here's the RFE from Bug Parade:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4640520