org.osgi.framework.BundleEvent#STARTED源码实例Demo

下面列出了org.osgi.framework.BundleEvent#STARTED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    try {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);

        if (event.getType() == BundleEvent.STARTED) {
            addUIPermissionFromBundle(bundle);
        }
    } catch (Exception e) {
        log.error("Error occured when processing component xml in bundle " +
                bundle.getSymbolicName(), e);
    }
}
 
源代码2 项目: knopflerfish.org   文件: SCR.java
/**
 * Process bundle components when it starts.
 */
public void bundleChanged(BundleEvent event) {
  postponeCheckin();
  try {
    final Bundle bundle = event.getBundle();

    switch (event.getType()) {
    case BundleEvent.LAZY_ACTIVATION:
      lazy.add(bundle);
      processBundle(bundle);
      break;
    case BundleEvent.STARTED:
      if (!lazy.remove(bundle)) {
        processBundle(bundle);
      }
      break;
    case BundleEvent.STOPPING:
      lazy.remove(bundle);
      removeBundle(bundle, ComponentConstants.DEACTIVATION_REASON_BUNDLE_STOPPED);
      break;
    }
  } finally {
    postponeCheckout();
  }
}
 
源代码3 项目: ACDD   文件: BundleImpl.java
public synchronized void startBundle() throws BundleException {
    if (this.state == BundleEvent.INSTALLED) {
        throw new IllegalStateException("Cannot start uninstalled bundle "
                + toString());
    } else if (this.state != BundleEvent.RESOLVED) {
        if (this.state == BundleEvent.STARTED) {
            resolveBundle(true);
        }
        this.state = BundleEvent.UPDATED;
        try {

            isValid = true;
            this.state = BundleEvent.RESOLVED;
            Framework.notifyBundleListeners(BundleEvent.STARTED, this);
            if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
                log.info("Framework: Bundle " + toString() + " started.");
            }
        } catch (Throwable th) {

            Framework.clearBundleTrace(this);
            this.state = BundleEvent.STOPPED;
            String msg = "Error starting bundle " + toString();
            log.error(msg,th);
        }
    }
}
 
@Override
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    try {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);

        if (event.getType() == BundleEvent.STARTED) {
            addUIPermissionFromBundle(bundle);
        }
    } catch (Exception e) {
        log.error("Error occured when processing component xml in bundle " +
                bundle.getSymbolicName(), e);
    }
}
 
源代码5 项目: activiti6-boot2   文件: Extender.java
public void bundleChanged(BundleEvent event) {
  Bundle bundle = event.getBundle();
  if (event.getType() == BundleEvent.RESOLVED) {
    checkBundle(bundle);
  } else if (event.getType() == BundleEvent.STARTED) {
    checkBundleScriptEngines(bundle);
  }
}
 
源代码6 项目: incubator-tamaya   文件: OSGIServiceLoader.java
@Override
public void bundleChanged(BundleEvent bundleEvent) {
    // Parse and createObject metadata when installed
    Bundle bundle = bundleEvent.getBundle();
    if (bundleEvent.getType() == BundleEvent.STARTED) {
        checkAndLoadBundle(bundle);
    } else if (bundleEvent.getType() == BundleEvent.STOPPED) {
        checkAndUnloadBundle(bundle);
    }
}
 
源代码7 项目: siddhi   文件: SiddhiExtensionLoader.java
@Override
public void bundleChanged(BundleEvent bundleEvent) {
    if (bundleEvent.getType() == BundleEvent.STARTED) {
        addExtensions(bundleEvent.getBundle());
    } else {
        removeExtensions(bundleEvent.getBundle());
    }
}
 
源代码8 项目: flowable-engine   文件: Extender.java
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    if (event.getType() == BundleEvent.RESOLVED) {
        checkBundle(bundle);
    } else if (event.getType() == BundleEvent.STARTED) {
        checkBundleScriptEngines(bundle);
    }
}
 
源代码9 项目: carbon-commons   文件: JRxmlFileBundleListener.java
public void bundleChanged(BundleEvent bundleEvent) {
    Bundle bundle = bundleEvent.getBundle();
    try {
        if (bundleEvent.getType() == BundleEvent.STARTED) {
            addJrXmlToRegistry(bundle);
        }
    } catch (Exception e) {
        log.error("Error occurred when putting jrXml file to registry in bundle "
                + bundle.getSymbolicName(), e);
    }
}
 
源代码10 项目: knopflerfish.org   文件: LogFrameworkListener.java
/**
  * The bundle event callback method inserts all bundle events into the
  * log. Events are all assigned the log level info.
  * 
  * @param be
  *            the bundle event that has occured.
  */
 public void bundleChanged(BundleEvent be) {
     String msg = null;
     switch (be.getType()) {
     case BundleEvent.INSTALLED:
         msg = "BundleEvent INSTALLED";
         break;
     case BundleEvent.STARTED:
         msg = "BundleEvent STARTED";
         break;
     case BundleEvent.STOPPED:
         msg = "BundleEvent STOPPED";
         break;
     case BundleEvent.UNINSTALLED:
         msg = "BundleEvent UNINSTALLED";
         break;
     case BundleEvent.UPDATED:
         msg = "BundleEvent UPDATED";
         break;
     case BundleEvent.RESOLVED:
         msg = "BundleEvent RESOLVED";
         break;  
     case BundleEvent.UNRESOLVED:
         msg = "BundleEvent UNRESOLVED";
         break;
/*     case BundleEvent.STARTING:
         msg = "BundleEvent STARTING";
         break;
     case BundleEvent.STOPPING:
         msg = "BundleEvent STOPPING";
         break;  
         */   
     }
     lrsf.log(new LogEntryImpl(be.getBundle(), LogService.LOG_INFO, msg));
 }
 
源代码11 项目: sis   文件: OSGiActivator.java
/**
 * Invoked when an other module has been installed or un-installed.
 * This method notifies the Apache SIS library that the classpath may have changed.
 *
 * @param  event  the event that describe the life-cycle change.
 */
@Override
public void bundleChanged(final BundleEvent event) {
    switch (event.getType()) {
        case BundleEvent.STARTED: {
            SystemListener.fireClasspathChanged();
            break;
        }
        case BundleEvent.STOPPED: {
            SystemListener.fireClasspathChanged();
            SystemListener.removeModule(event.getBundle().getSymbolicName());
            break;
        }
    }
}
 
源代码12 项目: knopflerfish.org   文件: Util.java
public static String bundleEventName(int type)
{
  switch (type) {
  case BundleEvent.INSTALLED:
    return "installed";
  case BundleEvent.STARTED:
    return "started";
  case BundleEvent.STOPPED:
    return "stopped";
  case BundleEvent.UNINSTALLED:
    return "uninstalled";
  case BundleEvent.UPDATED:
    return "updated";
  case BundleEvent.RESOLVED:
    return "resolved";
  case BundleEvent.UNRESOLVED:
    return "unresolved";
  case BundleEvent.STARTING:
    return "starting";
  case BundleEvent.STOPPING:
    return "stopping";
  case BundleEvent.LAZY_ACTIVATION:
    return "lazyActivation";
  default:
    return "<" + type + ">";
  }
}
 
private BundleEvent initializeEvent(Bundle bundle) {
    switch (bundle.getState()) {
        case Bundle.INSTALLED:
            return new BundleEvent(BundleEvent.INSTALLED, bundle);
        case Bundle.RESOLVED:
            return new BundleEvent(BundleEvent.RESOLVED, bundle);
        default:
            return new BundleEvent(BundleEvent.STARTED, bundle);
    }
}
 
源代码14 项目: ACDD   文件: Framework.java
@Override
public void setBundleStartLevel(Bundle bundle, int level) {
    if (bundle == this) {
        throw new IllegalArgumentException("Cannot set the start level for the system bundle.");
    }
    BundleImpl bundleImpl = (BundleImpl) bundle;
    if (bundleImpl.state == BundleEvent.INSTALLED) {
        throw new IllegalArgumentException("Bundle " + bundle + " has been uninstalled");
    } else if (level <= 0) {
        throw new IllegalArgumentException("Start level " + level + " is not Component valid level");
    } else {
        bundleImpl.currentStartlevel = level;
        bundleImpl.updateMetadata();
        if (level <= Framework.startlevel && bundle.getState() != BundleEvent.RESOLVED && bundleImpl.persistently) {
            try {
                bundleImpl.startBundle();
            } catch (Throwable e) {
                e.printStackTrace();
                Framework.notifyFrameworkListeners(BundleEvent.STARTED, bundle, e);
            }
        } else if (level <= Framework.startlevel) {
        } else {
            if (bundle.getState() != BundleEvent.STOPPED || bundle.getState() != BundleEvent.STARTED) {
                try {
                    bundleImpl.stopBundle();
                } catch (Throwable e2) {
                    Framework.notifyFrameworkListeners(BundleEvent.STARTED, bundle, e2);
                }
            }
        }
    }
}
 
源代码15 项目: micro-integrator   文件: BundleCheckActivator.java
public void start(final BundleContext bundleContext) throws Exception {

		/*
         * Check for the services that should be deployed before this if there
		 * are any.
		 * if there are such services we wait for such bundles to deploy and
		 * gets the notification
		 * through a service listener.
		 */

        // first check whether there are such services and they have already
        // deployed.
        String pendingBundleName = null;
        final List<Bundle> pendingBundles = new ArrayList<Bundle>();
        for (Bundle bundle : bundleContext.getBundles()) {
            pendingBundleName = (String) bundle.getHeaders().get(DEPLOY_BEFORE);
            if ((pendingBundleName != null) && (pendingBundleName.equals(getName())) &&
                    (bundle.getState() != Bundle.ACTIVE)) {
                // i.e this bundle should be started before the user manager but
                // yet has not started
                pendingBundles.add(bundle);
            }
        }

        if (pendingBundles.isEmpty()) {
            startDeploy(bundleContext);
        } else {
            BundleListener bundleListener = new BundleListener() {
                public void bundleChanged(BundleEvent bundleEvent) {
                    synchronized (pendingBundles) {
                        if (bundleEvent.getType() == BundleEvent.STARTED) {

                            pendingBundles.remove(bundleEvent.getBundle());
                            if (pendingBundles.isEmpty()) {
                                // now start the user manager deployment
                                bundleContext.removeBundleListener(this);
                                try {
                                    startDeploy(bundleContext);
                                } catch (Exception e) {
                                    log.error("Can not start the bundle ", e);
                                }
                            }
                        }
                    }
                }
            };
            bundleContext.addBundleListener(bundleListener);
        }
    }
 
源代码16 项目: netbeans   文件: Netigso.java
final void notifyBundleChange(final String symbolicName, final Version version, final int action) {
    final Exception stack = Netigso.LOG.isLoggable(Level.FINER) ? new Exception("StackTrace") : null;
    final Runnable doLog = new Runnable() {
        @Override
        public void run() {
            if (isEnabled(symbolicName)) {
                return;
            }
            final Mutex mutex = Main.getModuleSystem().getManager().mutex();
            if (!mutex.isReadAccess()) {
                mutex.postReadRequest(this);
                return;
            }
            String type = "" + action;
            Level notify = Level.INFO;
            switch (action) {
                case BundleEvent.INSTALLED:
                    return; // no message for installed
                case BundleEvent.RESOLVED:
                    type = "resolved";
                    break;
                case BundleEvent.STARTED:
                    type = "started";
                    break;
                case BundleEvent.STOPPED:
                    type = "stopped";
                    break;
                case BundleEvent.UNINSTALLED:
                    return; // nothing for uninstalled
                case BundleEvent.LAZY_ACTIVATION:
                    type = "lazy";
                    notify = Level.FINEST;
                    break;
                case BundleEvent.STARTING:
                    type = "starting";
                    notify = Level.FINEST;
                    break;
            }
            Netigso.LOG.log(notify, "bundle {0}@{2} {1}", new Object[]{
                        symbolicName, type, version
                    });
            if (stack != null) {
                Netigso.LOG.log(Level.FINER, null, stack);
            }
        }
    };
    RP.post(doLog);
}
 
/**
 * Scan classpaths for given package name (and sub packages) to scan for and
 * register all classes with @Model annotation.
 */
public static void addModelsForPackage(BundleContext bundleContext, Class... classes) {
    Bundle bundle = new ModelsPackageBundle(classes, Bundle.ACTIVE, bundleContext);
    BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
    MockOsgi.sendBundleEvent(bundleContext, event);
}
 
源代码18 项目: knopflerfish.org   文件: MultiListener.java
/**
 * A listener for events sent by bundles
 * @param bundleEvent The event sent by the bundle
 * @author Johnny Baveras
 */


public void bundleChanged(BundleEvent bundleEvent) {
  String topic = null;
  boolean knownMessageType = true;

  switch (bundleEvent.getType()) {
  case BundleEvent.INSTALLED:
    topic = INSTALLED_TOPIC;
    break;
  case BundleEvent.STARTED:
    topic = STARTED_TOPIC;
    break;
  case BundleEvent.STOPPED:
    topic = STOPPED_TOPIC;
    break;
  case BundleEvent.UPDATED:
    topic = UPDATED_TOPIC;
    break;
  case BundleEvent.UNINSTALLED:
    topic = UNINSTALLED_TOPIC;
    break;
  case BundleEvent.RESOLVED:
    topic = RESOLVED_TOPIC;
    break;
  case BundleEvent.UNRESOLVED:
    topic = UNRESOLVED_TOPIC;
    break;
  default:
    /* Setting the boolean to false if an unknown event arrives */
    knownMessageType = false;
    break;
  }


  /* Stores the properties of the event in the dictionary, if the event is known */
  if (knownMessageType) {
    if(!Activator.handlerTracker.anyHandlersMatching(topic)) {
      return;
    }
    Map<String,Object> props = new HashMap<String,Object>();
    Bundle bundle = bundleEvent.getBundle();
    putProp(props, EventConstants.EVENT, bundleEvent);
    putProp(props, "bundle.id", new Long(bundle.getBundleId()));
    putProp(props, EventConstants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName());
    putProp(props, "bundle", bundle);
    /* Tries posting the event once the properties are set */
    try {
      Activator.eventAdmin.postEvent(new Event(topic, props));
    } catch (Exception e) {
      Activator.log.error("EXCEPTION in bundleChanged()", e);
    }
  } else {
    /* Logs an error if the event, which arrived, were of an unknown type */
    Activator.log.error("Recieved unknown bundle event message (type="
              +bundleEvent.getType() +"), discarding");
  }
  // }
}
 
源代码19 项目: ACDD   文件: BundleLifecycleHandler.java
@Override
@SuppressLint({"NewApi"})
public void bundleChanged(BundleEvent bundleEvent) {
    switch (bundleEvent.getType()) {
        case BundleEvent.LOADED:
            loaded(bundleEvent.getBundle());
            break;
        case BundleEvent.INSTALLED:
            installed(bundleEvent.getBundle());
            break;
        case BundleEvent.STARTED:
            if (isLewaOS()) {
                if (Looper.myLooper() == null) {
                    Looper.prepare();
                }
                started(bundleEvent.getBundle());
            } else if (Framework.isFrameworkStartupShutdown()) {
                BundleStartTask bundleStartTask = new BundleStartTask();
                if (VERSION.SDK_INT > 11) {
                    bundleStartTask.executeOnExecutor(
                            AsyncTask.THREAD_POOL_EXECUTOR,
                            bundleEvent.getBundle());
                    return;
                }
                bundleStartTask
                        .execute(bundleEvent.getBundle());
            } else {
                started(bundleEvent.getBundle());
            }
            break;
        case BundleEvent.STOPPED:
            stopped(bundleEvent.getBundle());
            break;
        case BundleEvent.UPDATED:
            updated(bundleEvent.getBundle());
            break;
        case BundleEvent.UNINSTALLED:

        {
            uninstalled(bundleEvent.getBundle());
            break;
        }
        default:
    }
}
 
源代码20 项目: ACDD   文件: BundleImpl.java
BundleImpl(File bundleDir, String location,
               InputStream archiveInputStream, File archiveFile, boolean isInstall)
            throws BundleException, IOException {
        this.persistently = false;
        this.domain = null;
        this.registeredFrameworkListeners = null;
        this.registeredBundleListeners = null;
        long currentTimeMillis = System.currentTimeMillis();
        this.location = location;

        this.currentStartlevel = Framework.startlevel;
        this.bundleDir = bundleDir;
        if (archiveInputStream != null) {
            //  try {
            this.archive = new BundleArchive(location, bundleDir, archiveInputStream);
//            } catch (Throwable e) {
//                Framework.deleteDirectory(bundleDir);
//                throw new BundleException("Could not install bundle " + location, e);
//            }
        } else if (archiveFile != null) {
            try {
                this.archive = new BundleArchive(location, bundleDir, archiveFile);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        this.state = BundleEvent.STARTED;

        updateMetadata();
        if (isInstall) {
            Framework.bundles.put(location, this);
            resolveBundle(false);
            Framework.notifyBundleListeners(BundleEvent.INSTALLED, this);
        }

        if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
            log.info("Framework: Bundle " + toString() + " created. "
                    + (System.currentTimeMillis() - currentTimeMillis) + " ms");
        }
    }