Commit fa187ca9 authored by 吴晟's avatar 吴晟
Browse files

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

parent f1d2aea3
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -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);
    }
+13 −0
Original line number Diff line number Diff line
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() {

    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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";
            }
        }};
    }