Search in sources :

Example 6 with RegionFilterBuilder

use of org.eclipse.equinox.region.RegionFilterBuilder 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 7 with RegionFilterBuilder

use of org.eclipse.equinox.region.RegionFilterBuilder in project aries by apache.

the class RegionUpdater method addHeadRegions.

private void addHeadRegions(Map<String, RegionFilterBuilder> heads, Region tail, RegionDigraph digraph) throws BundleException {
    for (Map.Entry<String, RegionFilterBuilder> entry : heads.entrySet()) {
        RegionFilterBuilder builder = entry.getValue();
        if (builder == null) {
            continue;
        }
        tail.connectRegion(digraph.getRegion(entry.getKey()), builder.build());
    }
}
Also used : RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with RegionFilterBuilder

use of org.eclipse.equinox.region.RegionFilterBuilder in project karaf by apache.

the class BundleInstallSupportImpl method replaceDigraph.

/* (non-Javadoc)
     * @see org.apache.karaf.features.internal.service.Regions#replaceDigraph(java.util.Map, java.util.Map)
     */
@Override
public void replaceDigraph(Map<String, Map<String, Map<String, Set<String>>>> policies, Map<String, Set<Long>> bundles) throws BundleException, InvalidSyntaxException {
    RegionDigraph temp = digraph.copy();
    // Remove everything
    for (Region region : temp.getRegions()) {
        temp.removeRegion(region);
    }
    // Re-create regions
    for (String name : policies.keySet()) {
        temp.createRegion(name);
    }
    // Dispatch bundles
    for (Map.Entry<String, Set<Long>> entry : bundles.entrySet()) {
        Region region = temp.getRegion(entry.getKey());
        for (long bundleId : entry.getValue()) {
            region.addBundle(bundleId);
        }
    }
    // Add policies
    for (Map.Entry<String, Map<String, Map<String, Set<String>>>> entry1 : policies.entrySet()) {
        Region region1 = temp.getRegion(entry1.getKey());
        for (Map.Entry<String, Map<String, Set<String>>> entry2 : entry1.getValue().entrySet()) {
            Region region2 = temp.getRegion(entry2.getKey());
            RegionFilterBuilder rfb = temp.createRegionFilterBuilder();
            for (Map.Entry<String, Set<String>> entry3 : entry2.getValue().entrySet()) {
                for (String flt : entry3.getValue()) {
                    rfb.allow(entry3.getKey(), flt);
                }
            }
            region1.connectRegion(region2, rfb.build());
        }
    }
    digraph.replace(temp);
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) HashSet(java.util.HashSet) Set(java.util.Set) Region(org.eclipse.equinox.region.Region) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RegionFilterBuilder (org.eclipse.equinox.region.RegionFilterBuilder)8 Region (org.eclipse.equinox.region.Region)7 HashMap (java.util.HashMap)3 Map (java.util.Map)3 RegionDigraph (org.eclipse.equinox.region.RegionDigraph)3 RegionFilter (org.eclipse.equinox.region.RegionFilter)3 ArrayList (java.util.ArrayList)2 StandardRegionDigraph (org.eclipse.equinox.internal.region.StandardRegionDigraph)2 BundleException (org.osgi.framework.BundleException)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Set (java.util.Set)1 ImportPackageRequirement (org.apache.aries.subsystem.core.archive.ImportPackageRequirement)1 RequireBundleRequirement (org.apache.aries.subsystem.core.archive.RequireBundleRequirement)1 RequireCapabilityRequirement (org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement)1 SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)1 SubsystemImportServiceRequirement (org.apache.aries.subsystem.core.archive.SubsystemImportServiceRequirement)1