From fa187ca945cde7fbe383ce342dc282fd71cd7e1f Mon Sep 17 00:00:00 2001 From: wusheng Date: Mon, 13 Mar 2017 17:13:59 +0800 Subject: [PATCH] Add a new ability to ServiceStarter, about finding a started service instance. --- .../eye/skywalking/api/boot/ServiceStarter.java | 17 ++++++++++++++++- .../api/client/CollectorClientService.java | 13 +++++++++++++ .../v1/x/LogbackPatternConverterActivation.java | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClientService.java diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/ServiceStarter.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/ServiceStarter.java index 97a7d9bb11..a01e82b71f 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/ServiceStarter.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/ServiceStarter.java @@ -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 bootedServices; public void boot() { - while (!isStarted) { + if (!isStarted) { try { + bootedServices = new HashMap<>(); Iterator 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 {@link BootService} implementation class. + * @return {@link BootService} instance + */ + public T findService(Class serviceClass){ + return (T)bootedServices.get(serviceClass); + } + ServiceLoader load() { return ServiceLoader.load(BootService.class); } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClientService.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClientService.java new file mode 100644 index 0000000000..84b4a1ad18 --- /dev/null +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClientService.java @@ -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() { + + } +} diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java index 02ff96d6d9..8c2512d2ae 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-logback-1.x-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java @@ -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"; } }}; }