Refactor cache module to provide cache services.
This commit is contained in:
parent
737e9c53b3
commit
b1e2ebd4d2
|
|
@ -50,9 +50,9 @@ public class CpuMetricPersistenceWorker extends PersistenceWorker<CpuMetric, Cpu
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,5 +136,12 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- stream provider -->
|
||||
<!-- cache provider -->
|
||||
<dependency>
|
||||
<groupId>org.skywalking</groupId>
|
||||
<artifactId>collector-cache-guava-provider</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- cache provider -->
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?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>
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#
|
||||
# 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
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?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>
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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 @@
|
|||
* 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.CacheBuilder;
|
||||
import org.skywalking.apm.collector.cache.service.ApplicationCacheService;
|
||||
import org.skywalking.apm.collector.core.util.Const;
|
||||
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.service.DAOService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
IApplicationCacheDAO dao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName());
|
||||
private final DAOService daoService;
|
||||
|
||||
public ApplicationCacheGuavaService(DAOService daoService) {
|
||||
this.daoService = daoService;
|
||||
}
|
||||
|
||||
public int get(String applicationCode) {
|
||||
IApplicationCacheDAO dao = (IApplicationCacheDAO)daoService.get(IApplicationCacheDAO.class);
|
||||
|
||||
int applicationId = 0;
|
||||
try {
|
||||
|
|
@ -55,10 +62,10 @@ public class ApplicationCache {
|
|||
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) {
|
||||
IApplicationCacheDAO dao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName());
|
||||
public String get(int applicationId) {
|
||||
IApplicationCacheDAO dao = (IApplicationCacheDAO)daoService.get(IApplicationCacheDAO.class);
|
||||
|
||||
String applicationCode = Const.EMPTY_STRING;
|
||||
try {
|
||||
|
|
@ -16,26 +16,33 @@
|
|||
* 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.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.service.DAOService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
IInstanceCacheDAO dao = (IInstanceCacheDAO)DAOContainer.INSTANCE.get(IInstanceCacheDAO.class.getName());
|
||||
private final DAOService daoService;
|
||||
|
||||
public InstanceCacheGuavaService(DAOService daoService) {
|
||||
this.daoService = daoService;
|
||||
}
|
||||
|
||||
public int get(int applicationInstanceId) {
|
||||
IInstanceCacheDAO dao = (IInstanceCacheDAO)daoService.get(IInstanceCacheDAO.class);
|
||||
|
||||
int applicationId = 0;
|
||||
try {
|
||||
|
|
@ -16,28 +16,34 @@
|
|||
* 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.CacheBuilder;
|
||||
import org.skywalking.apm.collector.cache.service.ServiceIdCacheService;
|
||||
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.service.DAOService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @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 static Cache<String, Integer> SERVICE_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
|
||||
private final Cache<String, Integer> SERVICE_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
|
||||
|
||||
public static int get(int applicationId, String serviceName) {
|
||||
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameCacheDAO.class.getName());
|
||||
private final DAOService daoService;
|
||||
|
||||
public ServiceIdCacheGuavaService(DAOService daoService) {
|
||||
this.daoService = daoService;
|
||||
}
|
||||
|
||||
public int get(int applicationId, String serviceName) {
|
||||
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)daoService.get(IServiceNameCacheDAO.class);
|
||||
|
||||
int serviceId = 0;
|
||||
try {
|
||||
|
|
@ -16,29 +16,35 @@
|
|||
* 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.CacheBuilder;
|
||||
import org.skywalking.apm.collector.cache.service.ServiceNameCacheService;
|
||||
import org.skywalking.apm.collector.core.util.Const;
|
||||
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.service.DAOService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @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 static Cache<Integer, String> CACHE = CacheBuilder.newBuilder().maximumSize(10000).build();
|
||||
private final Cache<Integer, String> CACHE = CacheBuilder.newBuilder().maximumSize(10000).build();
|
||||
|
||||
public static String get(int serviceId) {
|
||||
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameCacheDAO.class.getName());
|
||||
private final DAOService daoService;
|
||||
|
||||
public ServiceNameCacheGuavaService(DAOService daoService) {
|
||||
this.daoService = daoService;
|
||||
}
|
||||
|
||||
public String get(int serviceId) {
|
||||
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)daoService.get(IServiceNameCacheDAO.class);
|
||||
|
||||
String serviceName = Const.EMPTY_STRING;
|
||||
try {
|
||||
|
|
@ -57,7 +63,7 @@ public class ServiceNameCache {
|
|||
return serviceName;
|
||||
}
|
||||
|
||||
public static String getSplitServiceName(String serviceName) {
|
||||
public String getSplitServiceName(String serviceName) {
|
||||
if (StringUtils.isNotEmpty(serviceName)) {
|
||||
String[] serviceNames = serviceName.split(Const.ID_SPLIT);
|
||||
if (serviceNames.length == 2) {
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#
|
||||
# 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
|
||||
|
|
@ -10,7 +10,11 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<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>
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -25,13 +25,27 @@ import java.util.Map;
|
|||
* @author peng-yongsheng
|
||||
*/
|
||||
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) {
|
||||
daos.put(interfaceName, abstractDao);
|
||||
public DAOContainer() {
|
||||
daoImplMap = new HashMap<>();
|
||||
persistenceDaoImpl = new HashMap<>();
|
||||
}
|
||||
|
||||
public AbstractDAO get(String interfaceName) {
|
||||
return daos.get(interfaceName);
|
||||
public void put(String interfaceName, DAO daoImpl) {
|
||||
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;
|
|||
/**
|
||||
* @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);
|
||||
|
||||
Insert prepareBatchInsert(DataImpl data);
|
||||
|
|
|
|||
|
|
@ -18,9 +18,11 @@
|
|||
|
||||
package org.skywalking.apm.collector.storage.dao;
|
||||
|
||||
import org.skywalking.apm.collector.storage.base.dao.DAO;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface IInstanceCacheDAO {
|
||||
public interface IInstanceCacheDAO extends DAO {
|
||||
int getApplicationId(int applicationInstanceId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@
|
|||
|
||||
package org.skywalking.apm.collector.storage.dao;
|
||||
|
||||
import org.skywalking.apm.collector.storage.base.dao.DAO;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface IServiceNameCacheDAO {
|
||||
public interface IServiceNameCacheDAO extends DAO {
|
||||
String getServiceName(int serviceId);
|
||||
|
||||
int getServiceId(int applicationId, String serviceName);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
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.IPersistenceDAO;
|
||||
import org.skywalking.apm.collector.storage.service.DAOService;
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +34,11 @@ public class ElasticSearchDAOService implements DAOService {
|
|||
this.daoContainer = daoContainer;
|
||||
}
|
||||
|
||||
@Override public AbstractDAO get(Class<AbstractDAO> daoInterfaceClass) {
|
||||
@Override public DAO get(Class<? extends DAO> daoInterfaceClass) {
|
||||
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;
|
|||
public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
|
||||
|
||||
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_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} = ?";
|
||||
|
|
@ -96,7 +96,6 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
|
|||
logger.debug("applicationId: {}", applicationId);
|
||||
JsonObject application = new JsonObject();
|
||||
application.addProperty("applicationId", applicationId);
|
||||
application.addProperty("applicationCode", ApplicationCache.get(applicationId));
|
||||
application.addProperty("instanceCount", rs.getInt("cnt"));
|
||||
applications.add(application);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
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.IPersistenceDAO;
|
||||
import org.skywalking.apm.collector.storage.service.DAOService;
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +34,11 @@ public class H2DAOService implements DAOService {
|
|||
this.daoContainer = daoContainer;
|
||||
}
|
||||
|
||||
@Override public AbstractDAO get(Class<AbstractDAO> daoInterfaceClass) {
|
||||
@Override public DAO get(Class<? extends DAO> daoInterfaceClass) {
|
||||
return daoContainer.get(daoInterfaceClass.getName());
|
||||
}
|
||||
|
||||
@Override public IPersistenceDAO getPersistenceDAO(Class<? extends IPersistenceDAO> daoInterfaceClass) {
|
||||
return daoContainer.getPersistenceDAO(daoInterfaceClass.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,16 +29,4 @@
|
|||
|
||||
<artifactId>collector-stream-define</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<<<<<<< HEAD
|
||||
</project>
|
||||
=======
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.skywalking</groupId>
|
||||
<artifactId>queue-component</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
>>>>>>> 406c4f52d8251eb81aa868ec38f17789e18e0dc0
|
||||
</project>
|
||||
Loading…
Reference in New Issue