Search in sources :

Example 26 with ServiceEvent

use of org.osgi.framework.ServiceEvent in project ddf by codice.

the class RegistryStorePublisher method handleEvent.

@Override
public void handleEvent(Event event) {
    if (((ServiceEvent) event.getProperty(EventConstants.EVENT)).getType() != ServiceEvent.MODIFIED) {
        return;
    }
    String pid = event.getProperty(Constants.SERVICE_PID).toString();
    Boolean previousAutoPush = registryStoreMap.get(pid);
    if (previousAutoPush == null) {
        return;
    }
    BundleContext bundleContext = getBundleContext();
    if (bundleContext == null) {
        return;
    }
    RegistryStore registryStore = (RegistryStore) bundleContext.getService(((ServiceEvent) event.getProperty(EventConstants.EVENT)).getServiceReference());
    if (!previousAutoPush && registryStore.isAutoPush()) {
        registryPublish(registryStore, PUBLISH);
        registryStoreMap.put(pid, true);
    } else if (previousAutoPush && !registryStore.isAutoPush()) {
        registryPublish(registryStore, UNPUBLISH);
        registryStoreMap.put(pid, false);
    }
}
Also used : RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) ServiceEvent(org.osgi.framework.ServiceEvent) BundleContext(org.osgi.framework.BundleContext)

Aggregations

ServiceEvent (org.osgi.framework.ServiceEvent)26 Test (org.junit.Test)18 BundleContext (org.osgi.framework.BundleContext)15 ServiceReference (org.osgi.framework.ServiceReference)13 Hashtable (java.util.Hashtable)9 Bundle (org.osgi.framework.Bundle)9 ServiceListener (org.osgi.framework.ServiceListener)7 HashMap (java.util.HashMap)5 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4 ServiceRegistrationHolder (org.apache.karaf.service.guard.impl.GuardProxyCatalog.ServiceRegistrationHolder)4 Dictionary (java.util.Dictionary)3 TimeoutException (java.util.concurrent.TimeoutException)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 RegistryStore (org.codice.ddf.registry.api.internal.RegistryStore)3 IAnswer (org.easymock.IAnswer)3 BundleException (org.osgi.framework.BundleException)3 ServiceRegistration (org.osgi.framework.ServiceRegistration)3 BundleWiring (org.osgi.framework.wiring.BundleWiring)3