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

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

源代码1 项目: knopflerfish.org   文件: LogConfigImpl.java
@Override
public void bundleChanged(BundleEvent event) {
  switch (event.getType()) {
    case BundleEvent.INSTALLED: // Fall through
    case BundleEvent.UPDATED:
      computeBidFilter(bidFilters, event.getBundle());
      break;
    case BundleEvent.UNINSTALLED:
      final Long key = new Long(event.getBundle().getBundleId());
      synchronized (bidFilters) {
        bidFilters.remove(key);
      }
      break;
    default:
  }
}
 
源代码2 项目: knopflerfish.org   文件: Desktop.java
public Icon getBundleEventIcon(int type)
{
  switch (type) {
  case BundleEvent.INSTALLED:
    return installIcon;
  case BundleEvent.STARTED:
    return startIcon;
  case BundleEvent.STOPPED:
    return stopIcon;
  case BundleEvent.UNINSTALLED:
    return uninstallIcon;
  case BundleEvent.UPDATED:
    return updateIcon;
  default:
    return null;
  }
}
 
源代码3 项目: ACDD   文件: Framework.java
static void shutdown(boolean restart) {
    System.out.println("---------------------------------------------------------");
    System.out.println("  OpenAtlas OSGi shutting down ...");
    System.out.println("  Bye !");
    System.out.println("---------------------------------------------------------");
    systemBundle.state = BundleEvent.UNINSTALLED;
    systemBundle.setLevel(getBundles().toArray(new Bundle[bundles.size()]), 0, true);
    bundles.clear();
    systemBundle.state = BundleEvent.INSTALLED;
    if (restart) {
        try {
            startup();
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }
}
 
源代码4 项目: 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);
        }
    }
}
 
源代码5 项目: ACDD   文件: BundleImpl.java
@Override
public synchronized void uninstall() throws BundleException {
    if (this.state == BundleEvent.INSTALLED) {
        throw new IllegalStateException("Bundle " + toString() + " is already uninstalled.");
    }
    if (this.state == BundleEvent.RESOLVED) {
        try {
            stopBundle();
        } catch (Throwable th) {
            Framework.notifyFrameworkListeners(BundleEvent.STARTED, this, th);
        }
    }
    this.state = BundleEvent.INSTALLED;
    new File(this.bundleDir, "meta").delete();
    this.classloader.cleanup(true);
    this.classloader = null;
    Framework.bundles.remove(this);
    Framework.notifyBundleListeners(BundleEvent.UNINSTALLED, this);
    isValid = false;



}
 
源代码6 项目: M2Doc   文件: EclipseClassProvider.java
/**
 * Constructor.
 * 
 * @param context
 *            the {@link BundleContext}
 * @param classLoader
 *            the fall back {@link ClassLoader}
 */
public EclipseClassProvider(BundleContext context, ClassLoader classLoader) {
    super(classLoader);
    this.context = context;
    for (Bundle bundle : context.getBundles()) {
        bundles.put(bundle.getSymbolicName(), bundle);
    }
    listener = new BundleListener() {

        @Override
        public void bundleChanged(BundleEvent event) {
            switch (event.getType()) {
                case BundleEvent.INSTALLED:
                    bundles.put(event.getBundle().getSymbolicName(), event.getBundle());
                    break;

                case BundleEvent.UNINSTALLED:
                    bundles.remove(event.getBundle().getSymbolicName());
                    break;

                default:
                    // nothing to do here
                    break;
            }
        }
    };
    context.addBundleListener(listener);
}
 
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);
    }
}
 
源代码8 项目: 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));
 }
 
源代码9 项目: 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);
    }
}
 
@Override
public void bundleChanged(BundleEvent event)
{
  if (event.getType() == BundleEvent.UNINSTALLED) {
    final String uninstalledBundleLocation = event.getBundle().getLocation();
    existingBundleLocations.remove(uninstalledBundleLocation);
    findAndUnbindConfigurationsDynamicallyBoundTo(uninstalledBundleLocation);
  } else if (event.getType() == BundleEvent.INSTALLED) {
    final String installedBundleLocation = event.getBundle().getLocation();
    existingBundleLocations.put(installedBundleLocation,
                                installedBundleLocation);
  }
}
 
源代码12 项目: ACDD   文件: Framework.java
@Override
public boolean isBundlePersistentlyStarted(Bundle bundle) {
    if (bundle == this) {
        return true;
    }
    BundleImpl bundleImpl = (BundleImpl) bundle;
    if (bundleImpl.state != BundleEvent.INSTALLED) {
        return bundleImpl.persistently;
    }
    throw new IllegalArgumentException("Bundle " + bundle + " has been uninstalled");
}
 
源代码13 项目: ACDD   文件: SecurityBundleListner.java
public void bundleChanged(BundleEvent bundleEvent) {

        switch (bundleEvent.getType()) {
            case BundleEvent.INSTALLED:
            case BundleEvent.UPDATED:
                Message obtain = Message.obtain();
                obtain.obj = bundleEvent.getBundle().getLocation();
                this.mSecurityCheckHandler.sendMessage(obtain);
                return;
            default:
                return;
        }
    }
 
源代码14 项目: ACDD   文件: BundleImpl.java
@Override
public URL getResource(String name) {
    if (this.state != BundleEvent.INSTALLED) {
        return this.classloader.getResource(name);
    }
    throw new IllegalStateException("Bundle " + toString()
            + " has been uninstalled");
}
 
源代码15 项目: 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);
                }
            }
        }
    }
}
 
源代码16 项目: ACDD   文件: BundleImpl.java
@Override
public synchronized void update(InputStream inputStream)
        throws BundleException {
    if (this.state == BundleEvent.INSTALLED) {
        throw new IllegalStateException("Cannot update uninstalled bundle "
                + toString());
    }
    try {
        this.archive
                .newRevision(this.location, this.bundleDir, inputStream);
    } catch (Throwable e) {
        throw new BundleException("Could not update bundle " + toString(),
                e);
    }
}
 
源代码17 项目: ACDD   文件: BundleImpl.java
@Override
public synchronized void update(File bundleFile) throws BundleException {
    if (this.state == BundleEvent.INSTALLED) {
        throw new IllegalStateException("Cannot update uninstalled bundle "
                + toString());
    }
    try {
        this.archive.newRevision(this.location, this.bundleDir, bundleFile);
    } catch (Throwable e) {
        throw new BundleException("Could not update bundle " + toString(),
                e);
    }
}
 
源代码18 项目: ACDD   文件: Framework.java
@Override
public int getBundleStartLevel(Bundle bundle) {
    if (bundle == this) {
        return 0;
    }
    BundleImpl bundleImpl = (BundleImpl) bundle;
    if (bundleImpl.state != BundleEvent.INSTALLED) {
        return bundleImpl.currentStartlevel;
    }
    throw new IllegalArgumentException("Bundle " + bundle + " has been uninstalled");
}
 
源代码19 项目: 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);
}
 
源代码20 项目: 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");
  }
  // }
}