Commit 714b4ccb authored by peng-yongsheng's avatar peng-yongsheng
Browse files

Move service register to prepare method.

parent 9c174d3a
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ package org.skywalking.apm.collector.agent.grpc.handler;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.junit.Test;
import org.skywalking.apm.network.proto.Application;
import org.skywalking.apm.network.proto.ApplicationMapping;
import org.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc;
@@ -36,7 +35,6 @@ public class ApplicationRegisterServiceHandlerTestCase {

    private ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub stub;

    @Test
    public void testRegister() {
        ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build();
        stub = ApplicationRegisterServiceGrpc.newBlockingStub(channel);
+4 −7
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import org.skywalking.apm.collector.core.module.Module;
import org.skywalking.apm.collector.core.module.ModuleProvider;
import org.skywalking.apm.collector.core.module.ServiceNotProvidedException;
import org.skywalking.apm.collector.storage.StorageModule;
import org.skywalking.apm.collector.storage.service.DAOService;

/**
 * @author peng-yongsheng
@@ -48,15 +47,13 @@ public class CacheModuleGuavaProvider extends ModuleProvider {
    }

    @Override public void prepare(Properties config) throws ServiceNotProvidedException {
        this.registerServiceImplementation(ApplicationCacheService.class, new ApplicationCacheGuavaService(getManager()));
        this.registerServiceImplementation(InstanceCacheService.class, new InstanceCacheGuavaService(getManager()));
        this.registerServiceImplementation(ServiceIdCacheService.class, new ServiceIdCacheGuavaService(getManager()));
        this.registerServiceImplementation(ServiceNameCacheService.class, new ServiceNameCacheGuavaService(getManager()));
    }

    @Override public void start(Properties config) throws ServiceNotProvidedException {
        DAOService daoService = getManager().find(StorageModule.NAME).getService(DAOService.class);

        this.registerServiceImplementation(ApplicationCacheService.class, new ApplicationCacheGuavaService(daoService));
        this.registerServiceImplementation(InstanceCacheService.class, new InstanceCacheGuavaService(daoService));
        this.registerServiceImplementation(ServiceIdCacheService.class, new ServiceIdCacheGuavaService(daoService));
        this.registerServiceImplementation(ServiceNameCacheService.class, new ServiceNameCacheGuavaService(daoService));
    }

    @Override public void notifyAfterCompleted() throws ServiceNotProvidedException {
+4 −2
Original line number Diff line number Diff line
@@ -21,8 +21,10 @@ package org.skywalking.apm.collector.cache.guava.service;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.skywalking.apm.collector.core.module.ModuleManager;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.StorageModule;
import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.slf4j.Logger;
@@ -39,8 +41,8 @@ public class ApplicationCacheGuavaService implements ApplicationCacheService {

    private final DAOService daoService;

    public ApplicationCacheGuavaService(DAOService daoService) {
        this.daoService = daoService;
    public ApplicationCacheGuavaService(ModuleManager moduleManager) {
        this.daoService = moduleManager.find(StorageModule.NAME).getService(DAOService.class);
    }

    public int get(String applicationCode) {
+4 −2
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@ package org.skywalking.apm.collector.cache.guava.service;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.skywalking.apm.collector.cache.service.InstanceCacheService;
import org.skywalking.apm.collector.core.module.ModuleManager;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.StorageModule;
import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.slf4j.Logger;
@@ -40,8 +42,8 @@ public class InstanceCacheGuavaService implements InstanceCacheService {

    private final DAOService daoService;

    public InstanceCacheGuavaService(DAOService daoService) {
        this.daoService = daoService;
    public InstanceCacheGuavaService(ModuleManager moduleManager) {
        this.daoService = moduleManager.find(StorageModule.NAME).getService(DAOService.class);
    }

    public int get(int applicationInstanceId) {
+4 −2
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@ package org.skywalking.apm.collector.cache.guava.service;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.skywalking.apm.collector.cache.service.ServiceIdCacheService;
import org.skywalking.apm.collector.core.module.ModuleManager;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.StorageModule;
import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.slf4j.Logger;
@@ -38,8 +40,8 @@ public class ServiceIdCacheGuavaService implements ServiceIdCacheService {

    private final DAOService daoService;

    public ServiceIdCacheGuavaService(DAOService daoService) {
        this.daoService = daoService;
    public ServiceIdCacheGuavaService(ModuleManager moduleManager) {
        this.daoService = moduleManager.find(StorageModule.NAME).getService(DAOService.class);
    }

    public int get(int applicationId, String serviceName) {
Loading