From 74995d212bdaec98140a3d2e36a730b05465e9e4 Mon Sep 17 00:00:00 2001 From: Bernd Ahlers Date: Tue, 23 Jan 2024 16:24:11 +0100 Subject: [PATCH] Remove unused OSGi extension support --- modules/siddhi-core/pom.xml | 4 -- .../siddhi/core/util/ReferenceHolder.java | 44 ------------ .../core/util/SiddhiExtensionLoader.java | 70 ------------------- pom.xml | 8 --- 4 files changed, 126 deletions(-) delete mode 100644 modules/siddhi-core/src/main/java/org/wso2/siddhi/core/util/ReferenceHolder.java diff --git a/modules/siddhi-core/pom.xml b/modules/siddhi-core/pom.xml index b4ed14f0f7..1ec315ca1e 100644 --- a/modules/siddhi-core/pom.xml +++ b/modules/siddhi-core/pom.xml @@ -77,10 +77,6 @@ com.google.code.gson gson - - org.osgi - org.osgi.core - org.atteo.classindex classindex diff --git a/modules/siddhi-core/src/main/java/org/wso2/siddhi/core/util/ReferenceHolder.java b/modules/siddhi-core/src/main/java/org/wso2/siddhi/core/util/ReferenceHolder.java deleted file mode 100644 index 0b62dbd031..0000000000 --- a/modules/siddhi-core/src/main/java/org/wso2/siddhi/core/util/ReferenceHolder.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.wso2.siddhi.core.util; - -import org.osgi.framework.BundleContext; - -/** - * Class to hold references need by siddhi bundle. - */ -public class ReferenceHolder { - private BundleContext bundleContext; //bundle context for siddhi bundle. - private static final ReferenceHolder instance = new ReferenceHolder(); - - private ReferenceHolder() { - //empty constructor to facilitate singleton. - } - - public static ReferenceHolder getInstance() { - return instance; - } - - public BundleContext getBundleContext() { - return bundleContext; - } - - public void setBundleContext(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } -} diff --git a/modules/siddhi-core/src/main/java/org/wso2/siddhi/core/util/SiddhiExtensionLoader.java b/modules/siddhi-core/src/main/java/org/wso2/siddhi/core/util/SiddhiExtensionLoader.java index 1c02262243..208315fd3f 100644 --- a/modules/siddhi-core/src/main/java/org/wso2/siddhi/core/util/SiddhiExtensionLoader.java +++ b/modules/siddhi-core/src/main/java/org/wso2/siddhi/core/util/SiddhiExtensionLoader.java @@ -20,11 +20,6 @@ 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; @@ -32,7 +27,6 @@ import org.wso2.siddhi.core.executor.incremental.IncrementalTimeGetTimeZone; import org.wso2.siddhi.core.executor.incremental.IncrementalUnixTimeFunctionExecutor; -import java.util.HashMap; import java.util.Map; /** @@ -49,22 +43,6 @@ public class SiddhiExtensionLoader { */ public static void loadSiddhiExtensions(Map 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 siddhiExtensionsMap) { - ExtensionBundleListener extensionBundleListener = new ExtensionBundleListener(siddhiExtensionsMap); - bundleContext.addBundleListener(extensionBundleListener); - extensionBundleListener.loadAllExtensions(bundleContext); } /** @@ -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 bundleExtensions = new HashMap(); - private Map siddhiExtensionsMap; - - ExtensionBundleListener(Map 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> 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); - } - } - } - } } diff --git a/pom.xml b/pom.xml index 9974d401c2..c2501d306f 100644 --- a/pom.xml +++ b/pom.xml @@ -125,13 +125,6 @@ ${metrics.version} - - - org.osgi - org.osgi.core - ${org.osgi.core.version} - - org.graylog.repackaged.siddhi @@ -373,7 +366,6 @@ 32.1.3-jre 2.10.1 3.13 - 6.0.0 4.2.22