use of org.osgi.framework.BundleEvent in project eclipse.platform.runtime by eclipse.
the class OSGiObjectSupplier method track.
private void track(final Bundle bundle, final IRequestor requestor) {
// A _synchronous_ BundleListener asserts that the BC is un-injected,
// _before_ it becomes invalid (state-wise).
BundleListener listener = new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getBundle().equals(bundle)) {
if (requestor.isValid()) {
requestor.resolveArguments(false);
requestor.execute();
}
}
}
};
synchronized (requestor2listener) {
localBundleContext.addBundleListener(listener);
requestor2listener.put(requestor, listener);
}
}
use of org.osgi.framework.BundleEvent in project eclipse.platform.runtime by eclipse.
the class Expressions method createClassCaches.
private static void createClassCaches() {
if (fgKnownClasses == null) {
fgKnownClasses = new WeakHashMap<>();
fgNotFoundClasses = new WeakHashMap<>();
BundleContext bundleContext = ExpressionPlugin.getDefault().getBundleContext();
BundleListener listener = new BundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
// Invalidate the caches if any of the bundles is stopped
if (event.getType() == BundleEvent.STOPPED) {
synchronized (Expressions.class) {
fgKnownClasses.clear();
fgNotFoundClasses.clear();
}
}
}
};
ExpressionPlugin.fgBundleListener = listener;
bundleContext.addBundleListener(listener);
}
}
use of org.osgi.framework.BundleEvent in project smarthome by eclipse.
the class XmlDocumentBundleTracker method open.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public final synchronized void open() {
relevantBundlesTracker = new BundleTracker(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null) {
@Override
public Object addingBundle(Bundle bundle, BundleEvent event) {
return isBundleRelevant(bundle) ? bundle : null;
}
};
relevantBundlesTracker.open();
super.open();
}
use of org.osgi.framework.BundleEvent in project smarthome by eclipse.
the class AutomationResourceBundlesEventQueue method run.
/**
* When a new event for a bundle providing automation resources is received, this will causes a creation of a new
* thread if there is no other created yet. If the thread already exists, then it will be notified for the event.
* Starting the thread will cause the execution of this method in separate thread.
* <p>
* The general contract of this method <code>run</code> is invoking of the
* {@link #processBundleChanged(BundleEvent)} method and executing it in separate thread.
*
* @see java.lang.Thread#run()
*/
@Override
public void run() {
boolean waitForEvents = true;
while (true) {
List<BundleEvent> lQueue = null;
synchronized (this) {
if (closed) {
notifyAll();
return;
}
if (queue.isEmpty()) {
if (waitForEvents) {
try {
wait(180000);
} catch (Throwable t) {
}
waitForEvents = false;
continue;
}
running = false;
runningThread = null;
notifyAll();
return;
}
lQueue = queue;
shared = true;
}
Iterator<BundleEvent> events = lQueue.iterator();
while (events.hasNext()) {
BundleEvent event = events.next();
try {
processBundleChanged(event);
synchronized (this) {
if (closed) {
notifyAll();
return;
}
}
} catch (Throwable t) {
if (!closed && !(t instanceof IllegalStateException)) {
logger.warn("Processing bundle event {}, for automation resource bundle '{}' failed", event.getType(), event.getBundle().getSymbolicName(), t);
}
}
}
synchronized (this) {
if (shared) {
queue.clear();
}
shared = false;
waitForEvents = true;
notifyAll();
}
}
}
use of org.osgi.framework.BundleEvent in project feature-flags-for-osgi by amitjoy.
the class FeatureManagerProviderTest method testGetFeaturesFromMetatypeXMLDescriptorWithoutName.
@Test
public void testGetFeaturesFromMetatypeXMLDescriptorWithoutName() throws Exception {
final FeatureManagerProvider manager = new FeatureManagerProvider();
manager.setConfigurationAdmin(configurationAdmin);
manager.setMetaTypeService(metaTypeService);
manager.activate(bundleContext1);
final MetaTypeExtender extender = manager.getExtender();
final String[] pids = new String[] { "a" };
final BundleEvent bundleEvent = new BundleEvent(BundleEvent.STARTED, bundle);
when(metaTypeService.getMetaTypeInformation(bundle)).thenReturn(metaTypeInfo);
when(metaTypeInfo.getPids()).thenReturn(pids);
when(metaTypeInfo.getObjectClassDefinition("a", null)).thenReturn(ocd);
when(ocd.getAttributeDefinitions(ALL)).thenReturn(new AttributeDefinition[] { ad });
mockADWithoutName();
when(bundleContext1.getBundle(0)).thenReturn(systemBundle);
when(bundle.getState()).thenReturn(ACTIVE);
when(bundle.getBundleContext()).thenReturn(bundleContext1);
extender.addingBundle(bundle, bundleEvent);
Thread.sleep(1000);
FeatureDTO feature = manager.getFeatures().collect(Collectors.toList()).get(0);
assertEquals(FEATURE_ID, feature.name);
assertEquals(FEATURE_ID, feature.id);
assertEquals(FEATURE_DESC, feature.description);
assertTrue(feature.isEnabled);
feature = manager.getFeatures(FEATURE_ID).findFirst().get();
assertEquals(FEATURE_ID, feature.name);
assertEquals(FEATURE_ID, feature.id);
assertEquals(FEATURE_DESC, feature.description);
assertTrue(feature.isEnabled);
feature = manager.getFeatures(FEATURE_ID).findAny().get();
assertEquals(FEATURE_ID, feature.name);
assertEquals(FEATURE_DESC, feature.description);
assertTrue(feature.isEnabled);
manager.unsetConfigurationAdmin(configurationAdmin);
manager.unsetMetaTypeService(metaTypeService);
manager.deactivate(bundleContext1);
}
Aggregations