Skip to content

Commit

Permalink
优化 solon.health.detector 代码实现,增加复用性
Browse files Browse the repository at this point in the history
  • Loading branch information
noear committed Aug 3, 2023
1 parent 6e85f74 commit 46ecfe4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static Detector get(String name) {
/**
* 获取全部
*/
public static Collection<Detector> getAll() {
return Collections.unmodifiableCollection(detectorMap.values());
public static Collection<Detector> all() {
return detectorMap.values();
}


Expand Down Expand Up @@ -65,4 +65,23 @@ public static Map<String, Detector> getMore(String... names) {

return tmp;
}

/**
* 启动
* */
public static void start(String... names) throws Throwable{
for (String name : names) {
if ("*".equals(name)) {
for (Detector detector : detectorMap.values()) {
detector.start();
}
break;
} else {
Detector detector = get(name);
if (detector != null) {
detector.start();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.noear.solon.admin.client.annotation.EnableAdminClient;
import org.noear.solon.core.AopContext;
import org.noear.solon.core.Plugin;
import org.noear.solon.core.event.AppLoadEndEvent;
import org.noear.solon.core.event.EventBus;
import org.noear.solon.health.detector.DetectorManager;

/**
* @author noear
Expand All @@ -17,5 +20,9 @@ public void start(AopContext context) throws Throwable {
}

context.beanScan("org.noear.solon.admin.client");

EventBus.subscribe(AppLoadEndEvent.class, e->{
DetectorManager.start("*");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public class MonitorService {
* @return 所有监视器信息
*/
public Collection<Detector> getMonitors() {
return DetectorManager.getAll().parallelStream().map(it -> new Detector(it.getName(), it.getInfo())).collect(Collectors.toSet());
return DetectorManager.all()
.parallelStream()
.map(it -> new Detector(it.getName(), it.getInfo()))
.collect(Collectors.toList());
}

}

0 comments on commit 46ecfe4

Please sign in to comment.