use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.
the class Activator method removedService.
@Override
public synchronized void removedService(ServiceReference<Object> reference, Object service) {
if (service instanceof Coordinator) {
if (service.equals(coordinator)) {
Coordinator coordinator = findAlternateServiceFor(Coordinator.class);
if (coordinator == null)
deactivate();
this.coordinator = coordinator;
}
} else if (service instanceof RegionDigraph) {
if (service.equals(regionDigraph)) {
RegionDigraph regionDigraph = findAlternateServiceFor(RegionDigraph.class);
if (regionDigraph == null)
deactivate();
this.regionDigraph = regionDigraph;
}
} else if (service instanceof Resolver) {
if (service.equals(resolver)) {
Resolver resolver = findAlternateServiceFor(Resolver.class);
if (resolver == null)
deactivate();
this.resolver = resolver;
}
} else if (service instanceof IDirectoryFinder)
finders.remove(service);
else {
if (service.equals(modelledResourceManager)) {
try {
Class clazz = getClass().getClassLoader().loadClass(MODELLED_RESOURCE_MANAGER);
Object manager = findAlternateServiceFor(clazz);
if (manager == null) {
modelledResourceManager = null;
serviceModeller = null;
} else {
modelledResourceManager = service;
serviceModeller = new ApplicationServiceModeller(service);
}
} catch (ClassNotFoundException e) {
// ignore
} catch (NoClassDefFoundError e) {
// ignore
}
}
}
}
use of org.eclipse.equinox.region.RegionDigraph 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.RegionDigraph in project aries by apache.
the class SubsystemResource method createRegion.
private Region createRegion(long id) throws BundleException {
if (!isScoped())
return getParents().iterator().next().getRegion();
Activator activator = Activator.getInstance();
RegionDigraph digraph = activator.getRegionDigraph();
if (getParents().isEmpty())
// the subsystems implementation bundle was installed.
return digraph.getRegion(activator.getBundleContext().getBundle());
String name = getSubsystemManifest().getSubsystemSymbolicNameHeader().getSymbolicName() + ';' + getSubsystemManifest().getSubsystemVersionHeader().getVersion() + ';' + getSubsystemManifest().getSubsystemTypeHeader().getType() + ';' + Long.toString(id);
Region region = digraph.getRegion(name);
// install, but there's no access to the coordination here.
if (region == null)
return digraph.createRegion(name);
return region;
}
use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.
the class SubsystemTest method removeConnectionWithParent.
protected void removeConnectionWithParent(Subsystem subsystem) throws BundleException {
Region tail = getRegion(subsystem);
RegionDigraph digraph = tail.getRegionDigraph();
RegionDigraph copy = digraph.copy();
Region tailCopy = copy.getRegion(tail.getName());
Set<Long> ids = tail.getBundleIds();
copy.removeRegion(tailCopy);
tailCopy = copy.createRegion(tailCopy.getName());
for (long id : ids) {
tailCopy.addBundle(id);
}
digraph.replace(copy);
}
use of org.eclipse.equinox.region.RegionDigraph in project karaf by apache.
the class SubsystemResolver method getFlatDigraph.
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