You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/07/19 04:39:54 UTC

[GitHub] [incubator-kyuubi] ulysses-you commented on a diff in pull request #3090: [KYUUBI #3089] Support to load custom event handlers by ServiceLoader

ulysses-you commented on code in PR #3090:
URL: https://github.com/apache/incubator-kyuubi/pull/3090#discussion_r924052027


##########
kyuubi-events/src/main/scala/org/apache/kyuubi/events/EventHandlerRegister.scala:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+package org.apache.kyuubi.events
+
+import org.apache.kyuubi.Logging
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.config.KyuubiConf.{ENGINE_EVENT_LOGGERS, SERVER_EVENT_LOGGERS}
+import org.apache.kyuubi.events.handler.{EventHandler, EventHandlerLoader}
+
+trait EventHandlerRegister extends Logging {
+
+  def registerEngineEventLoggers(conf: KyuubiConf): Unit = {
+    val loggers = conf.get(ENGINE_EVENT_LOGGERS)
+    register(loggers, conf)
+  }
+
+  def registerServiceEventLoggers(conf: KyuubiConf): Unit = {
+    val loggers = conf.get(SERVER_EVENT_LOGGERS)
+    register(loggers, conf)
+  }
+
+  private def register(loggers: Seq[String], conf: KyuubiConf): Unit = {
+    loggers
+      .map(EventLoggerType.withName)
+      .foreach {
+        case EventLoggerType.SPARK =>
+          loadSparkEventHandler(conf)
+            .foreach(EventBus.register)
+
+        case EventLoggerType.JSON =>
+          loadJsonEventHandler(conf)
+            .foreach(EventBus.register)
+
+        case EventLoggerType.JDBC =>
+          loadJdbcEventHandler(conf)
+            .foreach(EventBus.register)
+
+        case EventLoggerType.CUSTOM =>
+          EventHandlerLoader.loadCustom(conf)
+            .foreach(EventBus.register)
+
+        case other =>
+          warn(s"Unsupported event logger: ${other.toString}")
+      }
+  }
+
+  protected def createSparkEventHandler(kyuubiConf: KyuubiConf)
+      : Option[EventHandler[KyuubiEvent]] = {
+    Option.empty

Review Comment:
   we should throw exception if child deos not implemet the corresponding method



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org