提交 b1e2ebd4 编写于 作者: P peng-yongsheng

Refactor cache module to provide cache services.

上级 737e9c53
...@@ -50,9 +50,9 @@ public class CpuMetricPersistenceWorker extends PersistenceWorker<CpuMetric, Cpu ...@@ -50,9 +50,9 @@ public class CpuMetricPersistenceWorker extends PersistenceWorker<CpuMetric, Cpu
return daoService.getPersistenceDAO(ICpuMetricStreamDAO.class); return daoService.getPersistenceDAO(ICpuMetricStreamDAO.class);
} }
public static class Factory extends AbstractLocalAsyncWorkerProvider<CpuMetricPersistenceWorker> { public static class Factory extends AbstractLocalAsyncWorkerProvider<CpuMetric, CpuMetric, CpuMetricPersistenceWorker> {
public Factory(DAOService daoService, QueueCreatorService queueCreatorService) { public Factory(DAOService daoService, QueueCreatorService<CpuMetric> queueCreatorService) {
super(daoService, queueCreatorService); super(daoService, queueCreatorService);
} }
......
...@@ -136,5 +136,12 @@ ...@@ -136,5 +136,12 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<!-- stream provider --> <!-- stream provider -->
<!-- cache provider -->
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>collector-cache-guava-provider</artifactId>
<version>${project.version}</version>
</dependency>
<!-- cache provider -->
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017, OpenSkywalking Organization All rights reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ Project repository: https://github.com/OpenSkywalking/skywalking
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-collector-cache</artifactId>
<groupId>org.skywalking</groupId>
<version>3.2.4-2017</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>collector-cache-define</artifactId>
<packaging>jar</packaging>
</project>
\ No newline at end of file
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.cache;
import org.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.skywalking.apm.collector.cache.service.InstanceCacheService;
import org.skywalking.apm.collector.cache.service.ServiceIdCacheService;
import org.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.skywalking.apm.collector.core.module.Module;
/**
* @author peng-yongsheng
*/
public class CacheModule extends Module {
public static final String NAME = "cache";
@Override public String name() {
return NAME;
}
@Override public Class[] services() {
return new Class[] {ApplicationCacheService.class, InstanceCacheService.class, ServiceIdCacheService.class, ServiceNameCacheService.class};
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.cache.service;
import org.skywalking.apm.collector.core.module.Service;
/**
* @author peng-yongsheng
*/
public interface ApplicationCacheService extends Service {
int get(String applicationCode);
String get(int applicationId);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.cache.service;
import org.skywalking.apm.collector.core.module.Service;
/**
* @author peng-yongsheng
*/
public interface InstanceCacheService extends Service {
int get(int applicationInstanceId);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.cache.service;
import org.skywalking.apm.collector.core.module.Service;
/**
* @author peng-yongsheng
*/
public interface ServiceIdCacheService extends Service {
int get(int applicationId, String serviceName);
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.cache.service;
import org.skywalking.apm.collector.core.module.Service;
/**
* @author peng-yongsheng
*/
public interface ServiceNameCacheService extends Service {
String get(int serviceId);
String getSplitServiceName(String serviceName);
}
#
# Copyright 2017, OpenSkywalking Organization All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Project repository: https://github.com/OpenSkywalking/skywalking
#
org.skywalking.apm.collector.cache.CacheModule
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017, OpenSkywalking Organization All rights reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ Project repository: https://github.com/OpenSkywalking/skywalking
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-collector-cache</artifactId>
<groupId>org.skywalking</groupId>
<version>3.2.4-2017</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>collector-cache-guava-provider</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>collector-cache-define</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.cache.guava;
import java.util.Properties;
import org.skywalking.apm.collector.cache.CacheModule;
import org.skywalking.apm.collector.cache.guava.service.ApplicationCacheGuavaService;
import org.skywalking.apm.collector.cache.guava.service.InstanceCacheGuavaService;
import org.skywalking.apm.collector.cache.guava.service.ServiceIdCacheGuavaService;
import org.skywalking.apm.collector.cache.guava.service.ServiceNameCacheGuavaService;
import org.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.skywalking.apm.collector.cache.service.InstanceCacheService;
import org.skywalking.apm.collector.cache.service.ServiceIdCacheService;
import org.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.skywalking.apm.collector.core.module.Module;
import org.skywalking.apm.collector.core.module.ModuleNotFoundException;
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
*/
public class CacheModuleGuavaProvider extends ModuleProvider {
@Override public String name() {
return "guava";
}
@Override public Class<? extends Module> module() {
return CacheModule.class;
}
@Override public void prepare(Properties config) throws ServiceNotProvidedException {
}
@Override public void start(Properties config) throws ServiceNotProvidedException {
try {
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));
} catch (ModuleNotFoundException e) {
throw new ServiceNotProvidedException(e.getMessage());
}
}
@Override public void notifyAfterCompleted() throws ServiceNotProvidedException {
}
@Override public String[] requiredModules() {
return new String[] {StorageModule.NAME};
}
}
...@@ -16,28 +16,35 @@ ...@@ -16,28 +16,35 @@
* Project repository: https://github.com/OpenSkywalking/skywalking * Project repository: https://github.com/OpenSkywalking/skywalking
*/ */
package org.skywalking.apm.collector.cache; package org.skywalking.apm.collector.cache.guava.service;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import org.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.skywalking.apm.collector.core.util.Const; import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.StringUtils; import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.base.dao.DAOContainer;
import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
public class ApplicationCache { public class ApplicationCacheGuavaService implements ApplicationCacheService {
private static final Logger logger = LoggerFactory.getLogger(ApplicationCache.class); private final Logger logger = LoggerFactory.getLogger(ApplicationCacheGuavaService.class);
private static Cache<String, Integer> CODE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build(); private final Cache<String, Integer> CODE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build();
public static int get(String applicationCode) { private final DAOService daoService;
IApplicationCacheDAO dao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName());
public ApplicationCacheGuavaService(DAOService daoService) {
this.daoService = daoService;
}
public int get(String applicationCode) {
IApplicationCacheDAO dao = (IApplicationCacheDAO)daoService.get(IApplicationCacheDAO.class);
int applicationId = 0; int applicationId = 0;
try { try {
...@@ -55,10 +62,10 @@ public class ApplicationCache { ...@@ -55,10 +62,10 @@ public class ApplicationCache {
return applicationId; return applicationId;
} }
private static Cache<Integer, String> ID_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build(); private final Cache<Integer, String> ID_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
public static String get(int applicationId) { public String get(int applicationId) {
IApplicationCacheDAO dao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName()); IApplicationCacheDAO dao = (IApplicationCacheDAO)daoService.get(IApplicationCacheDAO.class);
String applicationCode = Const.EMPTY_STRING; String applicationCode = Const.EMPTY_STRING;
try { try {
......
...@@ -16,26 +16,33 @@ ...@@ -16,26 +16,33 @@
* Project repository: https://github.com/OpenSkywalking/skywalking * Project repository: https://github.com/OpenSkywalking/skywalking
*/ */
package org.skywalking.apm.collector.cache; package org.skywalking.apm.collector.cache.guava.service;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import org.skywalking.apm.collector.storage.base.dao.DAOContainer; import org.skywalking.apm.collector.cache.service.InstanceCacheService;
import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
public class InstanceCache { public class InstanceCacheGuavaService implements InstanceCacheService {
private static final Logger logger = LoggerFactory.getLogger(InstanceCache.class); private final Logger logger = LoggerFactory.getLogger(InstanceCacheGuavaService.class);
private static Cache<Integer, Integer> INSTANCE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build(); private final Cache<Integer, Integer> INSTANCE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build();
public static int get(int applicationInstanceId) { private final DAOService daoService;
IInstanceCacheDAO dao = (IInstanceCacheDAO)DAOContainer.INSTANCE.get(IInstanceCacheDAO.class.getName());
public InstanceCacheGuavaService(DAOService daoService) {
this.daoService = daoService;
}
public int get(int applicationInstanceId) {
IInstanceCacheDAO dao = (IInstanceCacheDAO)daoService.get(IInstanceCacheDAO.class);
int applicationId = 0; int applicationId = 0;
try { try {
......
...@@ -16,28 +16,34 @@ ...@@ -16,28 +16,34 @@
* Project repository: https://github.com/OpenSkywalking/skywalking * Project repository: https://github.com/OpenSkywalking/skywalking
*/ */
package org.skywalking.apm.collector.cache; package org.skywalking.apm.collector.cache.guava.service;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import org.skywalking.apm.collector.cache.service.ServiceIdCacheService;
import org.skywalking.apm.collector.core.util.Const; import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.base.dao.DAOContainer;
import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
public class ServiceIdCache { public class ServiceIdCacheGuavaService implements ServiceIdCacheService {
private static final Logger logger = LoggerFactory.getLogger(ServiceIdCache.class); private final Logger logger = LoggerFactory.getLogger(ServiceIdCacheGuavaService.class);
//TODO size configuration private final Cache<String, Integer> SERVICE_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
private static Cache<String, Integer> SERVICE_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
public static int get(int applicationId, String serviceName) { private final DAOService daoService;
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameCacheDAO.class.getName());
public ServiceIdCacheGuavaService(DAOService daoService) {
this.daoService = daoService;
}
public int get(int applicationId, String serviceName) {
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)daoService.get(IServiceNameCacheDAO.class);
int serviceId = 0; int serviceId = 0;
try { try {
......
...@@ -16,29 +16,35 @@ ...@@ -16,29 +16,35 @@
* Project repository: https://github.com/OpenSkywalking/skywalking * Project repository: https://github.com/OpenSkywalking/skywalking
*/ */
package org.skywalking.apm.collector.cache; package org.skywalking.apm.collector.cache.guava.service;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import org.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.skywalking.apm.collector.core.util.Const; import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.StringUtils; import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.base.dao.DAOContainer;
import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO;
import org.skywalking.apm.collector.storage.service.DAOService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
public class ServiceNameCache { public class ServiceNameCacheGuavaService implements ServiceNameCacheService {
private static final Logger logger = LoggerFactory.getLogger(ServiceNameCache.class); private final Logger logger = LoggerFactory.getLogger(ServiceNameCacheGuavaService.class);
//TODO size configuration private final Cache<Integer, String> CACHE = CacheBuilder.newBuilder().maximumSize(10000).build();
private static Cache<Integer, String> CACHE = CacheBuilder.newBuilder().maximumSize(10000).build();
public static String get(int serviceId) { private final DAOService daoService;
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameCacheDAO.class.getName());
public ServiceNameCacheGuavaService(DAOService daoService) {
this.daoService = daoService;
}
public String get(int serviceId) {
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)daoService.get(IServiceNameCacheDAO.class);
String serviceName = Const.EMPTY_STRING; String serviceName = Const.EMPTY_STRING;
try { try {
...@@ -57,7 +63,7 @@ public class ServiceNameCache { ...@@ -57,7 +63,7 @@ public class ServiceNameCache {
return serviceName; return serviceName;
} }
public static String getSplitServiceName(String serviceName) { public String getSplitServiceName(String serviceName) {
if (StringUtils.isNotEmpty(serviceName)) { if (StringUtils.isNotEmpty(serviceName)) {
String[] serviceNames = serviceName.split(Const.ID_SPLIT); String[] serviceNames = serviceName.split(Const.ID_SPLIT);
if (serviceNames.length == 2) { if (serviceNames.length == 2) {
......
#
# Copyright 2017, OpenSkywalking Organization All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Project repository: https://github.com/OpenSkywalking/skywalking
#
org.skywalking.apm.collector.cache.guava.CacheModuleGuavaProvider
\ No newline at end of file
...@@ -10,7 +10,11 @@ ...@@ -10,7 +10,11 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>apm-collector-cache</artifactId> <artifactId>apm-collector-cache</artifactId>
<packaging>jar</packaging> <packaging>pom</packaging>
<modules>
<module>collector-cache-define</module>
<module>collector-cache-guava-provider</module>
</modules>
<dependencies> <dependencies>
<dependency> <dependency>
......
...@@ -25,13 +25,27 @@ import java.util.Map; ...@@ -25,13 +25,27 @@ import java.util.Map;
* @author peng-yongsheng * @author peng-yongsheng
*/ */
public class DAOContainer { public class DAOContainer {
private Map<String, AbstractDAO> daos = new HashMap<>(); private Map<String, DAO> daoImplMap;
private Map<String, IPersistenceDAO> persistenceDaoImpl;
public void put(String interfaceName, AbstractDAO abstractDao) { public DAOContainer() {
daos.put(interfaceName, abstractDao); daoImplMap = new HashMap<>();
persistenceDaoImpl = new HashMap<>();
} }
public AbstractDAO get(String interfaceName) { public void put(String interfaceName, DAO daoImpl) {
return daos.get(interfaceName); if (daoImpl instanceof IPersistenceDAO) {
persistenceDaoImpl.put(interfaceName, (IPersistenceDAO)daoImpl);
} else {
daoImplMap.put(interfaceName, daoImpl);
}
}
public DAO get(String interfaceName) {
return daoImplMap.get(interfaceName);
}
public IPersistenceDAO getPersistenceDAO(String interfaceName) {
return persistenceDaoImpl.get(interfaceName);
} }
} }
...@@ -23,7 +23,7 @@ import org.skywalking.apm.collector.core.data.Data; ...@@ -23,7 +23,7 @@ import org.skywalking.apm.collector.core.data.Data;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
public interface IPersistenceDAO<Insert, Update, DataImpl extends Data> { public interface IPersistenceDAO<Insert, Update, DataImpl extends Data> extends DAO {
DataImpl get(String id); DataImpl get(String id);
Insert prepareBatchInsert(DataImpl data); Insert prepareBatchInsert(DataImpl data);
......
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
package org.skywalking.apm.collector.storage.dao; package org.skywalking.apm.collector.storage.dao;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
public interface IInstanceCacheDAO { public interface IInstanceCacheDAO extends DAO {
int getApplicationId(int applicationInstanceId); int getApplicationId(int applicationInstanceId);
} }
...@@ -18,10 +18,12 @@ ...@@ -18,10 +18,12 @@
package org.skywalking.apm.collector.storage.dao; package org.skywalking.apm.collector.storage.dao;
import org.skywalking.apm.collector.storage.base.dao.DAO;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
public interface IServiceNameCacheDAO { public interface IServiceNameCacheDAO extends DAO {
String getServiceName(int serviceId); String getServiceName(int serviceId);
int getServiceId(int applicationId, String serviceName); int getServiceId(int applicationId, String serviceName);
......
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
package org.skywalking.apm.collector.storage.es.service; package org.skywalking.apm.collector.storage.es.service;
import org.skywalking.apm.collector.storage.base.dao.AbstractDAO; import org.skywalking.apm.collector.storage.base.dao.DAO;
import org.skywalking.apm.collector.storage.base.dao.DAOContainer; import org.skywalking.apm.collector.storage.base.dao.DAOContainer;
import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
import org.skywalking.apm.collector.storage.service.DAOService; import org.skywalking.apm.collector.storage.service.DAOService;
/** /**
...@@ -33,7 +34,11 @@ public class ElasticSearchDAOService implements DAOService { ...@@ -33,7 +34,11 @@ public class ElasticSearchDAOService implements DAOService {
this.daoContainer = daoContainer; this.daoContainer = daoContainer;
} }
@Override public AbstractDAO get(Class<AbstractDAO> daoInterfaceClass) { @Override public DAO get(Class<? extends DAO> daoInterfaceClass) {
return daoContainer.get(daoInterfaceClass.getName()); return daoContainer.get(daoInterfaceClass.getName());
} }
@Override public IPersistenceDAO getPersistenceDAO(Class<? extends IPersistenceDAO> daoInterfaceClass) {
return daoContainer.getPersistenceDAO(daoInterfaceClass.getName());
}
} }
...@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory; ...@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO { public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
private final Logger logger = LoggerFactory.getLogger(InstanceH2UIDAO.class); private final Logger logger = LoggerFactory.getLogger(InstanceH2UIDAO.class);
private static final String GET_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? limit 1"; private static final String GET_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? limit 1";
private static final String GET_INST_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? and {3} = ? limit 1"; private static final String GET_INST_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? and {3} = ? limit 1";
private static final String GET_INSTANCE_SQL = "select * from {0} where {1} = ?"; private static final String GET_INSTANCE_SQL = "select * from {0} where {1} = ?";
...@@ -96,7 +96,6 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO { ...@@ -96,7 +96,6 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
logger.debug("applicationId: {}", applicationId); logger.debug("applicationId: {}", applicationId);
JsonObject application = new JsonObject(); JsonObject application = new JsonObject();
application.addProperty("applicationId", applicationId); application.addProperty("applicationId", applicationId);
application.addProperty("applicationCode", ApplicationCache.get(applicationId));
application.addProperty("instanceCount", rs.getInt("cnt")); application.addProperty("instanceCount", rs.getInt("cnt"));
applications.add(application); applications.add(application);
} }
......
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
package org.skywalking.apm.collector.storage.h2.service; package org.skywalking.apm.collector.storage.h2.service;
import org.skywalking.apm.collector.storage.base.dao.AbstractDAO; import org.skywalking.apm.collector.storage.base.dao.DAO;
import org.skywalking.apm.collector.storage.base.dao.DAOContainer; import org.skywalking.apm.collector.storage.base.dao.DAOContainer;
import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
import org.skywalking.apm.collector.storage.service.DAOService; import org.skywalking.apm.collector.storage.service.DAOService;
/** /**
...@@ -33,7 +34,11 @@ public class H2DAOService implements DAOService { ...@@ -33,7 +34,11 @@ public class H2DAOService implements DAOService {
this.daoContainer = daoContainer; this.daoContainer = daoContainer;
} }
@Override public AbstractDAO get(Class<AbstractDAO> daoInterfaceClass) { @Override public DAO get(Class<? extends DAO> daoInterfaceClass) {
return daoContainer.get(daoInterfaceClass.getName()); return daoContainer.get(daoInterfaceClass.getName());
} }
@Override public IPersistenceDAO getPersistenceDAO(Class<? extends IPersistenceDAO> daoInterfaceClass) {
return daoContainer.getPersistenceDAO(daoInterfaceClass.getName());
}
} }
...@@ -29,16 +29,4 @@ ...@@ -29,16 +29,4 @@
<artifactId>collector-stream-define</artifactId> <artifactId>collector-stream-define</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<<<<<<< HEAD </project>
</project> \ No newline at end of file
=======
<dependencies>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>queue-component</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
>>>>>>> 406c4f52d8251eb81aa868ec38f17789e18e0dc0
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册