Skip to content

Commit

Permalink
Merge pull request #55 from linyimin0812/feat/20230803_health_check_u…
Browse files Browse the repository at this point in the history
…pgrade_1

feat: health check upgrade
  • Loading branch information
linyimin0812 authored Aug 2, 2023
2 parents 4295a46 + 40f7571 commit 8a912fe
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.github.linyimin0812.profiler.core.monitor;

import io.github.linyimin0812.profiler.api.EventListener;
import io.github.linyimin0812.profiler.api.event.AtExitEvent;
import io.github.linyimin0812.profiler.api.event.Event;
import io.github.linyimin0812.profiler.common.logger.LogFactory;
import io.github.linyimin0812.profiler.core.container.IocContainer;
import org.kohsuke.MetaInfServices;
import org.slf4j.Logger;

import java.util.Collections;
import java.util.List;

/**
* @author yiminlin
**/
@MetaInfServices
public class ApplicationRunMonitor implements EventListener {

private final Logger logger = LogFactory.getStartupLogger();

@Override
public boolean filter(String className) {
return "org.springframework.boot.SpringApplication".equals(className);
}

@Override
public boolean filter(String methodName, String[] methodTypes) {

if (!"run".equals(methodName) || methodTypes == null || methodTypes.length != 2) {
return false;
}

return "java.lang.Class[]".equals(methodTypes[0]) && "java.lang.String[]".equals(methodTypes[1]);
}

@Override
public void onEvent(Event event) {
if (! (event instanceof AtExitEvent)) {
return;
}

IocContainer.stop();
}

@Override
public List<Event.Type> listen() {
return Collections.singletonList(Event.Type.AT_EXIT);
}

@Override
public void start() {
logger.info("=============ApplicationRunMonitor start=============");
}

@Override
public void stop() {
logger.info("=============ApplicationRunMonitor stop=============");
}
}

0 comments on commit 8a912fe

Please sign in to comment.