Class Engine

java.lang.Object
org.apache.harmony.security.fortress.Engine

public class Engine
extends Object
This class implements common functionality for Provider supplied classes. The usage pattern is to allocate static Engine instance per service type and synchronize on that instance during calls to getInstance and retreival of the selected Provider and Service Provider Interface (SPI) results. Retreiving the results with getProvider and getSpi sets the internal Engine values to null to prevent memory leaks.

For example:

   {@code
   public class Foo {

       private static final Engine ENGINE = new Engine("Foo");

       private final FooSpi spi;
       private final Provider provider;
       private final String algorithm;

       protected Foo(FooSpi spi,
                     Provider provider,
                     String algorithm) {
           this.spi = spi;
           this.provider = provider;
           this.algorithm = algorithm;
       }

       public static Foo getInstance(String algorithm) {
           Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
           return new Foo((FooSpi) sap.spi, sap.provider, algorithm);
       }

       public static Foo getInstance(String algorithm, Provider provider) {
           Object spi = ENGINE.getInstance(algorithm, provider, null);
           return new Foo((FooSpi) spi, provider, algorithm);
       }

       ...

 }