Search in sources :

Example 51 with Event

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));
}
Also used : Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 52 with Event

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));
    }
}
Also used : AdapterFactoryDescriptorMap(org.apache.sling.adapter.internal.AdapterFactoryDescriptorMap) Adaption(org.apache.sling.adapter.Adaption) EventAdmin(org.osgi.service.event.EventAdmin) AdapterFactoryDescriptor(org.apache.sling.adapter.internal.AdapterFactoryDescriptor) Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 53 with Event

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);
}
Also used : HashMap(java.util.HashMap) Event(org.osgi.service.event.Event)

Example 54 with 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;
}
Also used : CommandExecutionFlag(org.apache.sling.ide.transport.Repository.CommandExecutionFlag) HashMap(java.util.HashMap) Event(org.osgi.service.event.Event)

Example 55 with Event

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());
}
Also used : Event(org.osgi.service.event.Event)

Aggregations

Event (org.osgi.service.event.Event)142 Test (org.junit.Test)79 HashMap (java.util.HashMap)48 Hashtable (java.util.Hashtable)44 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)23 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)20 EventAdmin (org.osgi.service.event.EventAdmin)19 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)18 Predicate (ddf.catalog.pubsub.predicate.Predicate)16 ArrayList (java.util.ArrayList)16 ActivityEvent (org.codice.ddf.activities.ActivityEvent)13 EventHandler (org.osgi.service.event.EventHandler)13 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)11 Date (java.util.Date)11 Job (org.apache.sling.event.jobs.Job)9 Map (java.util.Map)8 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 JobManager (org.apache.sling.event.jobs.JobManager)7 JobConsumer (org.apache.sling.event.jobs.consumer.JobConsumer)7