Search in sources :

Example 1 with SharePolicy

use of org.apache.aries.subsystem.scope.SharePolicy in project aries by apache.

the class AbstractTest method addPackageImportPolicy.

protected void addPackageImportPolicy(String packageName, ScopeUpdate scopeUpdate) throws InvalidSyntaxException {
    Filter filter = bundleContext.createFilter("(osgi.wiring.package=" + packageName + ')');
    SharePolicy policy = new SharePolicy(SharePolicy.TYPE_IMPORT, "osgi.wiring.package", filter);
    Map<String, List<SharePolicy>> policyMap = scopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
    List<SharePolicy> policies = policyMap.get("osgi.wiring.package");
    if (policies == null) {
        policies = new ArrayList<SharePolicy>();
        policyMap.put("osgi.wiring.package", policies);
    }
    policies.add(policy);
}
Also used : Filter(org.osgi.framework.Filter) SharePolicy(org.apache.aries.subsystem.scope.SharePolicy) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with SharePolicy

use of org.apache.aries.subsystem.scope.SharePolicy in project aries by apache.

the class AbstractTest method addServiceExportPolicy.

protected void addServiceExportPolicy(Class<?> clazz, ScopeUpdate scopeUpdate) throws InvalidSyntaxException {
    Filter filter = bundleContext.createFilter('(' + Constants.OBJECTCLASS + '=' + clazz.getName() + ')');
    SharePolicy policy = new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter);
    Map<String, List<SharePolicy>> policyMap = scopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
    List<SharePolicy> policies = policyMap.get("scope.share.service");
    if (policies == null) {
        policies = new ArrayList<SharePolicy>();
        policyMap.put("scope.share.service", policies);
    }
    policies.add(policy);
}
Also used : Filter(org.osgi.framework.Filter) SharePolicy(org.apache.aries.subsystem.scope.SharePolicy) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with SharePolicy

use of org.apache.aries.subsystem.scope.SharePolicy in project aries by apache.

the class Scopes method insertSharePolicies.

private void insertSharePolicies(List<SharePolicy> sharePolicies, DataOutputStream dos) throws IOException {
    for (SharePolicy sharePolicy : sharePolicies) {
        dos.writeUTF(sharePolicy.getType());
        dos.writeUTF(sharePolicy.getNamespace());
        dos.writeUTF(sharePolicy.getFilter().toString());
    }
}
Also used : SharePolicy(org.apache.aries.subsystem.scope.SharePolicy)

Example 4 with SharePolicy

use of org.apache.aries.subsystem.scope.SharePolicy in project aries by apache.

the class Scopes method selectSharePolicies.

private SharePolicies selectSharePolicies(DataInputStream dis) throws InvalidSyntaxException, IOException {
    SharePolicies sharePolicies = new SharePolicies();
    while (true) {
        try {
            String type = dis.readUTF();
            String namespace = dis.readUTF();
            String filter = dis.readUTF();
            sharePolicies.addSharePolicy(new SharePolicy(type, namespace, FrameworkUtil.createFilter(filter)));
        } catch (EOFException e) {
            break;
        }
    }
    return sharePolicies;
}
Also used : SharePolicy(org.apache.aries.subsystem.scope.SharePolicy) EOFException(java.io.EOFException)

Example 5 with SharePolicy

use of org.apache.aries.subsystem.scope.SharePolicy in project aries by apache.

the class ScopeAdminTest method testPackageSharingFromTestScope.

// test sharing the helloIsolation package from the test scope.
@Test
@Ignore
public void testPackageSharingFromTestScope() throws Exception {
    // make sure we are using a framework that provides composite admin service
    assertNotNull("scope admin should not be null", scope);
    System.out.println("able to get scope admin service");
    ScopeUpdate su = scope.newScopeUpdate();
    ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
    su.getChildren().add(childScopeUpdate);
    addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
    addPackageImportPolicy("org.osgi.util.tracker", childScopeUpdate);
    Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
    final Filter filter1 = FrameworkUtil.createFilter("(&" + "(osgi.wiring.package=org.apache.aries.subsystem.example.helloIsolation)" + ")");
    final Filter filter2 = FrameworkUtil.createFilter("(&" + "(scope.share.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" + ")");
    List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
    if (packagePolicies == null) {
        packagePolicies = new ArrayList<SharePolicy>();
        sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE, packagePolicies);
    }
    packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
    List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
    if (servicePolicies == null) {
        servicePolicies = new ArrayList<SharePolicy>();
        sharePolicies.put("scope.share.service", servicePolicies);
    }
    servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter2));
    // build up installInfo object for the scope
    InstallInfo info1 = new InstallInfo("helloIsolation", new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolation/0.1-SNAPSHOT"));
    InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolationRef/0.1-SNAPSHOT"));
    List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
    bundlesToInstall.add(info1);
    bundlesToInstall.add(info2);
    // add bundles to be installed, based on subsystem content
    su.commit();
    // start all bundles in the scope scope_test1
    Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
    for (Bundle b : bundlesToStart) {
        b.start();
    }
    // install helloIsolationRef1 bundle in the root scope
    URL url1 = new URL("mvn:org.apache.aries.subsystem/org.apache.aries.subsystem.example.helloIsolationRef/0.1-SNAPSHOT");
    Bundle helloIsolationRef = bundleContext.installBundle("helloIsolationRef1-rootScope", url1.openStream());
    try {
        helloIsolationRef.start();
    } catch (Exception ex) {
        fail("should be able to start helloIsolationRef by import packages from scope_test1");
    }
    // remove helloIsolationRef
    helloIsolationRef.uninstall();
    // remove child scope
    su = scope.newScopeUpdate();
    Collection<ScopeUpdate> scopes = su.getChildren();
    childScopeUpdate = scopes.iterator().next();
    // obtain child scope admin from service registry
    // String filter = "ScopeName=scope_test1";
    Scope childScopeAdmin = childScopeUpdate.getScope();
    assertEquals(scope, childScopeAdmin.getParent());
    scopes.remove(childScopeUpdate);
    su.commit();
    assertFalse(scope.getChildren().contains(childScopeAdmin));
    su = scope.newScopeUpdate();
    assertFalse(su.getChildren().contains(childScopeUpdate));
// childScopeAdmin = null;
// try {
// childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
// } catch (Exception ex) {
// // ignore
// }
// assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) SharePolicy(org.apache.aries.subsystem.scope.SharePolicy) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Scope(org.apache.aries.subsystem.scope.Scope) Filter(org.osgi.framework.Filter) ArrayList(java.util.ArrayList) List(java.util.List) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SharePolicy (org.apache.aries.subsystem.scope.SharePolicy)11 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Filter (org.osgi.framework.Filter)9 URL (java.net.URL)5 InstallInfo (org.apache.aries.subsystem.scope.InstallInfo)5 ScopeUpdate (org.apache.aries.subsystem.scope.ScopeUpdate)5 Bundle (org.osgi.framework.Bundle)5 Scope (org.apache.aries.subsystem.scope.Scope)4 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 Test (org.junit.Test)3 BundleException (org.osgi.framework.BundleException)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 Ignore (org.junit.Ignore)2 EOFException (java.io.EOFException)1 Permission (java.security.Permission)1 HelloIsolation (org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)1 CoreOptions.mavenBundle (org.ops4j.pax.exam.CoreOptions.mavenBundle)1 BundleContext (org.osgi.framework.BundleContext)1