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
  • Loading branch information
lvjing2 authored Jan 15, 2024
1 parent bc52a4c commit 368a8be
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 173 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 Expand Up @@ -56,19 +55,17 @@
*/
@Singleton
public class HandleArchiveStage implements PipelineStage {
private final static ArkLogger LOGGER = ArkLoggerFactory.getDefaultLogger();

@Inject
private PluginManagerService pluginManagerService;
private PluginManagerService pluginManagerService;

@Inject
private PluginFactoryService pluginFactoryService;
private PluginFactoryService pluginFactoryService;

@Inject
private BizManagerService bizManagerService;
private BizManagerService bizManagerService;

@Inject
private BizFactoryService bizFactoryService;
private BizFactoryService bizFactoryService;

@Override
public void process(PipelineContext pipelineContext) throws ArkRuntimeException {
Expand Down Expand Up @@ -101,15 +98,17 @@ public void process(PipelineContext pipelineContext) throws ArkRuntimeException
bizManagerService.registerBiz(biz);
bizCount += 1;
} else {
LOGGER.warn("The biz of {} is ignored when using dynamic config.",
ArkLoggerFactory.getDefaultLogger().warn(
"The biz of {} is ignored when using dynamic config.",
biz.getIdentity());
}
} else {
if (!isBizExcluded(biz)) {
bizManagerService.registerBiz(biz);
bizCount += 1;
} else {
LOGGER.warn(String.format("The biz of %s is excluded.", biz.getIdentity()));
ArkLoggerFactory.getDefaultLogger().warn(
String.format("The biz of %s is excluded.", biz.getIdentity()));
}
}
}
Expand Down Expand Up @@ -156,8 +155,8 @@ public void process(PipelineContext pipelineContext) throws ArkRuntimeException
if (!isPluginExcluded(plugin)) {
pluginManagerService.registerPlugin(plugin);
} else {
LOGGER.warn(String.format("The plugin of %s is excluded.",
plugin.getPluginName()));
ArkLoggerFactory.getDefaultLogger().warn(
String.format("The plugin of %s is excluded.", plugin.getPluginName()));
}
}

Expand All @@ -180,7 +179,8 @@ protected void processEmbed(PipelineContext pipelineContext) throws Exception {
if (!isPluginExcluded(plugin)) {
pluginManagerService.registerPlugin(plugin);
} else {
LOGGER.warn(String.format("The plugin of %s is excluded.", plugin.getPluginName()));
ArkLoggerFactory.getDefaultLogger().warn(
String.format("The plugin of %s is excluded.", plugin.getPluginName()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
@Singleton
public class StandardPipeline implements Pipeline {

private static final ArkLogger LOGGER = ArkLoggerFactory.getDefaultLogger();
private List<PipelineStage> stages = new ArrayList<>();
private List<PipelineStage> stages = new ArrayList<>();

public StandardPipeline() {
initializePipeline();
Expand Down Expand Up @@ -70,16 +69,19 @@ public Pipeline addPipelineStage(PipelineStage pipelineStage) {
public void process(PipelineContext pipelineContext) throws ArkRuntimeException {
for (PipelineStage pipelineStage : stages) {
try {
LOGGER.info(String.format("Start to process pipeline stage: %s", pipelineStage
.getClass().getName()));
ArkLoggerFactory.getDefaultLogger().info(
String.format("Start to process pipeline stage: %s", pipelineStage.getClass()
.getName()));
pipelineStage.process(pipelineContext);
LOGGER.info(String.format("Finish to process pipeline stage: %s", pipelineStage
.getClass().getName()));
ArkLoggerFactory.getDefaultLogger().info(
String.format("Finish to process pipeline stage: %s", pipelineStage.getClass()
.getName()));
} catch (Throwable e) {
LOGGER.error(String.format("Process pipeline stage fail: %s", pipelineStage
.getClass().getName()), e);
ArkLoggerFactory.getDefaultLogger().error(
String.format("Process pipeline stage fail: %s", pipelineStage.getClass()
.getName()), e);
throw new ArkRuntimeException(e);
}
}
}
}
}
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 Expand Up @@ -48,16 +47,14 @@
*/
public class ArkServiceContainer {

private Injector injector;
private Injector injector;

private List<ArkService> arkServiceList = new ArrayList<>();
private List<ArkService> arkServiceList = new ArrayList<>();

private AtomicBoolean started = new AtomicBoolean(false);
private AtomicBoolean stopped = new AtomicBoolean(false);
private AtomicBoolean started = new AtomicBoolean(false);
private AtomicBoolean stopped = new AtomicBoolean(false);

private final String[] arguments;

private static final ArkLogger LOGGER = ArkLoggerFactory.getDefaultLogger();
private final String[] arguments;

public ArkServiceContainer(String[] arguments) {
this.arguments = arguments;
Expand All @@ -73,7 +70,7 @@ public void start() throws ArkRuntimeException {
ClassLoader oldClassLoader = ClassLoaderUtils.pushContextClassLoader(getClass()
.getClassLoader());
try {
LOGGER.info("Begin to start ArkServiceContainer");
ArkLoggerFactory.getDefaultLogger().info("Begin to start ArkServiceContainer");

injector = Guice.createInjector(findServiceModules());
for (Binding<ArkService> binding : injector
Expand All @@ -84,7 +81,8 @@ public void start() throws ArkRuntimeException {
Collections.sort(arkServiceList, new OrderComparator());

for (ArkService arkService : arkServiceList) {
LOGGER.info(String.format("Init Service: %s", arkService.getClass().getName()));
ArkLoggerFactory.getDefaultLogger().info(
String.format("Init Service: %s", arkService.getClass().getName()));
arkService.init();
}

Expand All @@ -95,7 +93,7 @@ public void start() throws ArkRuntimeException {
ArkClient.setEventAdminService(getService(EventAdminService.class));
ArkClient.setPluginManagerService(getService(PluginManagerService.class));
ArkClient.setArguments(arguments);
LOGGER.info("Finish to start ArkServiceContainer");
ArkLoggerFactory.getDefaultLogger().info("Finish to start ArkServiceContainer");
} finally {
ClassLoaderUtils.popContextClassLoader(oldClassLoader);
}
Expand Down Expand Up @@ -134,18 +132,18 @@ public <T> T getService(Class<T> clazz) {
*/
public void stop() throws ArkRuntimeException {
if (stopped.compareAndSet(false, true)) {
LOGGER.info("Begin to stop ArkServiceContainer");
ArkLoggerFactory.getDefaultLogger().info("Begin to stop ArkServiceContainer");

ClassLoader oldClassLoader = ClassLoaderUtils.pushContextClassLoader(getClass()
.getClassLoader());
try {
Collections.reverse(arkServiceList);
for (ArkService arkService : arkServiceList) {
LOGGER.info(String.format("Dispose service: %s", arkService.getClass()
.getName()));
ArkLoggerFactory.getDefaultLogger().info(
String.format("Dispose service: %s", arkService.getClass().getName()));
arkService.dispose();
}
LOGGER.info("Finish to stop ArkServiceContainer");
ArkLoggerFactory.getDefaultLogger().info("Finish to stop ArkServiceContainer");
} finally {
ClassLoaderUtils.popContextClassLoader(oldClassLoader);
}
Expand All @@ -170,4 +168,4 @@ public boolean isRunning() {
return isStarted() && !stopped.get();
}

}
}
Loading

0 comments on commit 368a8be

Please sign in to comment.