yuqi1129 commented on code in PR #4239:
URL: https://github.com/apache/gravitino/pull/4239#discussion_r1697785428


##########
core/src/main/java/org/apache/gravitino/lifecycle/LifecycleHookProxy.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.lifecycle;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.function.BiConsumer;
+
+class LifecycleHookProxy<T> implements InvocationHandler {

Review Comment:
   Perhaps it's better to name the class `DispatcherHookProxy`



##########
core/src/main/java/org/apache/gravitino/authorization/AuthorizationUtils.java:
##########
@@ -116,4 +123,65 @@ public static void checkRoleNamespace(Namespace namespace) 
{
         "Role namespace must have 3 levels, the input namespace is %s",
         namespace);
   }
+
+  public static <T> void prepareAuthorizationHooks(T manager, LifecycleHooks 
hooks) {
+    if (manager instanceof SupportsMetalakes) {

Review Comment:
   This method only hooks the event of `createXXXX`?



##########
core/src/main/java/org/apache/gravitino/lifecycle/LifecycleHookProxy.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.lifecycle;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.function.BiConsumer;
+
+class LifecycleHookProxy<T> implements InvocationHandler {
+  private final LifecycleHooks hooks;
+  private final T dispatcher;
+
+  LifecycleHookProxy(T dispatcher, LifecycleHooks hooks) {
+    this.hooks = hooks;
+    this.dispatcher = dispatcher;
+  }
+
+  @Override
+  public Object invoke(Object proxy, Method method, Object[] args) throws 
Throwable {
+    Object result = method.invoke(dispatcher, args);
+    List<BiConsumer> postHooks = hooks.getPostHooks(method.getName());
+    for (BiConsumer hook : postHooks) {

Review Comment:
   What if anyone fails halfway through? 



-- 
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