You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@griffin.apache.org by toyboxman <gi...@git.apache.org> on 2018/11/01 13:42:26 UTC
[GitHub] incubator-griffin pull request #444: Define griffin plain-vanilla hook.
Github user toyboxman commented on a diff in the pull request:
https://github.com/apache/incubator-griffin/pull/444#discussion_r230045266
--- Diff: service/src/main/java/org/apache/griffin/core/integration/GriffinEventListeners.java ---
@@ -0,0 +1,61 @@
+package org.apache.griffin.core.integration;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+@Configuration
+@ConfigurationProperties(prefix = "internal.event")
+public class GriffinEventListeners {
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(GriffinEventListeners.class);
+ @Value("${internal.event.listeners}")
+ private String listeners;
+
+ @Value("${internal.event.scheduler.thread.size}")
+ private int threadPoolSize;
+
+ @Bean
+ public ThreadPoolTaskExecutor getListenersScheduler() {
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ executor.setCorePoolSize(threadPoolSize);
+ executor.setMaxPoolSize(threadPoolSize * 2);
+ executor.setThreadNamePrefix("event_listener_task_scheduler");
+ executor.initialize();
+
+ return executor;
+ }
+
+ @Bean
+ public List<GriffinHook> getListenersRegistered() {
+ ArrayList<GriffinHook> hookList = new ArrayList<>();
+ if (listeners == null || listeners.isEmpty()) {
+ LOGGER.info("Disable griffin event listener for service.");
+ } else {
+ //split list of class name
+ Scanner scanner = new Scanner(listeners).useDelimiter(";");
+ while (scanner.hasNext()) {
+ String hookName = scanner.next();
+ try {
+ Class<GriffinHook> cl = (Class<GriffinHook>) Class.forName(hookName);
+ GriffinHook hook = cl.newInstance();
--- End diff --
I have no feasible/good idea to inject/load external listener now.
so I used java reflection to new listener instance.
let me think about spring inject functionality
---