use of org.osgi.service.coordinator.Participant in project aries by apache.
the class SubsystemResource method getRegion.
public synchronized Region getRegion() throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
if (region == null) {
region = createRegion(getId());
Coordination coordination = Activator.getInstance().getCoordinator().peek();
coordination.addParticipant(new Participant() {
@Override
public void ended(Coordination arg0) throws Exception {
// Nothing.
}
@Override
public void failed(Coordination arg0) throws Exception {
if (isScoped())
region.getRegionDigraph().removeRegion(region);
}
});
if (!isApplication()) {
setImportIsolationPolicy();
}
}
return region;
}
use of org.osgi.service.coordinator.Participant in project aries by apache.
the class SubsystemResourceInstaller method installAriesSubsystem.
private BasicSubsystem installAriesSubsystem(final BasicSubsystem subsystem) throws Exception {
addChild(subsystem);
addReference(subsystem);
addConstituent(subsystem);
addSubsystem(subsystem);
installRegionContextBundle(subsystem);
// The first event for RESOLVED (i.e. persisted) subsystems is emitted later.
if (State.INSTALLING.equals(subsystem.getState())) {
Activator.getInstance().getSubsystemServiceRegistrar().register(subsystem, this.subsystem);
coordination.addParticipant(new Participant() {
@Override
public void ended(Coordination coordination) throws Exception {
// Nothing.
}
@Override
public void failed(Coordination coordination) throws Exception {
subsystem.setState(State.INSTALL_FAILED);
subsystem.uninstall();
}
});
}
Comparator<Resource> comparator = new InstallResourceComparator();
// Install dependencies first if appropriate...
if (!subsystem.isRoot() && Utils.isProvisionDependenciesInstall(subsystem)) {
new InstallDependencies().install(subsystem, this.subsystem, coordination);
}
// Simulate installation of shared content so that necessary relationships are established.
for (Resource content : subsystem.getResource().getSharedContent()) {
ResourceInstaller.newInstance(coordination, content, subsystem).install();
}
// Now take care of the installable content.
if (State.INSTALLING.equals(subsystem.getState())) {
List<Resource> installableContent = new ArrayList<Resource>(subsystem.getResource().getInstallableContent());
Collections.sort(installableContent, comparator);
for (Resource content : installableContent) ResourceInstaller.newInstance(coordination, content, subsystem).install();
}
// in which case an INSTALLED event must be propagated.
if (State.INSTALLING.equals(subsystem.getState()) && Utils.isProvisionDependenciesInstall(subsystem)) {
subsystem.setState(State.INSTALLED);
} else {
// This is a persisted subsystem in the RESOLVED state. Emit the first service event.
Activator.getInstance().getSubsystemServiceRegistrar().register(subsystem, this.subsystem);
}
return subsystem;
}
use of org.osgi.service.coordinator.Participant in project aries by apache.
the class StartAction method setExportIsolationPolicy.
private static void setExportIsolationPolicy(final BasicSubsystem subsystem, Coordination coordination) throws InvalidSyntaxException {
if (!subsystem.isComposite())
return;
final Region from = ((BasicSubsystem) subsystem.getParents().iterator().next()).getRegion();
final Region to = subsystem.getRegion();
RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder();
setExportIsolationPolicy(builder, subsystem.getDeploymentManifest().getExportPackageHeader(), subsystem);
setExportIsolationPolicy(builder, subsystem.getDeploymentManifest().getProvideCapabilityHeader(), subsystem);
setExportIsolationPolicy(builder, subsystem.getDeploymentManifest().getSubsystemExportServiceHeader(), subsystem);
RegionFilter regionFilter = builder.build();
if (regionFilter.getSharingPolicy().isEmpty())
return;
if (logger.isDebugEnabled())
logger.debug("Establishing region connection: from=" + from + ", to=" + to + ", filter=" + regionFilter);
try {
from.connectRegion(to, regionFilter);
} catch (BundleException e) {
// been set. Bad assumption?
return;
}
coordination.addParticipant(new Participant() {
@Override
public void ended(Coordination coordination) throws Exception {
// It may be necessary to rollback the export sharing policy
// even when the coordination did not fail. For example, this
// might have been a subsystem whose export sharing policy was
// set just in case it offered dependencies for some other
// subsystem.
unsetExportIsolationPolicyIfNecessary();
}
@Override
public void failed(Coordination coordination) throws Exception {
// Nothing to do because a coordination is always ended.
}
private void unsetExportIsolationPolicyIfNecessary() throws BundleException, InvalidSyntaxException {
if (!EnumSet.of(State.INSTALLING, State.INSTALLED).contains(subsystem.getState())) {
// does not require a rollback.
return;
}
// The subsystem is either INSTALLING or INSTALLED and therefore
// requires a rollback since the export sharing policy must only
// be set upon entering the RESOLVED state.
RegionUpdater updater = new RegionUpdater(from, to);
updater.addRequirements(null);
}
});
}
use of org.osgi.service.coordinator.Participant in project aries by apache.
the class StartAction method startBundleResource.
private void startBundleResource(Resource resource, Coordination coordination) throws BundleException {
if (target.isRoot())
// root region.
return;
if (Utils.isRegionContextBundle(resource))
// The region context bundle was persistently started elsewhere.
return;
final Bundle bundle = ((BundleRevision) resource).getBundle();
if ((bundle.getState() & (Bundle.STARTING | Bundle.ACTIVE)) != 0)
return;
if (logger.isDebugEnabled()) {
int bundleStartLevel = bundle.adapt(BundleStartLevel.class).getStartLevel();
Bundle systemBundle = Activator.getInstance().getBundleContext().getBundle(0);
int fwStartLevel = systemBundle.adapt(FrameworkStartLevel.class).getStartLevel();
logger.debug("StartAction: starting bundle " + bundle.getSymbolicName() + " " + bundle.getVersion().toString() + " bundleStartLevel=" + bundleStartLevel + " frameworkStartLevel=" + fwStartLevel);
}
bundle.start(Bundle.START_TRANSIENT | Bundle.START_ACTIVATION_POLICY);
if (logger.isDebugEnabled()) {
logger.debug("StartAction: bundle " + bundle.getSymbolicName() + " " + bundle.getVersion().toString() + " started correctly");
}
if (coordination == null)
return;
coordination.addParticipant(new Participant() {
public void ended(Coordination coordination) throws Exception {
// noop
}
public void failed(Coordination coordination) throws Exception {
bundle.stop();
}
});
}
Aggregations