Skip to content

Commit

Permalink
Remove unused OSGi extension support
Browse files Browse the repository at this point in the history
  • Loading branch information
bernd committed Jan 23, 2024
1 parent 9bc2313 commit 74995d2
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 126 deletions.
4 changes: 0 additions & 4 deletions modules/siddhi-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.atteo.classindex</groupId>
<artifactId>classindex</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@

import org.apache.log4j.Logger;
import org.atteo.classindex.ClassIndex;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.osgi.framework.wiring.BundleWiring;
import org.wso2.siddhi.annotation.Extension;
import org.wso2.siddhi.core.executor.incremental.IncrementalAggregateBaseTimeFunctionExecutor;
import org.wso2.siddhi.core.executor.incremental.IncrementalShouldUpdateFunctionExecutor;
import org.wso2.siddhi.core.executor.incremental.IncrementalStartTimeEndTimeFunctionExecutor;
import org.wso2.siddhi.core.executor.incremental.IncrementalTimeGetTimeZone;
import org.wso2.siddhi.core.executor.incremental.IncrementalUnixTimeFunctionExecutor;

import java.util.HashMap;
import java.util.Map;

/**
Expand All @@ -49,22 +43,6 @@ public class SiddhiExtensionLoader {
*/
public static void loadSiddhiExtensions(Map<String, Class> siddhiExtensionsMap) {
loadLocalExtensions(siddhiExtensionsMap);
BundleContext bundleContext = ReferenceHolder.getInstance().getBundleContext();
if (bundleContext != null) {
loadExtensionOSGI(bundleContext, siddhiExtensionsMap);
}
}

/**
* Load Extensions in OSGi environment.
*
* @param bundleContext OSGi bundleContext
* @param siddhiExtensionsMap reference map for the Siddhi extension
*/
private static void loadExtensionOSGI(BundleContext bundleContext, Map<String, Class> siddhiExtensionsMap) {
ExtensionBundleListener extensionBundleListener = new ExtensionBundleListener(siddhiExtensionsMap);
bundleContext.addBundleListener(extensionBundleListener);
extensionBundleListener.loadAllExtensions(bundleContext);
}

/**
Expand Down Expand Up @@ -151,52 +129,4 @@ private static void addExtensionToMap(String fqExtensionName, Class extensionCla
"loaded with the same namespace and name '" + fqExtensionName + "'");
}
}

/**
* Class to listen to Bundle changes to update available extensions.
*/
private static class ExtensionBundleListener implements BundleListener {

private Map<Class, Integer> bundleExtensions = new HashMap<Class, Integer>();
private Map<String, Class> siddhiExtensionsMap;

ExtensionBundleListener(Map<String, Class> siddhiExtensionsMap) {
this.siddhiExtensionsMap = siddhiExtensionsMap;
}

@Override
public void bundleChanged(BundleEvent bundleEvent) {
if (bundleEvent.getType() == BundleEvent.STARTED) {
addExtensions(bundleEvent.getBundle());
} else {
removeExtensions(bundleEvent.getBundle());
}
}

private void addExtensions(Bundle bundle) {
ClassLoader classLoader = bundle.adapt(BundleWiring.class).getClassLoader();
Iterable<Class<?>> extensions = ClassIndex.getAnnotated(Extension.class, classLoader);
for (Class extension : extensions) {
addExtensionToMap(extension, siddhiExtensionsMap);
bundleExtensions.put(extension, (int) bundle.getBundleId());
}
}

private void removeExtensions(Bundle bundle) {
bundleExtensions.entrySet().stream().filter(entry -> entry.getValue() ==
bundle.getBundleId()).forEachOrdered(entry -> {
siddhiExtensionsMap.remove(entry.getKey());
});
bundleExtensions.entrySet().removeIf(entry -> entry.getValue() ==
bundle.getBundleId());
}

void loadAllExtensions(BundleContext bundleContext) {
for (Bundle b : bundleContext.getBundles()) {
if (b.getState() == Bundle.ACTIVE) {
addExtensions(b);
}
}
}
}
}
8 changes: 0 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@
<version>${metrics.version}</version>
</dependency>

<!--Event Table-->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>${org.osgi.core.version}</version>
</dependency>

<!--Time-->
<dependency>
<groupId>org.graylog.repackaged.siddhi</groupId>
Expand Down Expand Up @@ -373,7 +366,6 @@
<guava.version>32.1.3-jre</guava.version>
<gson.version>2.10.1</gson.version>
<classindex.version>3.13</classindex.version>
<org.osgi.core.version>6.0.0</org.osgi.core.version>
<metrics.version>4.2.22</metrics.version>
</properties>

Expand Down

0 comments on commit 74995d2

Please sign in to comment.