Commit 82ccb8dc authored by 吴晟's avatar 吴晟
Browse files

Rename ServiceStarter to ServiceManager.

Finish the major codes of TraceSegmentProcessQueue and CollectorClientService.
parent 413f207e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
package com.a.eye.skywalking.agent;

import com.a.eye.skywalking.agent.junction.SkyWalkingEnhanceMatcher;
import com.a.eye.skywalking.api.boot.ServiceStarter;
import com.a.eye.skywalking.api.boot.ServiceManager;
import com.a.eye.skywalking.api.conf.Config;
import com.a.eye.skywalking.api.conf.SnifferConfigInitializer;
import com.a.eye.skywalking.api.logging.EasyLogResolver;
@@ -54,7 +54,7 @@ public class SkyWalkingAgent {

        final PluginFinder pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins());

        ServiceStarter.INSTANCE.boot();
        ServiceManager.INSTANCE.boot();

        new AgentBuilder.Default().type(enhanceClassMatcher(pluginFinder).and(not(isInterface()))).transform(new AgentBuilder.Transformer() {
            public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader) {
+3 −3
Original line number Diff line number Diff line
@@ -8,12 +8,12 @@ import java.util.Map;
import java.util.ServiceLoader;

/**
 * The <code>ServiceStarter</code> bases on {@link ServiceLoader},
 * The <code>ServiceManager</code> bases on {@link ServiceLoader},
 * load all {@link BootService} implementations.
 *
 * @author wusheng
 */
public enum ServiceStarter {
public enum ServiceManager {
    INSTANCE;

    private static ILog logger = LogManager.getLogger(StatusBootService.class);
@@ -31,7 +31,7 @@ public enum ServiceStarter {
                        bootService.bootUp();
                        bootedServices.put(bootService.getClass(), bootService);
                    } catch (Exception e) {
                        logger.error(e, "ServiceStarter try to start [{}] fail.", bootService.getClass().getName());
                        logger.error(e, "ServiceManager try to start [{}] fail.", bootService.getClass().getName());
                    }
                }
            } finally {
+50 −1
Original line number Diff line number Diff line
package com.a.eye.skywalking.api.client;

import com.a.eye.skywalking.api.boot.BootService;
import com.a.eye.skywalking.api.boot.ServiceManager;
import com.a.eye.skywalking.api.queue.TraceSegmentProcessQueue;
import com.a.eye.skywalking.logging.ILog;
import com.a.eye.skywalking.logging.LogManager;
import com.a.eye.skywalking.trace.TraceSegment;
import java.util.List;

/**
 * @author wusheng
 */
public class CollectorClientService implements BootService {
public class CollectorClientService implements Runnable, BootService {
    private static ILog logger = LogManager.getLogger(CollectorClientService.class);
    private static long NO_DATA_SLEEP_TIME_MILLIS = 500;

    /**
     * Start a new {@link Thread} to get finished {@link TraceSegment} by {@link TraceSegmentProcessQueue#getCachedTraceSegments()}
     */
    @Override
    public void bootUp() {
        Thread collectorClientThread = new Thread(this, "collectorClientThread");
        collectorClientThread.start();
    }

    @Override
    public void run() {
        while (true) {
            try {
                TraceSegmentProcessQueue segmentProcessQueue = ServiceManager.INSTANCE.findService(TraceSegmentProcessQueue.class);
                List<TraceSegment> cachedTraceSegments = segmentProcessQueue.getCachedTraceSegments();
                if (cachedTraceSegments.size() > 0) {
                    for (TraceSegment segment : cachedTraceSegments) {
                        //TODO: wusheng
                        //send data
                    }
                    /**
                     * No sleep, when exist finished {@link TraceSegment}.
                     */
                } else {
                    try2Sleep(NO_DATA_SLEEP_TIME_MILLIS);
                }
            } catch (Throwable t) {
                logger.error(t, "Send trace segments to collector failure.");
            }
        }
    }

    /**
     * Try to sleep, and ignore the {@link InterruptedException}
     *
     * @param millis the length of time to sleep in milliseconds
     */
    private void try2Sleep(long millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {

        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ public class Config {
    }

    public static class Disruptor{
        public static int BUFFER_SIZE = 1024 * 4;
        public static int BUFFER_SIZE = 512;
    }


+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@ public final class TraceSegmentHolder {
        this.value = value;
    }

    public void clear(){
        this.value = null;
    }

    public enum Factory implements EventFactory<TraceSegmentHolder> {
        INSTANCE;

Loading