Class Candidates
- java.lang.Object
-
- org.apache.felix.framework.resolver.Candidates
-
class Candidates extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<BundleRevision,WrappedRevision>
m_allWrappedHosts
private java.util.Map<BundleRequirement,java.util.List<BundleCapability>>
m_candidateMap
private java.util.Map<BundleCapability,java.util.Set<BundleRequirement>>
m_dependentMap
private boolean
m_fragmentsPresent
private java.util.Set<BundleRevision>
m_mandatoryRevisions
private java.util.Map<BundleRevision,java.lang.Object>
m_populateResultCache
static int
MANDATORY
static int
ON_DEMAND
static int
OPTIONAL
-
Constructor Summary
Constructors Modifier Constructor Description Candidates()
Constructs an empty Candidates object.private
Candidates(java.util.Set<BundleRevision> mandatoryRevisions, java.util.Map<BundleCapability,java.util.Set<BundleRequirement>> dependentMap, java.util.Map<BundleRequirement,java.util.List<BundleCapability>> candidateMap, java.util.Map<BundleRevision,WrappedRevision> wrappedHosts, java.util.Map<BundleRevision,java.lang.Object> populateResultCache, boolean fragmentsPresent)
Private copy constructor used by the copy() method.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
add(java.util.Map<BundleRequirement,java.util.List<BundleCapability>> candidates)
Adds requirements and candidates in bulk.private void
add(BundleRequirement req, java.util.List<BundleCapability> candidates)
Adds a requirement and its matching candidates to the internal data structure.Candidates
copy()
Creates a copy of the Candidates object.void
dump()
java.util.List<BundleCapability>
getCandidates(BundleRequirement req)
Gets the candidates associated with a given requirement.ResolveException
getResolveException(BundleRevision revision)
BundleRevision
getWrappedHost(BundleRevision m)
Returns the wrapped module associated with the given module.boolean
isPopulated(BundleRevision revision)
void
populate(ResolveContext rc, BundleRevision revision, int resolution)
Populates candidates for the specified revision.private java.util.Map<BundleCapability,java.util.Map<java.lang.String,java.util.Map<Version,java.util.List<BundleRequirement>>>>
populateDependents()
void
populateDynamic(ResolveContext rc, BundleRevision revision, BundleRequirement req, java.util.List<BundleCapability> candidates)
private boolean
populateFragmentOndemand(ResolveContext rc, BundleRevision revision)
private void
populateRevision(ResolveContext rc, BundleRevision revision)
Populates candidates for the specified revision.void
prepare(ResolveContext rc)
Merges fragments into their hosts.private ResolveException
processCandidates(ResolveContext rc, BundleRevision revision, java.util.List<BundleCapability> candidates)
This method performs common processing on the given set of candidates.private void
remove(BundleCapability c, java.util.Set<BundleRevision> unresolvedRevisions)
Removes a capability from the internal data structures.private void
remove(BundleRequirement req)
Removes a requirement from the internal data structures.private void
remove(BundleRevision br, java.util.Set<BundleRevision> unresolvedRevisions)
Removes the specified module from the internal data structures, which involves removing its requirements and its capabilities.private void
removeRevision(BundleRevision revision, ResolveException ex)
Removes a module from the internal data structures if it wasn't selected as a fragment or a singleton.
-
-
-
Field Detail
-
MANDATORY
public static final int MANDATORY
- See Also:
- Constant Field Values
-
OPTIONAL
public static final int OPTIONAL
- See Also:
- Constant Field Values
-
ON_DEMAND
public static final int ON_DEMAND
- See Also:
- Constant Field Values
-
m_mandatoryRevisions
private final java.util.Set<BundleRevision> m_mandatoryRevisions
-
m_dependentMap
private final java.util.Map<BundleCapability,java.util.Set<BundleRequirement>> m_dependentMap
-
m_candidateMap
private final java.util.Map<BundleRequirement,java.util.List<BundleCapability>> m_candidateMap
-
m_allWrappedHosts
private final java.util.Map<BundleRevision,WrappedRevision> m_allWrappedHosts
-
m_populateResultCache
private final java.util.Map<BundleRevision,java.lang.Object> m_populateResultCache
-
m_fragmentsPresent
private boolean m_fragmentsPresent
-
-
Constructor Detail
-
Candidates
private Candidates(java.util.Set<BundleRevision> mandatoryRevisions, java.util.Map<BundleCapability,java.util.Set<BundleRequirement>> dependentMap, java.util.Map<BundleRequirement,java.util.List<BundleCapability>> candidateMap, java.util.Map<BundleRevision,WrappedRevision> wrappedHosts, java.util.Map<BundleRevision,java.lang.Object> populateResultCache, boolean fragmentsPresent)
Private copy constructor used by the copy() method.- Parameters:
dependentMap
- the capability dependency map.candidateMap
- the requirement candidate map.hostFragments
- the fragment map.wrappedHosts
- the wrapped hosts map.
-
Candidates
public Candidates()
Constructs an empty Candidates object.
-
-
Method Detail
-
populate
public final void populate(ResolveContext rc, BundleRevision revision, int resolution)
Populates candidates for the specified revision. How a revision is resolved depends on its resolution type as follows:- MANDATORY - must resolve and failure to do so throws an exception.
- OPTIONAL - attempt to resolve, but no exception is thrown if the resolve fails.
- ON_DEMAND - only resolve on demand; this only applies to fragments and will only resolve a fragment if its host is already selected as a candidate.
- Parameters:
state
- the resolver state used for populating the candidates.revision
- the revision whose candidates should be populated.resolution
- indicates the resolution type.
-
populateRevision
private void populateRevision(ResolveContext rc, BundleRevision revision)
Populates candidates for the specified revision.- Parameters:
state
- the resolver state used for populating the candidates.revision
- the revision whose candidates should be populated.
-
populateFragmentOndemand
private boolean populateFragmentOndemand(ResolveContext rc, BundleRevision revision) throws ResolveException
- Throws:
ResolveException
-
populateDynamic
public void populateDynamic(ResolveContext rc, BundleRevision revision, BundleRequirement req, java.util.List<BundleCapability> candidates)
-
processCandidates
private ResolveException processCandidates(ResolveContext rc, BundleRevision revision, java.util.List<BundleCapability> candidates)
This method performs common processing on the given set of candidates. Specifically, it removes any candidates which cannot resolve and it synthesizes candidates for any candidates coming from any attached fragments, since fragment capabilities only appear once, but technically each host represents a unique capability.- Parameters:
state
- the resolver state.revision
- the revision being resolved.candidates
- the candidates to process.- Returns:
- a resolve exception to be re-thrown, if any, or null.
-
isPopulated
public boolean isPopulated(BundleRevision revision)
-
getResolveException
public ResolveException getResolveException(BundleRevision revision)
-
add
private void add(BundleRequirement req, java.util.List<BundleCapability> candidates)
Adds a requirement and its matching candidates to the internal data structure. This method assumes it owns the data being passed in and does not make a copy. It takes the data and processes, such as calculating which requirements depend on which capabilities and recording any fragments it finds for future merging.- Parameters:
req
- the requirement to add.candidates
- the candidates matching the requirement.
-
add
private void add(java.util.Map<BundleRequirement,java.util.List<BundleCapability>> candidates)
Adds requirements and candidates in bulk. The outer map is not retained by this method, but the inner data structures are, so they should not be further modified by the caller.- Parameters:
candidates
- the bulk requirements and candidates to add.
-
getWrappedHost
public BundleRevision getWrappedHost(BundleRevision m)
Returns the wrapped module associated with the given module. If the module was not wrapped, then the module itself is returned. This is really only needed to determine if the root modules of the resolve have been wrapped.- Parameters:
m
- the module whose wrapper is desired.- Returns:
- the wrapper module or the module itself if it was not wrapped.
-
getCandidates
public java.util.List<BundleCapability> getCandidates(BundleRequirement req)
Gets the candidates associated with a given requirement.- Parameters:
req
- the requirement whose candidates are desired.- Returns:
- the matching candidates or null.
-
prepare
public void prepare(ResolveContext rc)
Merges fragments into their hosts. It does this by wrapping all host modules and attaching their selected fragments, removing all unselected fragment modules, and replacing all occurrences of the original fragments in the internal data structures with the wrapped host modules instead. Thus, fragment capabilities and requirements are merged into the appropriate host and the candidates for the fragment now become candidates for the host. Likewise, any module depending on a fragment now depend on the host. Note that this process is sort of like multiplication, since one fragment that can attach to two hosts effectively gets multiplied across the two hosts. So, any modules being satisfied by the fragment will end up having the two hosts as potential candidates, rather than the single fragment.- Parameters:
existingSingletons
- existing resolved singletons.- Throws:
ResolveException
- if the removal of any unselected fragments result in the root module being unable to resolve.
-
populateDependents
private java.util.Map<BundleCapability,java.util.Map<java.lang.String,java.util.Map<Version,java.util.List<BundleRequirement>>>> populateDependents()
-
removeRevision
private void removeRevision(BundleRevision revision, ResolveException ex)
Removes a module from the internal data structures if it wasn't selected as a fragment or a singleton. This process may cause other modules to become unresolved if they depended on the module's capabilities and there is no other candidate.- Parameters:
revision
- the module to remove.- Throws:
ResolveException
- if removing the module caused the resolve to fail.
-
remove
private void remove(BundleRevision br, java.util.Set<BundleRevision> unresolvedRevisions) throws ResolveException
Removes the specified module from the internal data structures, which involves removing its requirements and its capabilities. This may cause other modules to become unresolved as a result.- Parameters:
br
- the module to remove.unresolvedRevisions
- a list to containing any additional modules that that became unresolved as a result of removing this module and will also need to be removed.- Throws:
ResolveException
- if removing the module caused the resolve to fail.
-
remove
private void remove(BundleRequirement req)
Removes a requirement from the internal data structures.- Parameters:
req
- the requirement to remove.
-
remove
private void remove(BundleCapability c, java.util.Set<BundleRevision> unresolvedRevisions) throws ResolveException
Removes a capability from the internal data structures. This may cause other modules to become unresolved as a result.- Parameters:
c
- the capability to remove.unresolvedRevisions
- a list to containing any additional modules that that became unresolved as a result of removing this module and will also need to be removed.- Throws:
ResolveException
- if removing the module caused the resolve to fail.
-
copy
public Candidates copy()
Creates a copy of the Candidates object. This is used for creating permutations when package space conflicts are discovered.- Returns:
- copy of this Candidates object.
-
dump
public void dump()
-
-