From b1e2ebd4d2256ab1e9fd4460c63771bdc522c437 Mon Sep 17 00:00:00 2001 From: peng-yongsheng <8082209@qq.com> Date: Thu, 9 Nov 2017 18:20:55 +0800 Subject: [PATCH] Refactor cache module to provide cache services. --- .../jvm/CpuMetricPersistenceWorker.java | 4 +- apm-collector/apm-collector-boot/pom.xml | 7 ++ .../collector-cache-define/pom.xml | 33 +++++++++ .../apm/collector/cache/CacheModule.java | 41 ++++++++++ .../service/ApplicationCacheService.java | 30 ++++++++ .../cache/service/InstanceCacheService.java | 28 +++++++ .../cache/service/ServiceIdCacheService.java | 28 +++++++ .../service/ServiceNameCacheService.java | 30 ++++++++ ...kywalking.apm.collector.core.module.Module | 19 +++++ .../collector-cache-guava-provider/pom.xml | 40 ++++++++++ .../cache/guava/CacheModuleGuavaProvider.java | 74 +++++++++++++++++++ .../ApplicationCacheGuavaService.java} | 27 ++++--- .../service/InstanceCacheGuavaService.java} | 21 ++++-- .../service/ServiceIdCacheGuavaService.java} | 22 ++++-- .../ServiceNameCacheGuavaService.java} | 24 +++--- ...g.apm.collector.core.module.ModuleProvider | 19 +++++ apm-collector/apm-collector-cache/pom.xml | 6 +- .../storage/base/dao/DAOContainer.java | 24 ++++-- .../storage/base/dao/IPersistenceDAO.java | 2 +- .../storage/dao/IInstanceCacheDAO.java | 4 +- .../storage/dao/IServiceNameCacheDAO.java | 4 +- .../es/service/ElasticSearchDAOService.java | 9 ++- .../storage/h2/dao/InstanceH2UIDAO.java | 3 +- .../storage/h2/service/H2DAOService.java | 9 ++- .../collector-stream-define/pom.xml | 14 +--- 25 files changed, 458 insertions(+), 64 deletions(-) create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/pom.xml create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/CacheModule.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ApplicationCacheService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/InstanceCacheService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceIdCacheService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceNameCacheService.java create mode 100644 apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module create mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/pom.xml create mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java rename apm-collector/apm-collector-cache/{src/main/java/org/skywalking/apm/collector/cache/ApplicationCache.java => collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java} (67%) rename apm-collector/apm-collector-cache/{src/main/java/org/skywalking/apm/collector/cache/InstanceCache.java => collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java} (65%) rename apm-collector/apm-collector-cache/{src/main/java/org/skywalking/apm/collector/cache/ServiceIdCache.java => collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java} (66%) rename apm-collector/apm-collector-cache/{src/main/java/org/skywalking/apm/collector/cache/ServiceNameCache.java => collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java} (70%) create mode 100644 apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider diff --git a/apm-collector/apm-collector-agent/collector-agent-stream/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java b/apm-collector/apm-collector-agent/collector-agent-stream/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java index 930cbf7b9d..8327604ddc 100644 --- a/apm-collector/apm-collector-agent/collector-agent-stream/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java +++ b/apm-collector/apm-collector-agent/collector-agent-stream/src/main/java/org/skywalking/apm/collector/agent/stream/worker/jvm/CpuMetricPersistenceWorker.java @@ -50,9 +50,9 @@ public class CpuMetricPersistenceWorker extends PersistenceWorker { + public static class Factory extends AbstractLocalAsyncWorkerProvider { - public Factory(DAOService daoService, QueueCreatorService queueCreatorService) { + public Factory(DAOService daoService, QueueCreatorService queueCreatorService) { super(daoService, queueCreatorService); } diff --git a/apm-collector/apm-collector-boot/pom.xml b/apm-collector/apm-collector-boot/pom.xml index 05ef93a059..7f6fd05605 100644 --- a/apm-collector/apm-collector-boot/pom.xml +++ b/apm-collector/apm-collector-boot/pom.xml @@ -136,5 +136,12 @@ ${project.version} + + + org.skywalking + collector-cache-guava-provider + ${project.version} + + \ No newline at end of file diff --git a/apm-collector/apm-collector-cache/collector-cache-define/pom.xml b/apm-collector/apm-collector-cache/collector-cache-define/pom.xml new file mode 100644 index 0000000000..9661e414b0 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/pom.xml @@ -0,0 +1,33 @@ + + + + + + apm-collector-cache + org.skywalking + 3.2.4-2017 + + 4.0.0 + + collector-cache-define + jar + + \ No newline at end of file diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/CacheModule.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/CacheModule.java new file mode 100644 index 0000000000..aed9cb7199 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/CacheModule.java @@ -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}; + } +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ApplicationCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ApplicationCacheService.java new file mode 100644 index 0000000000..46fc477a5c --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ApplicationCacheService.java @@ -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); +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/InstanceCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/InstanceCacheService.java new file mode 100644 index 0000000000..fbccc3a217 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/InstanceCacheService.java @@ -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); +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceIdCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceIdCacheService.java new file mode 100644 index 0000000000..bd155c8e6a --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceIdCacheService.java @@ -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); +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceNameCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceNameCacheService.java new file mode 100644 index 0000000000..54de076054 --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/skywalking/apm/collector/cache/service/ServiceNameCacheService.java @@ -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); +} diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module new file mode 100644 index 0000000000..3f6af42aad --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.Module @@ -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 \ No newline at end of file diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/pom.xml b/apm-collector/apm-collector-cache/collector-cache-guava-provider/pom.xml new file mode 100644 index 0000000000..b6069953bd --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/pom.xml @@ -0,0 +1,40 @@ + + + + + + apm-collector-cache + org.skywalking + 3.2.4-2017 + + 4.0.0 + + collector-cache-guava-provider + jar + + + + org.skywalking + collector-cache-define + ${project.version} + + + \ No newline at end of file diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java new file mode 100644 index 0000000000..7644018ceb --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/CacheModuleGuavaProvider.java @@ -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 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}; + } +} diff --git a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ApplicationCache.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java similarity index 67% rename from apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ApplicationCache.java rename to apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java index cbf2357692..e167a3bc2d 100644 --- a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ApplicationCache.java +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java @@ -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 CODE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build(); + private final Cache 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 ID_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build(); + private final Cache 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 { diff --git a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/InstanceCache.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java similarity index 65% rename from apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/InstanceCache.java rename to apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java index 07a818dbcc..82f4311db4 100644 --- a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/InstanceCache.java +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/InstanceCacheGuavaService.java @@ -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 INSTANCE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build(); + private final Cache 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 { diff --git a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceIdCache.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java similarity index 66% rename from apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceIdCache.java rename to apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java index 14f1d5a46b..8d7fe1defa 100644 --- a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceIdCache.java +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceIdCacheGuavaService.java @@ -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 SERVICE_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build(); + private final Cache 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 { diff --git a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceNameCache.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java similarity index 70% rename from apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceNameCache.java rename to apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java index 528f783c8d..7056f4e8ec 100644 --- a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceNameCache.java +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java @@ -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 CACHE = CacheBuilder.newBuilder().maximumSize(10000).build(); + private final Cache 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) { diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider new file mode 100644 index 0000000000..b944ba647f --- /dev/null +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/resources/META-INF/services/org.skywalking.apm.collector.core.module.ModuleProvider @@ -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 \ No newline at end of file diff --git a/apm-collector/apm-collector-cache/pom.xml b/apm-collector/apm-collector-cache/pom.xml index 55983ea3ab..37eb5b40c2 100644 --- a/apm-collector/apm-collector-cache/pom.xml +++ b/apm-collector/apm-collector-cache/pom.xml @@ -10,7 +10,11 @@ 4.0.0 apm-collector-cache - jar + pom + + collector-cache-define + collector-cache-guava-provider + diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/DAOContainer.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/DAOContainer.java index 1d109e013e..2559bfb0eb 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/DAOContainer.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/DAOContainer.java @@ -25,13 +25,27 @@ import java.util.Map; * @author peng-yongsheng */ public class DAOContainer { - private Map daos = new HashMap<>(); + private Map daoImplMap; + private Map 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); } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java index 7fef53189b..8219b5c998 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/base/dao/IPersistenceDAO.java @@ -23,7 +23,7 @@ import org.skywalking.apm.collector.core.data.Data; /** * @author peng-yongsheng */ -public interface IPersistenceDAO { +public interface IPersistenceDAO extends DAO { DataImpl get(String id); Insert prepareBatchInsert(DataImpl data); diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java index 3df32233bd..7bda556cea 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java @@ -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); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java index f9d352ded2..162909c40b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java @@ -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); diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/service/ElasticSearchDAOService.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/service/ElasticSearchDAOService.java index e764fa5713..933b30bc32 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/service/ElasticSearchDAOService.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/service/ElasticSearchDAOService.java @@ -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 daoInterfaceClass) { + @Override public DAO get(Class daoInterfaceClass) { return daoContainer.get(daoInterfaceClass.getName()); } + + @Override public IPersistenceDAO getPersistenceDAO(Class daoInterfaceClass) { + return daoContainer.getPersistenceDAO(daoInterfaceClass.getName()); + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java index e68639a1ce..f745133140 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java @@ -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); } diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/service/H2DAOService.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/service/H2DAOService.java index 4c74078e8d..0075876105 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/service/H2DAOService.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/service/H2DAOService.java @@ -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 daoInterfaceClass) { + @Override public DAO get(Class daoInterfaceClass) { return daoContainer.get(daoInterfaceClass.getName()); } + + @Override public IPersistenceDAO getPersistenceDAO(Class daoInterfaceClass) { + return daoContainer.getPersistenceDAO(daoInterfaceClass.getName()); + } } diff --git a/apm-collector/apm-collector-stream/collector-stream-define/pom.xml b/apm-collector/apm-collector-stream/collector-stream-define/pom.xml index d91106e08f..c39ff0609b 100644 --- a/apm-collector/apm-collector-stream/collector-stream-define/pom.xml +++ b/apm-collector/apm-collector-stream/collector-stream-define/pom.xml @@ -29,16 +29,4 @@ collector-stream-define jar -<<<<<<< HEAD - -======= - - - - org.skywalking - queue-component - ${project.version} - - - ->>>>>>> 406c4f52d8251eb81aa868ec38f17789e18e0dc0 + \ No newline at end of file -- GitLab