Skip to content

Commit

Permalink
ark logger lazy init (#829)
Browse files Browse the repository at this point in the history
* support delegate from classLoaderHook for getResourceAsStream

* Revert "support delegate from classLoaderHook for getResourceAsStream"

This reverts commit 5bd306b.

* fix typo

* plugin default export package without activator, modify to set

* fix format

* export class for plugin as default

* update to 2.2.6

* ark logger lazy init

* format

(cherry picked from commit 368a8be)
  • Loading branch information
lvjing2 committed Jan 18, 2024
1 parent feb4193 commit 0ab4120
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,50 +58,47 @@
* @since 0.1.0
*/
public class BizModel implements Biz {
private final static ArkLogger LOGGER = ArkLoggerFactory
.getDefaultLogger();
private String bizName;

private String bizName;
private String bizVersion;

private String bizVersion;
private BizState bizState;

private BizState bizState;
private String mainClass;

private String mainClass;
private String webContextPath;

private String webContextPath;
private URL[] urls;

private URL[] urls;
private URL[] pluginUrls;

private URL[] pluginUrls;
private ClassLoader classLoader;

private ClassLoader classLoader;
private Map<String, String> attributes = new ConcurrentHashMap<>();

private Map<String, String> attributes = new ConcurrentHashMap<>();
private int priority = DEFAULT_PRECEDENCE;

private int priority = DEFAULT_PRECEDENCE;
private Set<String> denyImportPackages;

private Set<String> denyImportPackages;
private Set<String> denyImportPackageNodes = new HashSet<>();

private Set<String> denyImportPackageNodes = new HashSet<>();
private Set<String> denyImportPackageStems = new HashSet<>();

private Set<String> denyImportPackageStems = new HashSet<>();
private Set<String> denyImportClasses;

private Set<String> denyImportClasses;
private Set<String> denyImportResources = new HashSet<>();

private Set<String> denyImportResources = new HashSet<>();
private Set<String> injectPluginDependencies = new HashSet<>();
private Set<String> injectExportPackages = new HashSet<>();

private Set<String> injectPluginDependencies = new HashSet<>();
private Set<String> injectExportPackages = new HashSet<>();
private Set<String> declaredLibraries = new LinkedHashSet<>();
private Map<String, Boolean> declaredCacheMap = new ConcurrentHashMap<>();

private Set<String> declaredLibraries = new LinkedHashSet<>();
private Map<String, Boolean> declaredCacheMap = new ConcurrentHashMap<>();
private Set<String> denyPrefixImportResourceStems = new HashSet<>();

private Set<String> denyPrefixImportResourceStems = new HashSet<>();
private Set<String> denySuffixImportResourceStems = new HashSet<>();

private Set<String> denySuffixImportResourceStems = new HashSet<>();

private File bizTempWorkDir;
private File bizTempWorkDir;

public BizModel setBizName(String bizName) {
AssertUtils.isFalse(StringUtils.isEmpty(bizName), "Biz Name must not be empty!");
Expand Down Expand Up @@ -287,13 +284,13 @@ public void start(String[] args) throws Throwable {
resetProperties();
if (!isMasterBizAndEmbedEnable()) {
long start = System.currentTimeMillis();
LOGGER.info("Ark biz {} start.", getIdentity());
ArkLoggerFactory.getDefaultLogger().info("Ark biz {} start.", getIdentity());
MainMethodRunner mainMethodRunner = new MainMethodRunner(mainClass, args);
mainMethodRunner.run();
// this can trigger health checker handler
eventAdminService.sendEvent(new AfterBizStartupEvent(this));
LOGGER.info("Ark biz {} started in {} ms", getIdentity(),
(System.currentTimeMillis() - start));
ArkLoggerFactory.getDefaultLogger().info("Ark biz {} started in {} ms",
getIdentity(), (System.currentTimeMillis() - start));
}
} catch (Throwable e) {
bizState = BizState.BROKEN;
Expand Down Expand Up @@ -339,9 +336,9 @@ public void stop() {
try {
// this can trigger uninstall handler
long start = System.currentTimeMillis();
LOGGER.info("Ark biz {} stops.", getIdentity());
ArkLoggerFactory.getDefaultLogger().info("Ark biz {} stops.", getIdentity());
eventAdminService.sendEvent(new BeforeBizStopEvent(this));
LOGGER.info("Ark biz {} stopped in {} ms", getIdentity(),
ArkLoggerFactory.getDefaultLogger().info("Ark biz {} stopped in {} ms", getIdentity(),
(System.currentTimeMillis() - start));
} finally {
BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer()
Expand Down Expand Up @@ -463,13 +460,15 @@ boolean doCheckDeclared(String jarFilePath) {
if (artifactId == null) {
if (jarFilePath.contains(".jar!") || jarFilePath.endsWith(".jar")) {
// if in jar, and can't get artifactId from jar file, then just rollback to all delegate.
LOGGER.info(String.format("Can't find artifact id for %s, default as declared.",
jarFilePath));
ArkLoggerFactory.getDefaultLogger().info(
String.format("Can't find artifact id for %s, default as declared.",
jarFilePath));
return true;
} else {
// for not in jar, then default not delegate.
LOGGER.info(String.format(
"Can't find artifact id for %s, default as not declared.", jarFilePath));
ArkLoggerFactory.getDefaultLogger().info(
String.format("Can't find artifact id for %s, default as not declared.",
jarFilePath));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.alipay.sofa.ark.api.ArkClient;
import com.alipay.sofa.ark.api.ArkConfigs;
import com.alipay.sofa.ark.common.log.ArkLogger;
import com.alipay.sofa.ark.common.log.ArkLoggerFactory;
import com.alipay.sofa.ark.common.util.AssertUtils;
import com.alipay.sofa.ark.common.util.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.alipay.sofa.ark.api.ArkClient;
import com.alipay.sofa.ark.common.guice.AbstractArkGuiceModule;
import com.alipay.sofa.ark.common.log.ArkLogger;
import com.alipay.sofa.ark.common.log.ArkLoggerFactory;
import com.alipay.sofa.ark.common.util.ClassLoaderUtils;
import com.alipay.sofa.ark.common.util.OrderComparator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.alipay.sofa.ark.spi.service.ArkInject;
import com.alipay.sofa.ark.spi.service.biz.BizManagerService;
import com.alipay.sofa.ark.spi.service.session.CommandProvider;
import org.slf4j.Logger;

import java.net.URL;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.alipay.sofa.ark.container.service.biz;

import com.alipay.sofa.ark.api.ArkConfigs;
import com.alipay.sofa.ark.common.log.ArkLogger;
import com.alipay.sofa.ark.common.log.ArkLoggerFactory;
import com.alipay.sofa.ark.exception.ArkRuntimeException;
import com.alipay.sofa.ark.spi.model.Biz;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
@Singleton
public class ClassLoaderServiceImpl implements ClassLoaderService {

private static final ArkLogger LOGGER = ArkLoggerFactory
.getDefaultLogger();

private static final String ARK_SPI_PACKAGES = "com.alipay.sofa.ark.spi";
private static final String ARK_API_PACKAGES = "com.alipay.sofa.ark.api";
private static final String ARK_LOG_PACKAGES = "com.alipay.sofa.ark.common.log";
Expand Down Expand Up @@ -315,14 +312,15 @@ public void init() throws ArkRuntimeException {
URL[] urls = ClassLoaderUtils.getURLs(systemClassLoader);
for (URL url : urls) {
if (url.getPath().startsWith(javaHome)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Find JDK Url: %s", url));
if (ArkLoggerFactory.getDefaultLogger().isDebugEnabled()) {
ArkLoggerFactory.getDefaultLogger().debug(
String.format("Find JDK Url: %s", url));
}
jdkUrls.add(url);
}
}
} catch (Throwable e) {
LOGGER.warn("Meet exception when parse JDK urls", e);
ArkLoggerFactory.getDefaultLogger().warn("Meet exception when parse JDK urls", e);
}

jdkClassLoader = new JDKDelegateClassLoader(jdkUrls.toArray(new URL[0]), extClassLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.alipay.sofa.ark.spi.service.registry.RegistryService;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.slf4j.Logger;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand All @@ -48,9 +47,6 @@ public class EventAdminServiceImpl implements EventAdminService, EventHandler {

private final static ConcurrentMap<ClassLoader, CopyOnWriteArraySet<EventHandler>> SUBSCRIBER_MAP = new ConcurrentHashMap<>();

private final static Logger LOGGER = ArkLoggerFactory
.getDefaultLogger();

@Inject
private RegistryService registryService;

Expand Down Expand Up @@ -89,7 +85,8 @@ public void register(EventHandler eventHandler) {
}
}
set.add(eventHandler);
LOGGER.debug(String.format("Register event handler: %s.", eventHandler));
ArkLoggerFactory.getDefaultLogger().debug(
String.format("Register event handler: %s.", eventHandler));
}

@Override
Expand All @@ -98,14 +95,16 @@ public void unRegister(EventHandler eventHandler) {
.getClassLoader());
if (set != null) {
set.remove(eventHandler);
LOGGER.debug(String.format("Unregister event handler: %s.", eventHandler));
ArkLoggerFactory.getDefaultLogger().debug(
String.format("Unregister event handler: %s.", eventHandler));
}
}

@Override
public void unRegister(ClassLoader classLoader) {
SUBSCRIBER_MAP.remove(classLoader);
LOGGER.debug(String.format("Unregister event handler of classLoader: %s.", classLoader));
ArkLoggerFactory.getDefaultLogger().debug(
String.format("Unregister event handler of classLoader: %s.", classLoader));

}

Expand Down Expand Up @@ -178,4 +177,4 @@ private boolean checkEventHandlerType(Type type) {
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.alipay.sofa.ark.container.service.injection;

import com.alipay.sofa.ark.common.log.ArkLogger;
import com.alipay.sofa.ark.common.log.ArkLoggerFactory;
import com.alipay.sofa.ark.common.util.ReflectionUtils;
import com.alipay.sofa.ark.common.util.ReflectionUtils.FieldCallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.alipay.sofa.ark.container.service.plugin;

import com.alipay.sofa.ark.common.log.ArkLogger;
import com.alipay.sofa.ark.common.log.ArkLoggerFactory;
import com.alipay.sofa.ark.exception.ArkRuntimeException;
import com.alipay.sofa.ark.spi.service.plugin.PluginManagerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
@Singleton
public class RegistryServiceImpl implements RegistryService {

private static final ArkLogger LOGGER = ArkLoggerFactory
.getDefaultLogger();
private CopyOnWriteArraySet<ServiceReference<?>> services = new CopyOnWriteArraySet<>();

private OrderComparator orderComparator = new OrderComparator();
Expand All @@ -72,8 +70,9 @@ public <T> ServiceReference<T> publishService(Class<T> ifClass, T implObject, St
serviceProvider);
for (ServiceReference<?> serviceReference : services) {
if (serviceMetadata.equals(serviceReference.getServiceMetadata())) {
LOGGER.warn(String.format("Service: %s publish by: %s already exist",
serviceMetadata.getServiceName(), serviceProvider));
ArkLoggerFactory.getDefaultLogger().warn(
String.format("Service: %s publish by: %s already exist",
serviceMetadata.getServiceName(), serviceProvider));
return (ServiceReference<T>) serviceReference;
}
}
Expand All @@ -82,8 +81,9 @@ public <T> ServiceReference<T> publishService(Class<T> ifClass, T implObject, St
implObject);
injectionService.inject(serviceReference);

LOGGER.info(String.format("Service: %s publish by: %s succeed",
serviceMetadata.getServiceName(), serviceProvider));
ArkLoggerFactory.getDefaultLogger().info(
String.format("Service: %s publish by: %s succeed", serviceMetadata.getServiceName(),
serviceProvider));

services.add(serviceReference);

Expand Down Expand Up @@ -148,4 +148,4 @@ public int unPublishServices(ServiceFilter serviceFilter) {
return count;
}

}
}

0 comments on commit 0ab4120

Please sign in to comment.