@ThreadSafe public final class PluginRegistry extends Object
Plugin
s currently installed. Call getInstance(Context)
to obtain the singleton
instance of this class. Initially loading the plug-ins can take a few
seconds, so there are both blocking getPluginMap(PluginType)
and
non-blocking peekPluginMap(PluginType)
calls to retrieve a snapshot
the registry.
The registry will automatically keep itself up to date, and clients of this
class can monitor for changes via the Intent action returned by
getChangeIntentAction()
. When the registry changes, the snapshots
previously retrieved from the registry will not change. To get the latest
changes, call getPluginMap(PluginType)
or
peekPluginMap(PluginType)
again.
Modifier and Type | Method and Description |
---|---|
String |
getChangeIntentAction()
The registry broadcasts this Intent action when the registry changes,
allowing clients to implement an observer design pattern.
|
String |
getChangeIntentPermission() |
static PluginRegistry |
getInstance(Context context) |
Map<String,Plugin> |
getPluginMap(PluginType type)
Retrieves a snapshot of the registry's latest state, blocking until the
registry is loaded.
|
Map<String,Plugin> |
peekPluginMap(PluginType type)
Retrieves a snapshot of the registry's latest state or
null if
the registry isn't loaded yet. |
public static PluginRegistry getInstance(Context context)
context
- Application Context.public String getChangeIntentAction()
getChangeIntentPermission()
public String getChangeIntentPermission()
getChangeIntentAction()
.public Map<String,Plugin> getPluginMap(PluginType type)
Return values of this method are snapshots and will not change. If the
Intent from getChangeIntentAction()
is broadcast, call
getPluginMap(PluginType)
again to get an updated snapshot.
type
- The type of registry information to return.Plugin.getRegistryName()
keys to Plugin
instances. Clients MUST NOT attempt to modify the map.public Map<String,Plugin> peekPluginMap(PluginType type)
null
if
the registry isn't loaded yet. Once the registry is initially loaded,
this method will no longer return null
.
Return values of this method are snapshots and will not change. If the
Intent from getChangeIntentAction()
is broadcast, call
peekPluginMap(PluginType)
again to get an updated snapshot.
type
- The type of registry information to return.Plugin.getRegistryName()
keys to Plugin
instances. This may return null if
the registry isn't loaded yet. Clients MUST NOT attempt to modify the map.