use of org.osgi.service.event.EventAdmin in project sling by apache.
the class MockEventAdminTest method testSendEvent_Other3.
@Test
public void testSendEvent_Other3() {
EventAdmin eventAdmin = context.getService(EventAdmin.class);
eventAdmin.sendEvent(EVENT_OTHER_3);
assertEquals(ImmutableList.of(), eventHandler1.getReceivedEvents());
assertEquals(ImmutableList.of(), eventHandler12.getReceivedEvents());
assertEquals(ImmutableList.of(), eventHandlerSampleAll.getReceivedEvents());
assertEquals(ImmutableList.of(EVENT_OTHER_3), eventHandlerAll.getReceivedEvents());
}
use of org.osgi.service.event.EventAdmin in project sling by apache.
the class MockEventAdminTest method testSendEvent_Sample2.
@Test
public void testSendEvent_Sample2() {
EventAdmin eventAdmin = context.getService(EventAdmin.class);
eventAdmin.sendEvent(EVENT_SAMPLE_2);
assertEquals(ImmutableList.of(), eventHandler1.getReceivedEvents());
assertEquals(ImmutableList.of(EVENT_SAMPLE_2), eventHandler12.getReceivedEvents());
assertEquals(ImmutableList.of(EVENT_SAMPLE_2), eventHandlerSampleAll.getReceivedEvents());
assertEquals(ImmutableList.of(EVENT_SAMPLE_2), eventHandlerAll.getReceivedEvents());
}
use of org.osgi.service.event.EventAdmin in project sling by apache.
the class MockEventAdminTest method testPostEvents.
@Test(timeout = 2000)
public void testPostEvents() {
EventAdmin eventAdmin = context.getService(EventAdmin.class);
eventAdmin.postEvent(EVENT_SAMPLE_2);
eventAdmin.postEvent(EVENT_OTHER_3);
// wait until result is as expected (with timeout)
boolean expectedResult = false;
while (!expectedResult) {
expectedResult = ObjectUtils.equals(ImmutableList.of(), eventHandler1.getReceivedEvents()) && ObjectUtils.equals(ImmutableList.of(EVENT_SAMPLE_2), eventHandler12.getReceivedEvents()) && ObjectUtils.equals(ImmutableList.of(EVENT_SAMPLE_2), eventHandlerSampleAll.getReceivedEvents()) && ObjectUtils.equals(ImmutableList.of(EVENT_SAMPLE_2, EVENT_OTHER_3), eventHandlerAll.getReceivedEvents());
}
}
use of org.osgi.service.event.EventAdmin in project sling by apache.
the class MockAdapterManagerImpl method unregisterAdapterFactory.
/**
* Check that the package containing the class is exported or is a java.*
* class.
*
* @param packageAdmin the PackageAdmin service
* @param clazz the class name
* @return true if the package is exported
*/
// DISABLED IN THIS COPY OF CLASS
/*
static boolean checkPackage(PackageAdmin packageAdmin, String clazz) {
final String packageName = getPackageName(clazz);
if (packageName.startsWith("java.")) {
return true;
}
return packageAdmin.getExportedPackage(packageName) != null;
}
*/
/**
* Unregisters the {@link AdapterFactory} referred to by the service
* <code>reference</code> from the registry.
*/
private void unregisterAdapterFactory(final ServiceReference reference) {
synchronized (this.boundAdapterFactories) {
boundAdapterFactories.remove(reference);
}
final String[] adaptables = PropertiesUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
final String[] adapters = PropertiesUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
if (adaptables == null || adaptables.length == 0 || adapters == null || adapters.length == 0) {
return;
}
boolean factoriesModified = false;
AdapterFactoryDescriptorMap adfMap = null;
AdapterFactoryDescriptor removedDescriptor = null;
for (final String adaptable : adaptables) {
synchronized (this.descriptors) {
adfMap = this.descriptors.get(adaptable);
}
if (adfMap != null) {
synchronized (adfMap) {
AdapterFactoryDescriptor factoryDesc = adfMap.remove(reference);
if (factoryDesc != null) {
factoriesModified = true;
// Since the code paths above does not fully guarantee it though, let's keep this check in place
if (removedDescriptor != null && removedDescriptor != factoryDesc) {
log.error("When unregistering reference {} got duplicate service descriptors {} and {}. Unregistration of {} services may be incomplete.", new Object[] { reference, removedDescriptor, factoryDesc, Adaption.class.getName() });
}
removedDescriptor = factoryDesc;
}
}
}
}
// removed
if (factoriesModified) {
this.factoryCache.clear();
}
// unregister adaption
if (removedDescriptor != null) {
removedDescriptor.getAdaption().unregister();
if (log.isDebugEnabled()) {
log.debug("Unregistered service {} with {} : {} and {} : {}", new Object[] { Adaption.class.getName(), SlingConstants.PROPERTY_ADAPTABLE_CLASSES, Arrays.toString(adaptables), SlingConstants.PROPERTY_ADAPTER_CLASSES, Arrays.toString(adapters) });
}
}
// send event
final EventAdmin localEA = this.eventAdmin;
if (localEA != null) {
final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(SlingConstants.PROPERTY_ADAPTABLE_CLASSES, adaptables);
props.put(SlingConstants.PROPERTY_ADAPTER_CLASSES, adapters);
localEA.postEvent(new Event(SlingConstants.TOPIC_ADAPTER_FACTORY_REMOVED, props));
}
}
use of org.osgi.service.event.EventAdmin in project ddf by codice.
the class SendCommand method sendNotification.
private void sendNotification() throws Exception {
Long sysTimeMillis = System.currentTimeMillis();
String id = UUID.randomUUID().toString().replaceAll("-", "");
String sessionId = "mockSessionId";
Notification notification = new Notification(id, sessionId, application, title, message, sysTimeMillis, userId);
notification.put("status", "Started");
notification.put("bytes", "12345");
Event event = new Event(Notification.NOTIFICATION_TOPIC_DOWNLOADS, notification);
// Get OSGi Event Admin service
EventAdmin eventAdmin;
@SuppressWarnings("rawtypes") ServiceReference[] serviceReferences = bundleContext.getServiceReferences(SERVICE_PID, null);
if (serviceReferences == null || serviceReferences.length != 1) {
LOGGER.debug("Found no service references for {}", SERVICE_PID);
} else {
LOGGER.debug("Found " + serviceReferences.length + " service references for " + SERVICE_PID);
eventAdmin = (EventAdmin) bundleContext.getService(serviceReferences[0]);
if (eventAdmin != null) {
eventAdmin.postEvent(event);
}
}
}
Aggregations