lasdf1234 commented on code in PR #11226: URL: https://github.com/apache/gravitino/pull/11226#discussion_r3309633443
########## plugins/idp-basic/src/main/java/org/apache/gravitino/idp/IdpServerPluginBootstrap.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.idp; + +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.gravitino.Config; +import org.apache.gravitino.GravitinoEnv; +import org.apache.gravitino.idp.auth.ServiceAdminInitializer; +import org.apache.gravitino.server.plugin.ServerPluginBootstrap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Server plugin bootstrap for the built-in IdP (idp-basic). + * + * <p>Initializes configured service admins once per JVM when the plugin is on the server classpath. + */ +public final class IdpServerPluginBootstrap implements ServerPluginBootstrap { + + private static final Logger LOG = LoggerFactory.getLogger(IdpServerPluginBootstrap.class); + + private static final String NAME = "idp-basic"; + + private static final AtomicBoolean INITIALIZED = new AtomicBoolean(false); + + @Override + public String name() { + return NAME; + } + + @Override + public void initializeOnce() throws Exception { + if (!INITIALIZED.compareAndSet(false, true)) { + return; + } + + Config config = GravitinoEnv.getInstance().config(); + try { + ServiceAdminInitializer.initialize(config); + } catch (RuntimeException e) { + INITIALIZED.set(false); + LOG.error("Failed to initialize built-in IdP plugin", e); + throw e; + } catch (Exception e) { + INITIALIZED.set(false); + LOG.error("Failed to initialize built-in IdP plugin", e); + throw e; + } Review Comment: Rewrite this 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
