Skip to content

Commit

Permalink
Move service register to prepare method.
Browse files Browse the repository at this point in the history
  • Loading branch information
peng-yongsheng committed Nov 14, 2017
1 parent 9c174d3 commit 714b4cc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.skywalking.apm.collector.cache.service.ServiceNameCacheService;
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.IServiceNameCacheDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.slf4j.Logger;
Expand All @@ -39,8 +41,8 @@ public class ServiceNameCacheGuavaService implements ServiceNameCacheService {

private final DAOService daoService;

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

public String get(int serviceId) {
Expand Down

0 comments on commit 714b4cc

Please sign in to comment.