Add a new ability to ServiceStarter, about finding a started service instance.
This commit is contained in:
parent
f1d2aea35e
commit
fa187ca945
|
|
@ -2,7 +2,9 @@ package com.a.eye.skywalking.api.boot;
|
||||||
|
|
||||||
import com.a.eye.skywalking.logging.ILog;
|
import com.a.eye.skywalking.logging.ILog;
|
||||||
import com.a.eye.skywalking.logging.LogManager;
|
import com.a.eye.skywalking.logging.LogManager;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -16,15 +18,18 @@ public enum ServiceStarter {
|
||||||
|
|
||||||
private static ILog logger = LogManager.getLogger(StatusBootService.class);
|
private static ILog logger = LogManager.getLogger(StatusBootService.class);
|
||||||
private volatile boolean isStarted = false;
|
private volatile boolean isStarted = false;
|
||||||
|
private Map<Class, BootService> bootedServices;
|
||||||
|
|
||||||
public void boot() {
|
public void boot() {
|
||||||
while (!isStarted) {
|
if (!isStarted) {
|
||||||
try {
|
try {
|
||||||
|
bootedServices = new HashMap<>();
|
||||||
Iterator<BootService> serviceIterator = load().iterator();
|
Iterator<BootService> serviceIterator = load().iterator();
|
||||||
while (serviceIterator.hasNext()) {
|
while (serviceIterator.hasNext()) {
|
||||||
BootService bootService = serviceIterator.next();
|
BootService bootService = serviceIterator.next();
|
||||||
try {
|
try {
|
||||||
bootService.bootUp();
|
bootService.bootUp();
|
||||||
|
bootedServices.put(bootService.getClass(), bootService);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e, "ServiceStarter try to start [{}] fail.", bootService.getClass().getName());
|
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() {
|
ServiceLoader<BootService> load() {
|
||||||
return ServiceLoader.load(BootService.class);
|
return ServiceLoader.load(BootService.class);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
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
|
@Override
|
||||||
public String getMethodsInterceptor() {
|
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";
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue