use of org.eclipse.equinox.region.RegionFilterBuilder in project fabric8 by jboss-fuse.
the class SubsystemResolver method getFlatDigraph.
public RegionDigraph getFlatDigraph() throws BundleException, InvalidSyntaxException {
if (flatDigraph == null) {
flatDigraph = new StandardRegionDigraph(null, null);
Map<String, String> flats = getFlatSubsystemsMap();
for (Region r : digraph.getRegions()) {
if (r.getName().equals(flats.get(r.getName()))) {
flatDigraph.createRegion(r.getName());
}
}
for (Region r : digraph.getRegions()) {
for (RegionDigraph.FilteredRegion fr : digraph.getEdges(r)) {
String rt = flats.get(r.getName());
String rh = flats.get(fr.getRegion().getName());
if (!rh.equals(rt)) {
Region tail = flatDigraph.getRegion(rt);
Region head = flatDigraph.getRegion(rh);
RegionFilterBuilder rfb = flatDigraph.createRegionFilterBuilder();
for (Map.Entry<String, Collection<String>> entry : fr.getFilter().getSharingPolicy().entrySet()) {
// Discard osgi.identity namespace
if (!IDENTITY_NAMESPACE.equals(entry.getKey())) {
for (String f : entry.getValue()) {
rfb.allow(entry.getKey(), f);
}
}
}
flatDigraph.connect(tail, rfb.build(), head);
}
}
}
}
return flatDigraph;
}
use of org.eclipse.equinox.region.RegionFilterBuilder in project aries by apache.
the class SubsystemResource method setImportIsolationPolicy.
private void setImportIsolationPolicy() throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
if (isRoot() || !isScoped())
return;
Region region = getRegion();
Region from = region;
RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder();
Region to = getParents().iterator().next().getRegion();
addSubsystemServiceImportToSharingPolicy(builder, to);
// TODO Is this check really necessary? Looks like it was done at the beginning of this method.
if (isScoped()) {
// Both applications and composites have Import-Package headers that require processing.
// In the case of applications, the header is generated.
Header<?> header = getSubsystemManifest().getImportPackageHeader();
setImportIsolationPolicy(builder, (ImportPackageHeader) header);
// Both applications and composites have Require-Capability headers that require processing.
// In the case of applications, the header is generated.
header = getSubsystemManifest().getRequireCapabilityHeader();
setImportIsolationPolicy(builder, (RequireCapabilityHeader) header);
// Both applications and composites have Subsystem-ImportService headers that require processing.
// In the case of applications, the header is generated.
header = getSubsystemManifest().getSubsystemImportServiceHeader();
setImportIsolationPolicy(builder, (SubsystemImportServiceHeader) header);
header = getSubsystemManifest().getRequireBundleHeader();
setImportIsolationPolicy(builder, (RequireBundleHeader) header);
// Always add access to osgi.ee and osgi.native namespaces
setImplicitAccessToNativeAndEECapabilities(builder);
}
RegionFilter regionFilter = builder.build();
from.connectRegion(to, regionFilter);
}
use of org.eclipse.equinox.region.RegionFilterBuilder in project aries by apache.
the class RegionUpdater method addRequirements.
public void addRequirements(Collection<? extends Requirement> requirements) throws BundleException, InvalidSyntaxException {
for (int i = 0; i < MAX_ATTEMPTS_DEFAULT; i++) {
RegionDigraph copy = copyDigraph();
Region tail = copyTail(copy);
Region head = copyHead(copy);
Set<Long> bundleIds = copyBundleIds(tail);
Map<String, RegionFilterBuilder> heads = copyHeadRegions(tail, copy);
Map<String, RegionFilterBuilder> tails = copyTailRegions(tail, copy);
copy.removeRegion(tail);
tail = copy.createRegion(tail.getName());
addBundleIds(bundleIds, tail);
RegionFilterBuilder builder = heads.get(head.getName());
if (builder == null) {
// See ARIES-1429.
throw new IllegalStateException(new StringBuilder(tail.getName()).append(" not connected to ").append(head.getName()).toString());
}
if (requirements == null) {
heads.put(head.getName(), null);
} else {
addRequirements(requirements, builder);
}
addHeadRegions(heads, tail, copy);
addTailRegions(tails, tail, copy);
// Replace the current digraph.
try {
digraph.replace(copy);
} catch (BundleException e) {
// Something modified digraph since the copy was made.
if (i < MAX_ATTEMPTS_DEFAULT)
// There are more attempts to make.
continue;
// Number of attempts has been exhausted.
throw e;
}
// Success! No need to continue looping.
break;
}
}
use of org.eclipse.equinox.region.RegionFilterBuilder in project aries by apache.
the class SubsystemResource method setImportIsolationPolicy.
private void setImportIsolationPolicy(Map<Resource, List<Wire>> resolution) throws Exception {
if (!isApplication()) {
return;
}
SubsystemContentHeader contentHeader = getSubsystemManifest().getSubsystemContentHeader();
// Prepare the regions and filter builder to set the sharing policy.
Region from = getRegion();
Region to = ((BasicSubsystem) getParents().iterator().next()).getRegion();
RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder();
// Always provide visibility to this subsystem's service registration.
addSubsystemServiceImportToSharingPolicy(builder, to);
for (Resource resource : resolution.keySet()) {
if (!contentHeader.contains(resource)) {
continue;
}
// If the resource is content but the wire provider is not,
// the sharing policy must be updated.
List<Wire> wires = resolution.get(resource);
for (Wire wire : wires) {
Resource provider = wire.getProvider();
// visible.
if (contentHeader.contains(provider)) {
continue;
}
// requirements become part of the sharing policy.
if (!(wire.getCapability() instanceof DependencyCalculator.MissingCapability) && Constants.ResourceTypeSynthesized.equals(ResourceHelper.getTypeAttribute(provider))) {
continue;
}
// The requirement must be added to the sharing policy.
Requirement requirement = wire.getRequirement();
List<String> namespaces = new ArrayList<String>(2);
namespaces.add(requirement.getNamespace());
if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespaces.get(0))) {
// Both service capabilities and services must be visible.
namespaces.add(RegionFilter.VISIBLE_SERVICE_NAMESPACE);
}
String filter = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
if (filter == null) {
for (String namespace : namespaces) builder.allowAll(namespace);
} else {
for (String namespace : namespaces) builder.allow(namespace, filter);
}
}
}
// Always add access to osgi.ee and osgi.native namespaces
setImplicitAccessToNativeAndEECapabilities(builder);
// Now set the sharing policy, if the regions are different.
RegionFilter regionFilter = builder.build();
from.connectRegion(to, regionFilter);
}
use of org.eclipse.equinox.region.RegionFilterBuilder in project karaf by apache.
the class SubsystemResolver method getFlatDigraph.
@Override
public RegionDigraph getFlatDigraph() throws BundleException, InvalidSyntaxException {
if (flatDigraph == null) {
flatDigraph = new StandardRegionDigraph(null, null);
Map<String, String> flats = getFlatSubsystemsMap();
if (digraph != null) {
for (Region r : digraph.getRegions()) {
if (r.getName().equals(flats.get(r.getName()))) {
flatDigraph.createRegion(r.getName());
}
}
for (Region r : digraph.getRegions()) {
for (RegionDigraph.FilteredRegion fr : digraph.getEdges(r)) {
String rt = flats.get(r.getName());
String rh = flats.get(fr.getRegion().getName());
if (!rh.equals(rt)) {
Region tail = flatDigraph.getRegion(rt);
Region head = flatDigraph.getRegion(rh);
RegionFilterBuilder rfb = flatDigraph.createRegionFilterBuilder();
for (Map.Entry<String, Collection<String>> entry : fr.getFilter().getSharingPolicy().entrySet()) {
// Discard osgi.identity namespace
if (!IDENTITY_NAMESPACE.equals(entry.getKey())) {
for (String f : entry.getValue()) {
rfb.allow(entry.getKey(), f);
}
}
}
flatDigraph.connect(tail, rfb.build(), head);
}
}
}
}
}
return flatDigraph;
}
Aggregations