Class DynamicMap<T>

  • All Implemented Interfaces:
    Iterable<Extension<T>>
    Direct Known Subclasses:
    PrivateInternals_DynamicMapImpl

    public abstract class DynamicMap<T>
    extends Object
    implements Iterable<Extension<T>>
    A map of members that can be modified as plugins reload.

    Maps index their members by plugin name and export name.

    DynamicMaps are always mapped as singletons in Guice. Maps store Providers internally, and resolve the provider to an instance on demand. This enables registrations to decide between singleton and non-singleton members.

    • Method Detail

      • mapOf

        public static <T> void mapOf​(com.google.inject.Binder binder,
                                     Class<T> member)
        Declare a singleton DynamicMap<T> with a binder.

        Maps must be defined in a Guice module before they can be bound:

         DynamicMap.mapOf(binder(), Interface.class);
         bind(Interface.class)
           .annotatedWith(Exports.named("foo"))
           .to(Impl.class);
         
        Parameters:
        binder - a new binder created in the module.
        member - type of value in the map.
      • mapOf

        public static <T> void mapOf​(com.google.inject.Binder binder,
                                     com.google.inject.TypeLiteral<T> member)
        Declare a singleton DynamicMap<T> with a binder.

        Maps must be defined in a Guice module before they can be bound:

         DynamicMap.mapOf(binder(), new TypeLiteral<Thing<Bar>>(){});
         bind(new TypeLiteral<Thing<Bar>>() {})
           .annotatedWith(Exports.named("foo"))
           .to(Impl.class);
         
        Parameters:
        binder - a new binder created in the module.
        member - type of value in the map.
      • emptyMap

        public static <T> DynamicMap<T> emptyMap()
        Returns an empty DynamicMap instance *
      • get

        public T get​(String pluginName,
                     String exportName)
              throws com.google.inject.ProvisionException
        Lookup an implementation by name.
        Parameters:
        pluginName - local name of the plugin providing the item.
        exportName - name the plugin exports the item as.
        Returns:
        the implementation. Null if the plugin is not running, or if the plugin does not export this name.
        Throws:
        com.google.inject.ProvisionException - if the registered provider is unable to obtain an instance of the requested implementation.
      • plugins

        public SortedSet<String> plugins()
        Get the names of all running plugins supplying this type.
        Returns:
        sorted set of active plugins that supply at least one item.
      • byPlugin

        public SortedMap<String,​com.google.inject.Provider<T>> byPlugin​(String pluginName)
        Get the items exported by a single plugin.
        Parameters:
        pluginName - name of the plugin.
        Returns:
        items exported by a plugin, keyed by the export name.