You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by jk...@apache.org on 2023/03/01 10:50:00 UTC
[unomi] branch reduceIndicesItems3 updated: UNOMI-736: Cleanup annoying blueprint stuff
This is an automated email from the ASF dual-hosted git repository.
jkevan pushed a commit to branch reduceIndicesItems3
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/reduceIndicesItems3 by this push:
new 973d69c50 UNOMI-736: Cleanup annoying blueprint stuff
973d69c50 is described below
commit 973d69c50bd437eaf5bfa8cc934757d4d25d506c
Author: Kevan <ke...@jahia.com>
AuthorDate: Wed Mar 1 11:49:51 2023 +0100
UNOMI-736: Cleanup annoying blueprint stuff
---
extensions/groovy-actions/services/pom.xml | 1 +
.../groovy/actions/GroovyActionDispatcher.java | 6 +-
.../actions/listener/GroovyActionListener.java | 13 +++--
.../services/impl/GroovyActionsServiceImpl.java | 52 +++++++++--------
.../resources/OSGI-INF/blueprint/blueprint.xml | 68 ----------------------
5 files changed, 43 insertions(+), 97 deletions(-)
diff --git a/extensions/groovy-actions/services/pom.xml b/extensions/groovy-actions/services/pom.xml
index 8494a9938..b9b726575 100644
--- a/extensions/groovy-actions/services/pom.xml
+++ b/extensions/groovy-actions/services/pom.xml
@@ -104,6 +104,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
+ <_dsannotations>*</_dsannotations>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Unomi-Source-Folders>${project.basedir}</Unomi-Source-Folders>
<DynamicImport-Package>*</DynamicImport-Package>
diff --git a/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/GroovyActionDispatcher.java b/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/GroovyActionDispatcher.java
index dadeabb44..f5276ab37 100644
--- a/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/GroovyActionDispatcher.java
+++ b/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/GroovyActionDispatcher.java
@@ -25,6 +25,8 @@ import org.apache.unomi.api.actions.ActionDispatcher;
import org.apache.unomi.groovy.actions.services.GroovyActionsService;
import org.apache.unomi.metrics.MetricAdapter;
import org.apache.unomi.metrics.MetricsService;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,6 +34,7 @@ import org.slf4j.LoggerFactory;
* An implementation of an ActionDispatcher for the Groovy language. This dispatcher will load the groovy action script matching to an
* actionName. If a script if found, it will be executed.
*/
+@Component(service = ActionDispatcher.class)
public class GroovyActionDispatcher implements ActionDispatcher {
private static final Logger logger = LoggerFactory.getLogger(GroovyActionDispatcher.class.getName());
@@ -39,13 +42,14 @@ public class GroovyActionDispatcher implements ActionDispatcher {
private static final String GROOVY_PREFIX = "groovy";
private MetricsService metricsService;
-
private GroovyActionsService groovyActionsService;
+ @Reference
public void setMetricsService(MetricsService metricsService) {
this.metricsService = metricsService;
}
+ @Reference
public void setGroovyActionsService(GroovyActionsService groovyActionsService) {
this.groovyActionsService = groovyActionsService;
}
diff --git a/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/listener/GroovyActionListener.java b/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/listener/GroovyActionListener.java
index bb27e1d3b..1dacf8af4 100644
--- a/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/listener/GroovyActionListener.java
+++ b/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/listener/GroovyActionListener.java
@@ -23,6 +23,10 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,6 +40,7 @@ import java.util.Enumeration;
* The description of the action will be loaded from the ActionDescriptor annotation present in the groovy file.
* The script will be stored in the ES index groovyAction
*/
+@Component(service = SynchronousBundleListener.class)
public class GroovyActionListener implements SynchronousBundleListener {
private static final Logger logger = LoggerFactory.getLogger(GroovyActionListener.class.getName());
@@ -44,15 +49,14 @@ public class GroovyActionListener implements SynchronousBundleListener {
private GroovyActionsService groovyActionsService;
private BundleContext bundleContext;
+ @Reference
public void setGroovyActionsService(GroovyActionsService groovyActionsService) {
this.groovyActionsService = groovyActionsService;
}
- public void setBundleContext(BundleContext bundleContext) {
+ @Activate
+ public void postConstruct(BundleContext bundleContext) {
this.bundleContext = bundleContext;
- }
-
- public void postConstruct() {
logger.debug("postConstruct {}", bundleContext.getBundle());
loadGroovyActions(bundleContext);
for (Bundle bundle : bundleContext.getBundles()) {
@@ -65,6 +69,7 @@ public class GroovyActionListener implements SynchronousBundleListener {
logger.info("Groovy Action Dispatcher initialized.");
}
+ @Deactivate
public void preDestroy() {
processBundleStop(bundleContext);
bundleContext.removeBundleListener(this);
diff --git a/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/services/impl/GroovyActionsServiceImpl.java b/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/services/impl/GroovyActionsServiceImpl.java
index fa31a172b..450acaa9f 100644
--- a/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/services/impl/GroovyActionsServiceImpl.java
+++ b/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/services/impl/GroovyActionsServiceImpl.java
@@ -35,7 +35,9 @@ import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.osgi.framework.BundleContext;
import org.osgi.framework.wiring.BundleWiring;
-import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.*;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,8 +57,15 @@ import static java.util.Arrays.asList;
/**
* Implementation of the GroovyActionService. Allows to create a groovy action from a groovy file
*/
+@Component(service = GroovyActionsService.class, configurationPid = "org.apache.unomi.groovy.actions")
+@Designate(ocd = GroovyActionsServiceImpl.GroovyActionsServiceConfig.class)
public class GroovyActionsServiceImpl implements GroovyActionsService {
+ @ObjectClassDefinition(name = "Groovy actions service config", description = "The configuration for the Groovy actions service")
+ public @interface GroovyActionsServiceConfig {
+ int services_groovy_actions_refresh_interval() default 1000;
+ }
+
private BundleContext bundleContext;
private GroovyScriptEngine groovyScriptEngine;
@@ -72,40 +81,28 @@ public class GroovyActionsServiceImpl implements GroovyActionsService {
private static final String BASE_SCRIPT_NAME = "BaseScript";
private static final String GROOVY_SOURCE_CODE_ID_SUFFIX = "-groovySourceCode";
- public void setBundleContext(BundleContext bundleContext) {
- this.bundleContext = bundleContext;
- }
-
- @Reference
private DefinitionsService definitionsService;
-
- @Reference
private PersistenceService persistenceService;
-
- @Reference
private SchedulerService schedulerService;
-
- @Reference
private ActionExecutorDispatcher actionExecutorDispatcher;
+ private GroovyActionsServiceConfig config;
- private Integer groovyActionsRefreshInterval = 1000;
-
+ @Reference
public void setDefinitionsService(DefinitionsService definitionsService) {
this.definitionsService = definitionsService;
}
+ @Reference
public void setPersistenceService(PersistenceService persistenceService) {
this.persistenceService = persistenceService;
}
- public void setGroovyActionsRefreshInterval(Integer groovyActionsRefreshInterval) {
- this.groovyActionsRefreshInterval = groovyActionsRefreshInterval;
- }
-
+ @Reference()
public void setSchedulerService(SchedulerService schedulerService) {
this.schedulerService = schedulerService;
}
+ @Reference
public void setActionExecutorDispatcher(ActionExecutorDispatcher actionExecutorDispatcher) {
this.actionExecutorDispatcher = actionExecutorDispatcher;
}
@@ -114,13 +111,17 @@ public class GroovyActionsServiceImpl implements GroovyActionsService {
return groovyShell;
}
- public void postConstruct() {
+ @Activate
+ public void start(GroovyActionsServiceConfig config, BundleContext bundleContext) {
logger.debug("postConstruct {}", bundleContext.getBundle());
- groovyCodeSourceMap = new HashMap<>();
- GroovyBundleResourceConnector bundleResourceConnector = new GroovyBundleResourceConnector(bundleContext);
+ this.config = config;
+ this.bundleContext = bundleContext;
+ this.groovyCodeSourceMap = new HashMap<>();
+
+ GroovyBundleResourceConnector bundleResourceConnector = new GroovyBundleResourceConnector(bundleContext);
GroovyClassLoader groovyLoader = new GroovyClassLoader(bundleContext.getBundle().adapt(BundleWiring.class).getClassLoader());
- groovyScriptEngine = new GroovyScriptEngine(bundleResourceConnector, groovyLoader);
+ this.groovyScriptEngine = new GroovyScriptEngine(bundleResourceConnector, groovyLoader);
initializeGroovyShell();
try {
@@ -132,9 +133,12 @@ public class GroovyActionsServiceImpl implements GroovyActionsService {
logger.info("Groovy action service initialized.");
}
+ @Deactivate
public void onDestroy() {
logger.debug("onDestroy Method called");
- scheduledFuture.cancel(true);
+ if (scheduledFuture != null && !scheduledFuture.isCancelled()) {
+ scheduledFuture.cancel(true);
+ }
}
/**
@@ -272,7 +276,7 @@ public class GroovyActionsServiceImpl implements GroovyActionsService {
refreshGroovyActions();
}
};
- scheduledFuture = schedulerService.getScheduleExecutorService().scheduleWithFixedDelay(task, 0, groovyActionsRefreshInterval,
+ scheduledFuture = schedulerService.getScheduleExecutorService().scheduleWithFixedDelay(task, 0, config.services_groovy_actions_refresh_interval(),
TimeUnit.MILLISECONDS);
}
}
diff --git a/extensions/groovy-actions/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/groovy-actions/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
deleted file mode 100644
index f84e50fc6..000000000
--- a/extensions/groovy-actions/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF 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.
- -->
-
-<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
- xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
-
- <cm:property-placeholder persistent-id="org.apache.unomi.groovy.actions" update-strategy="reload">
- <cm:default-properties>
- <cm:property name="services.groovy.actions.refresh.interval" value="1000"/>
- </cm:default-properties>
- </cm:property-placeholder>
-
- <reference id="metricsService" interface="org.apache.unomi.metrics.MetricsService"/>
- <reference id="definitionsService" interface="org.apache.unomi.api.services.DefinitionsService"/>
- <reference id="persistenceService" interface="org.apache.unomi.persistence.spi.PersistenceService"/>
- <reference id="schedulerService" interface="org.apache.unomi.api.services.SchedulerService"/>
- <reference id="actionExecutorDispatcher" interface="org.apache.unomi.services.actions.ActionExecutorDispatcher"/>
-
- <bean id="groovyActionsServiceImpl" class="org.apache.unomi.groovy.actions.services.impl.GroovyActionsServiceImpl"
- init-method="postConstruct" destroy-method="onDestroy">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- <property name="definitionsService" ref="definitionsService"/>
- <property name="persistenceService" ref="persistenceService"/>
- <property name="schedulerService" ref="schedulerService"/>
- <property name="actionExecutorDispatcher" ref="actionExecutorDispatcher"/>
- <property name="groovyActionsRefreshInterval" value="${services.groovy.actions.refresh.interval}"/>
- </bean>
- <service id="groovyActionsService" ref="groovyActionsServiceImpl"
- interface="org.apache.unomi.groovy.actions.services.GroovyActionsService"/>
-
- <bean id="groovyActionDispatcherImpl" class="org.apache.unomi.groovy.actions.GroovyActionDispatcher">
- <property name="metricsService" ref="metricsService"/>
- <property name="groovyActionsService" ref="groovyActionsServiceImpl"/>
- </bean>
- <service id="groovyActionDispatcher" ref="groovyActionDispatcherImpl">
- <interfaces>
- <value>org.apache.unomi.api.actions.ActionDispatcher</value>
- </interfaces>
- </service>
-
- <bean id="groovyActionListenerImpl" class="org.apache.unomi.groovy.actions.listener.GroovyActionListener"
- init-method="postConstruct" destroy-method="preDestroy">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- <property name="groovyActionsService" ref="groovyActionsServiceImpl"/>
- </bean>
- <service id="groovyActionListener" ref="groovyActionListenerImpl">
- <interfaces>
- <value>org.osgi.framework.SynchronousBundleListener</value>
- </interfaces>
- </service>
-</blueprint>