use of org.osgi.service.event.Event in project ddf by codice.
the class NotificationControllerTest method testHandleEventThrowsIllegalArgumentExceptionOnEmptyTitle.
/**
* Test method for {@link NotificationController#handleEvent(org.osgi.service.event.Event)}
* <p>
* Verifies that {@code IllegalArgumentException} is thrown when {@code Event}'s
* {@link Notification#NOTIFICATION_KEY_TITLE property is empty.
*/
@Test(expected = IllegalArgumentException.class)
public void testHandleEventThrowsIllegalArgumentExceptionOnEmptyTitle() {
testEventProperties.put(Notification.NOTIFICATION_KEY_TITLE, "");
notificationController.handleEvent(new Event(Notification.NOTIFICATION_TOPIC_BROADCAST, testEventProperties));
}
use of org.osgi.service.event.Event in project sling by apache.
the class MockAdapterManagerImpl 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 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;
}
// DISABLED IN THIS COPY OF CLASS
/*
for (String clazz : adaptables) {
if (!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 (!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<String, Object>();
props.put(SlingConstants.PROPERTY_ADAPTABLE_CLASSES, adaptables);
props.put(SlingConstants.PROPERTY_ADAPTER_CLASSES, adapters);
ServiceRegistration adaptionRegistration = this.context.getBundleContext().registerService(Adaption.class.getName(), 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));
}
}
use of org.osgi.service.event.Event in project sling by apache.
the class Activator method issueConsoleLog.
/**
* @deprecated This should not be used directly to communicate with the client . There is no direct replacement
*/
@Deprecated
public void issueConsoleLog(String actionType, String path, String message) {
Map<String, Object> props = new HashMap<>();
props.put(CommandExecutionProperties.RESULT_TEXT, message);
props.put(CommandExecutionProperties.ACTION_TYPE, actionType);
props.put(CommandExecutionProperties.ACTION_TARGET, path);
props.put(CommandExecutionProperties.TIMESTAMP_START, System.currentTimeMillis());
props.put(CommandExecutionProperties.TIMESTAMP_END, System.currentTimeMillis());
Event event = new Event(CommandExecutionProperties.REPOSITORY_TOPIC, props);
getEventAdmin().postEvent(event);
}
use of org.osgi.service.event.Event in project sling by apache.
the class TracingCommand method execute.
@Override
public Result<T> execute() {
long start = System.currentTimeMillis();
Result<T> result = command.execute();
long end = System.currentTimeMillis();
if (eventAdmin != null) {
Map<String, Object> props = new HashMap<>();
props.put(CommandExecutionProperties.RESULT_TEXT, result.toString());
props.put(CommandExecutionProperties.RESULT_STATUS, result.isSuccess());
try {
result.get();
} catch (RepositoryException e) {
props.put(CommandExecutionProperties.RESULT_THROWABLE, e);
}
props.put(CommandExecutionProperties.ACTION_TYPE, command.getClass().getSimpleName());
Set<CommandExecutionFlag> flags = command.getFlags();
if (!flags.isEmpty()) {
StringBuilder flagsString = new StringBuilder();
for (CommandExecutionFlag flag : flags) {
flagsString.append(flag).append(',');
}
flagsString.deleteCharAt(flagsString.length() - 1);
props.put(CommandExecutionProperties.ACTION_FLAGS, flagsString.toString());
}
props.put(CommandExecutionProperties.ACTION_TARGET, command.getPath());
props.put(CommandExecutionProperties.TIMESTAMP_START, start);
props.put(CommandExecutionProperties.TIMESTAMP_END, end);
Event event = new Event(CommandExecutionProperties.REPOSITORY_TOPIC, props);
eventAdmin.postEvent(event);
}
return result;
}
use of org.osgi.service.event.Event in project sling by apache.
the class AbstractFailOnUnexpectedEventsRule method after.
protected void after() throws InterruptedException {
if (registration != null) {
registration.unregister();
}
waitForEventsToSettle();
if (unexpectedEvents.isEmpty()) {
return;
}
StringBuilder desc = new StringBuilder();
desc.append(getClass().getSimpleName() + " : " + unexpectedEvents.size() + " unexpected events captured:");
for (Event event : unexpectedEvents) {
String flags = (String) event.getProperty(CommandExecutionProperties.ACTION_FLAGS);
desc.append('\n');
desc.append(event.getProperty(CommandExecutionProperties.ACTION_TYPE));
if (flags != null && flags.length() > 0) {
desc.append(" (").append(flags).append(")");
}
desc.append(" -> ");
desc.append(event.getProperty(CommandExecutionProperties.ACTION_TARGET));
desc.append(" : ");
desc.append(event.getProperty(CommandExecutionProperties.RESULT_TEXT));
}
fail(desc.toString());
}
Aggregations