Search in sources :

Example 6 with Participant

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;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) Participant(org.osgi.service.coordinator.Participant) URISyntaxException(java.net.URISyntaxException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ResolutionException(org.osgi.service.resolver.ResolutionException) SubsystemException(org.osgi.service.subsystem.SubsystemException) IOException(java.io.IOException)

Example 7 with Participant

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;
}
Also used : Participant(org.osgi.service.coordinator.Participant) Coordination(org.osgi.service.coordinator.Coordination) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList)

Example 8 with Participant

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);
        }
    });
}
Also used : RegionFilter(org.eclipse.equinox.region.RegionFilter) Participant(org.osgi.service.coordinator.Participant) Coordination(org.osgi.service.coordinator.Coordination) Region(org.eclipse.equinox.region.Region) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleException(org.osgi.framework.BundleException) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder) BundleException(org.osgi.framework.BundleException) SubsystemException(org.osgi.service.subsystem.SubsystemException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Example 9 with Participant

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();
        }
    });
}
Also used : BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) Participant(org.osgi.service.coordinator.Participant) Coordination(org.osgi.service.coordinator.Coordination) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) FrameworkStartLevel(org.osgi.framework.startlevel.FrameworkStartLevel) BundleException(org.osgi.framework.BundleException) SubsystemException(org.osgi.service.subsystem.SubsystemException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Aggregations

Participant (org.osgi.service.coordinator.Participant)9 Coordination (org.osgi.service.coordinator.Coordination)7 CoordinationException (org.osgi.service.coordinator.CoordinationException)6 IOException (java.io.IOException)5 BundleException (org.osgi.framework.BundleException)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 SubsystemException (org.osgi.service.subsystem.SubsystemException)5 ArrayList (java.util.ArrayList)3 Resource (org.osgi.resource.Resource)2 URISyntaxException (java.net.URISyntaxException)1 SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)1 Region (org.eclipse.equinox.region.Region)1 RegionFilter (org.eclipse.equinox.region.RegionFilter)1 RegionFilterBuilder (org.eclipse.equinox.region.RegionFilterBuilder)1 Bundle (org.osgi.framework.Bundle)1 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)1 FrameworkStartLevel (org.osgi.framework.startlevel.FrameworkStartLevel)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1 Coordinator (org.osgi.service.coordinator.Coordinator)1 ResolutionException (org.osgi.service.resolver.ResolutionException)1