laserninja commented on code in PR #10499:
URL: https://github.com/apache/gravitino/pull/10499#discussion_r2983531818


##########
core/src/main/java/org/apache/gravitino/listener/api/event/function/AlterFunctionPreEvent.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.gravitino.listener.api.event.function;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.function.FunctionChange;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event triggered before altering a function. */
+@DeveloperApi
+public class AlterFunctionPreEvent extends FunctionPreEvent {
+  private final FunctionChange[] functionChanges;
+
+  public AlterFunctionPreEvent(
+      String user, NameIdentifier identifier, FunctionChange[] 
functionChanges) {
+    super(user, identifier);
+    this.functionChanges = functionChanges;

Review Comment:
   'AlterFunctionPreEvent' now uses 'Arrays.copyOf(functionChanges, 
functionChanges.length)' in its constructor.



##########
core/src/main/java/org/apache/gravitino/listener/FunctionEventDispatcher.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * 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.gravitino.listener;
+
+import java.util.Arrays;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.catalog.FunctionDispatcher;
+import org.apache.gravitino.exceptions.FunctionAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchFunctionException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.function.Function;
+import org.apache.gravitino.function.FunctionChange;
+import org.apache.gravitino.function.FunctionDefinition;
+import org.apache.gravitino.function.FunctionType;
+import org.apache.gravitino.listener.api.event.function.AlterFunctionEvent;
+import 
org.apache.gravitino.listener.api.event.function.AlterFunctionFailureEvent;
+import org.apache.gravitino.listener.api.event.function.AlterFunctionPreEvent;
+import org.apache.gravitino.listener.api.event.function.DropFunctionEvent;
+import 
org.apache.gravitino.listener.api.event.function.DropFunctionFailureEvent;
+import org.apache.gravitino.listener.api.event.function.DropFunctionPreEvent;
+import org.apache.gravitino.listener.api.event.function.GetFunctionEvent;
+import 
org.apache.gravitino.listener.api.event.function.GetFunctionFailureEvent;
+import org.apache.gravitino.listener.api.event.function.GetFunctionPreEvent;
+import org.apache.gravitino.listener.api.event.function.ListFunctionEvent;
+import 
org.apache.gravitino.listener.api.event.function.ListFunctionFailureEvent;
+import org.apache.gravitino.listener.api.event.function.ListFunctionInfosEvent;
+import org.apache.gravitino.listener.api.event.function.ListFunctionPreEvent;
+import org.apache.gravitino.listener.api.event.function.RegisterFunctionEvent;
+import 
org.apache.gravitino.listener.api.event.function.RegisterFunctionFailureEvent;
+import 
org.apache.gravitino.listener.api.event.function.RegisterFunctionPreEvent;
+import org.apache.gravitino.listener.api.info.FunctionInfo;
+import org.apache.gravitino.utils.PrincipalUtils;
+
+/**
+ * {@code FunctionEventDispatcher} is a decorator for {@link 
FunctionDispatcher} that not only
+ * delegates function operations to the underlying dispatcher but also 
dispatches corresponding
+ * events to an {@link EventBus} after each operation is completed.
+ */
+public class FunctionEventDispatcher implements FunctionDispatcher {
+
+  private final EventBus eventBus;
+  private final FunctionDispatcher dispatcher;
+
+  /**
+   * Constructs a FunctionEventDispatcher with a specified EventBus and 
FunctionDispatcher.
+   *
+   * @param eventBus The EventBus to which events will be dispatched.
+   * @param dispatcher The underlying {@link FunctionDispatcher} that will 
perform the actual
+   *     function operations.
+   */
+  public FunctionEventDispatcher(EventBus eventBus, FunctionDispatcher 
dispatcher) {
+    this.eventBus = eventBus;
+    this.dispatcher = dispatcher;
+  }
+
+  @Override
+  public NameIdentifier[] listFunctions(Namespace namespace) throws 
NoSuchSchemaException {
+    eventBus.dispatchEvent(
+        new ListFunctionPreEvent(PrincipalUtils.getCurrentUserName(), 
namespace));

Review Comment:
   `PrincipalUtils.getCurrentUserName()` extracted to `String user]` at the 
start of all 6 `FunctionEventDispatcher` methods, matching 
`ModelEventDispatcher` pattern.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to