提交 fa187ca9 编写于 作者: wu-sheng's avatar wu-sheng

Add a new ability to ServiceStarter, about finding a started service instance.

上级 f1d2aea3
......@@ -2,7 +2,9 @@ package com.a.eye.skywalking.api.boot;
import com.a.eye.skywalking.logging.ILog;
import com.a.eye.skywalking.logging.LogManager;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
/**
......@@ -16,15 +18,18 @@ public enum ServiceStarter {
private static ILog logger = LogManager.getLogger(StatusBootService.class);
private volatile boolean isStarted = false;
private Map<Class, BootService> bootedServices;
public void boot() {
while (!isStarted) {
if (!isStarted) {
try {
bootedServices = new HashMap<>();
Iterator<BootService> serviceIterator = load().iterator();
while (serviceIterator.hasNext()) {
BootService bootService = serviceIterator.next();
try {
bootService.bootUp();
bootedServices.put(bootService.getClass(), bootService);
} catch (Exception e) {
logger.error(e, "ServiceStarter try to start [{}] fail.", bootService.getClass().getName());
}
......@@ -35,6 +40,16 @@ public enum ServiceStarter {
}
}
/**
* Find a {@link BootService} implementation, which is already started.
* @param serviceClass class name.
* @param <T> {@link BootService} implementation class.
* @return {@link BootService} instance
*/
public <T extends BootService> T findService(Class<T> serviceClass){
return (T)bootedServices.get(serviceClass);
}
ServiceLoader<BootService> load() {
return ServiceLoader.load(BootService.class);
}
......
package com.a.eye.skywalking.api.client;
import com.a.eye.skywalking.api.boot.BootService;
/**
* @author wusheng
*/
public class CollectorClientService implements BootService {
@Override
public void bootUp() {
}
}
......@@ -47,7 +47,7 @@ public class LogbackPatternConverterActivation extends ClassInstanceMethodsEnhan
@Override
public String getMethodsInterceptor() {
return "com.a.eye.skywalking.toolkit.log.logback.v1.x.PrintTraceIdInterceptor";
return "com.a.eye.skywalking.toolkit.activation.log.logback.v1.x.PrintTraceIdInterceptor";
}
}};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册