Package org.apache.aries.application.management.spi.framework

Examples of org.apache.aries.application.management.spi.framework.BundleFramework


      public boolean allowsUpdate(DeploymentMetadata newMetadata, DeploymentMetadata oldMetadata) {
        return true;
      }

      public void update(UpdateInfo info) throws UpdateException {
        BundleFramework fwk = info.getAppFramework();
       
        Bundle old = null;
        for (Bundle b : fwk.getBundles()) {
          if (b.getSymbolicName().equals("org.apache.aries.isolated.sample")) {
            old = b;
            break;
          }
        }
       
        if (old == null) throw new RuntimeException("Could not find old bundle");
       
        try {
          info.unregister(old);
          fwk.uninstall(old);
         
          // only contains one element at most
          Map<DeploymentContent, BundleSuggestion> suggestions =
            info.suggestBundle(info.getNewMetadata().getApplicationDeploymentContents());
         
          BundleSuggestion toInstall = suggestions.values().iterator().next();
         
          Bundle newBundle = fwk.install(toInstall, info.getApplication());
          info.register(newBundle);
          if (info.startBundles()) fwk.start(newBundle);
         
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
View Full Code Here


    }
  }

  public BundleFramework getBundleFramework(Bundle frameworkBundle)
  {
    BundleFramework framework = null;
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
      framework = _frameworks.get(frameworkBundle);
    }
    return framework;
  }
View Full Code Here

    Bundle frameworkBundle = null;

    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
      // We need to create a new isolated framework for this content and install
      // the bundles to it
      BundleFramework isolatedFramework = isolatedInstall(bundlesToInstall, _sharedBundleFramework
          .getIsolatedBundleContext(), app);

      _frameworks.put(isolatedFramework.getFrameworkBundle(), isolatedFramework);
      _frameworksByAppScope.put(app.getApplicationMetadata().getApplicationScope(), isolatedFramework);

      frameworkBundle = isolatedFramework.getFrameworkBundle();
    }

    return frameworkBundle;
  }
View Full Code Here

            app);

    /**
     * Install and start the new isolated bundle framework
     */
    BundleFramework bundleFramework = _bundleFrameworkFactory.createBundleFramework(parentCtx,
        config);

    // We should now have a bundleFramework
    if (bundleFramework != null) {

      boolean frameworkStarted = false;
      try {
        // Start the empty framework bundle
        bundleFramework.start();
        frameworkStarted = true;
      } catch (BundleException e) {
        // This may fail if the framework bundle has exports but we will retry later
      }

      /**
       * Install the bundles into the new framework
       */
     
      try {
        List<Bundle> installedBundles = new ArrayList<Bundle>();
        BundleContext frameworkBundleContext = bundleFramework.getIsolatedBundleContext();
        if (frameworkBundleContext != null) {
          for (BundleSuggestion suggestion : bundlesToBeInstalled)
            installedBundles.add(bundleFramework.install(suggestion, app));
        }
       
        // Finally, start the whole lot
        if (!frameworkStarted)
          bundleFramework.start();
      } catch (BundleException be) {
        bundleFramework.close();
        throw be;
      } catch (RuntimeException re) {
        bundleFramework.close();
        throw re;
      }
    }

    LOGGER.debug(LOG_EXIT, "isolatedInstall", bundleFramework);
View Full Code Here

  }

  public void uninstallBundle(Bundle b) throws BundleException
  {
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
      BundleFramework framework = getBundleFramework(b);
      if (framework != null) {
        framework.close();
       
        // clean up our maps so we don't leak memory
        _frameworks.remove(b);
        Iterator<BundleFramework> it = _frameworksByAppScope.values().iterator();
        while (it.hasNext()) {
View Full Code Here

  }

  public void startBundle(Bundle b) throws BundleException
  {
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
      BundleFramework framework = getBundleFramework(b);
      if (framework != null) // App Content
      {
        for (Bundle bundle : framework.getBundles())
          framework.start(bundle);
      } else // Shared bundle
      _sharedBundleFramework.start(b);
    }
  }
View Full Code Here

  }

  public void stopBundle(Bundle b) throws BundleException
  {
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
      BundleFramework framework = getBundleFramework(b);
      if (framework != null) // App Content
      {
        for (Bundle bundle : framework.getBundles())
          framework.stop(bundle);
      }
      // Do not stop shared bundles
    }
  }
View Full Code Here

    if (strategy == null)
      throw new IllegalArgumentException(
          "No UpdateStrategy supports the supplied DeploymentMetadata changes.");

    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
      final BundleFramework appFwk = _frameworksByAppScope.get(app.getApplicationMetadata().getApplicationScope());

      strategy.update(new UpdateStrategy.UpdateInfo() {

        public void register(Bundle bundle)
        {
View Full Code Here

  }

  public void uninstallBundle(Bundle b) throws BundleException
  {
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
      BundleFramework framework = getBundleFramework(b);
      if (framework != null) {       
        for (Bundle bundle : new ArrayList<Bundle>(framework.getBundles())) {
          framework.uninstall(bundle);
        }
       
        BundleContext ctx = framework.getIsolatedBundleContext();
        ServiceReference ref = ctx.getServiceReference(PackageAdmin.class.getName());
        if (ref != null) {
          try {
            PackageAdmin pa = (PackageAdmin) ctx.getService(ref);
            if (pa != null) {
              final Semaphore sem = new Semaphore(0);
              FrameworkListener listener = new FrameworkListener() {
                public void frameworkEvent(FrameworkEvent event)
                {
                  if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
                    sem.release();
                  }
                }
              };
       
              ctx.addFrameworkListener(listener);
              pa.refreshPackages(null);
       
              try {
                sem.tryAcquire(60, TimeUnit.SECONDS);
              } catch (InterruptedException ie) {}
       
              ctx.removeFrameworkListener(listener);
            }
          } finally {
            ctx.ungetService(ref);
          }
        }
       
        framework.close();
       
        // clean up our maps so we don't leak memory
        _frameworks.remove(b);
        Iterator<BundleFramework> it = _frameworksByAppScope.values().iterator();
        while (it.hasNext()) {
View Full Code Here

  }

  public void startBundle(Bundle b) throws BundleException
  {
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
      BundleFramework framework = getBundleFramework(b);
           
      // Start all bundles inside the framework
      if (framework != null) // App Content
      {       
        framework.start();
       
        for (Bundle bundle : framework.getBundles())
          framework.start(bundle);
       
      } else // Shared bundle
      _sharedBundleFramework.start(b);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.aries.application.management.spi.framework.BundleFramework

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.