use of org.osgi.service.event.EventAdmin in project camel by apache.
the class OsgiEventAdminNotifier method notify.
public void notify(EventObject event) throws Exception {
EventAdmin eventAdmin = tracker.getService();
if (eventAdmin == null) {
return;
}
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(TYPE, getType(event));
props.put(EVENT, event);
props.put(TIMESTAMP, System.currentTimeMillis());
props.put(BUNDLE, bundleContext.getBundle());
props.put(BUNDLE_SYMBOLICNAME, bundleContext.getBundle().getSymbolicName());
props.put(BUNDLE_ID, bundleContext.getBundle().getBundleId());
props.put(BUNDLE_VERSION, getBundleVersion(bundleContext.getBundle()));
try {
props.put(CAUSE, event.getClass().getMethod("getCause").invoke(event));
} catch (Throwable t) {
// ignore
}
eventAdmin.postEvent(new Event(getTopic(event), props));
}
use of org.osgi.service.event.EventAdmin in project jersey by jersey.
the class Activator method sendAdminEvent.
private void sendAdminEvent() {
ServiceReference eaRef = bc.getServiceReference(EventAdmin.class.getName());
if (eaRef != null) {
EventAdmin ea = (EventAdmin) bc.getService(eaRef);
ea.sendEvent(new Event("jersey/test/DEPLOYED", new HashMap<String, String>() {
{
put("context-path", "/");
}
}));
bc.ungetService(eaRef);
}
}
use of org.osgi.service.event.EventAdmin in project karaf by apache.
the class EventAdminListener method featureEvent.
public void featureEvent(FeatureEvent event) {
try {
EventAdmin eventAdmin = tracker.getService();
if (eventAdmin == null) {
return;
}
Dictionary<String, Object> props = new Hashtable<>();
props.put(EventConstants.TYPE, event.getType());
props.put(EventConstants.EVENT, event);
props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
props.put(EventConstants.FEATURE_NAME, event.getFeature().getName());
props.put(EventConstants.FEATURE_VERSION, event.getFeature().getVersion());
String topic;
switch(event.getType()) {
case FeatureInstalled:
topic = EventConstants.TOPIC_FEATURES_INSTALLED;
break;
case FeatureUninstalled:
topic = EventConstants.TOPIC_FEATURES_UNINSTALLED;
break;
default:
throw new IllegalStateException("Unknown features event type: " + event.getType());
}
eventAdmin.postEvent(new Event(topic, props));
} catch (IllegalStateException e) {
LOGGER.warn("Unable to post event to EventAdmin", e);
}
}
use of org.osgi.service.event.EventAdmin in project sling by apache.
the class SlingAuthenticator method postLoginEvent.
private void postLoginEvent(final AuthenticationInfo authInfo) {
final Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(SlingConstants.PROPERTY_USERID, authInfo.getUser());
properties.put(AuthenticationInfo.AUTH_TYPE, authInfo.getAuthType());
EventAdmin localEA = this.eventAdmin;
if (localEA != null) {
localEA.postEvent(new Event(AuthConstants.TOPIC_LOGIN, properties));
}
}
use of org.osgi.service.event.EventAdmin in project sling by apache.
the class AdapterManagerImpl method registerAdapterFactory.
/**
* Unregisters the {@link AdapterFactory} referred to by the service
* <code>reference</code> from the registry.
*/
private void registerAdapterFactory(final ComponentContext context, final ServiceReference<AdapterFactory> reference) {
final String[] adaptables = PropertiesUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
final String[] adapters = PropertiesUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
final boolean allowedInPrivatePackage = PropertiesUtil.toBoolean(reference.getProperty(ALLOWED_IN_PRIVATE), false);
if (adaptables == null || adaptables.length == 0 || adapters == null || adapters.length == 0) {
return;
}
for (String clazz : adaptables) {
if (!allowedInPrivatePackage && !checkPackage(packageAdmin, clazz)) {
log.warn("Adaptable class {} in factory service {} is not in an exported package.", clazz, reference.getProperty(Constants.SERVICE_ID));
}
}
for (String clazz : adapters) {
if (!allowedInPrivatePackage && !checkPackage(packageAdmin, clazz)) {
log.warn("Adapter class {} in factory service {} is not in an exported package.", clazz, reference.getProperty(Constants.SERVICE_ID));
}
}
final AdapterFactoryDescriptor factoryDesc = new AdapterFactoryDescriptor(context, reference, adapters);
for (final String adaptable : adaptables) {
AdapterFactoryDescriptorMap adfMap = null;
synchronized (this.descriptors) {
adfMap = descriptors.get(adaptable);
if (adfMap == null) {
adfMap = new AdapterFactoryDescriptorMap();
descriptors.put(adaptable, adfMap);
}
}
synchronized (adfMap) {
adfMap.put(reference, factoryDesc);
}
}
// clear the factory cache to force rebuild on next access
this.factoryCache.clear();
// register adaption
final Dictionary<String, Object> props = new Hashtable<>();
props.put(SlingConstants.PROPERTY_ADAPTABLE_CLASSES, adaptables);
props.put(SlingConstants.PROPERTY_ADAPTER_CLASSES, adapters);
ServiceRegistration<Adaption> adaptionRegistration = this.context.getBundleContext().registerService(Adaption.class, AdaptionImpl.INSTANCE, props);
if (log.isDebugEnabled()) {
log.debug("Registered service {} with {} : {} and {} : {}", new Object[] { Adaption.class.getName(), SlingConstants.PROPERTY_ADAPTABLE_CLASSES, Arrays.toString(adaptables), SlingConstants.PROPERTY_ADAPTER_CLASSES, Arrays.toString(adapters) });
}
factoryDesc.setAdaption(adaptionRegistration);
// send event
final EventAdmin localEA = this.eventAdmin;
if (localEA != null) {
localEA.postEvent(new Event(SlingConstants.TOPIC_ADAPTER_FACTORY_ADDED, props));
}
}
Aggregations