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 930cbf7b9d62053ea8dd595d0f3f55f18fe08c03..8327604ddc668a1696da687424c2e3a8b14dca32 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 05ef93a0591cc36532b1b9fde216e8bd5545865e..7f6fd05605a917ff4ee21773800172a2e347de30 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 0000000000000000000000000000000000000000..9661e414b02d6bf6d74677933b21df28e5235b76 --- /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 0000000000000000000000000000000000000000..aed9cb7199a41364d94b83e25a3bc9c4237d2546 --- /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 0000000000000000000000000000000000000000..46fc477a5c815e2001bcea8f1e29e6e0b108c1a4 --- /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 0000000000000000000000000000000000000000..fbccc3a217ff34f898c094f8342ae6e75a8989d0 --- /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 0000000000000000000000000000000000000000..bd155c8e6ab4c6be88e6c0cf06596a1cac716fec --- /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 0000000000000000000000000000000000000000..54de07605471a3cd2c234adf89ec9308b8bfd549 --- /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 0000000000000000000000000000000000000000..3f6af42aad02e59efa6d8db1b39d0349d074154d --- /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 0000000000000000000000000000000000000000..b6069953bd65b9181ac7d34bf041b0431b6aa7dc --- /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 0000000000000000000000000000000000000000..7644018ceb28cefb11596a3155a5fa991ac1af96 --- /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 cbf2357692a61973ad1a1b2e28732e292ef7bc7f..e167a3bc2d3cd5176e96990cb6dc2135d909c42f 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 07a818dbcc102dedf0222248bced1e3a8056041b..82f4311db4fd7a1c8f6d8d7f6fd6b9905d8a592a 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 14f1d5a46b6bb1a488ab910b4ace8125c45a4b4e..8d7fe1defa3a4cba18d7e7f8e20835794dd9b94b 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 528f783c8de11df4f667a27d0b81a23eac00fb9d..7056f4e8ecace5289283b9bee302183bbca1f4fe 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 0000000000000000000000000000000000000000..b944ba647f34cb987d2a52a7d55694a50d4a1e92 --- /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 55983ea3abcf895a5668669d8dd64055da042235..37eb5b40c2f9a237994ab03aba157589e628ea64 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 1d109e013e30793c2264a6ceae36ab6f7942a62b..2559bfb0ebc7a6cd6109c1a39cd7f613f8889d8a 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 7fef53189be3322ea9254166cd750e89274239b6..8219b5c998c006c5f656856669fa47fc47ec7429 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 3df32233bd750a8ef210e4b12967b4cdf3f0775d..7bda556ceac1ba681228f16cdb174fee55952023 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 f9d352ded25914787d30f294b2da190de7a7bcd7..162909c40b06ddc2d07033076f138f1c0c5115a5 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 e764fa5713bef470313f6683f151e02094736682..933b30bc32b9a697ae7d1dead1d7e9871578f4af 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 e68639a1ce5f4cc8b83ceece80474783b6e69451..f745133140f664e88511e76396f39c9ea9b8d27c 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 4c74078e8dce91289b09e24f2f56c632f8d77242..0075876105bc8cf83c4764dcd36f928ae9c67afb 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 d91106e08fedffab6005735b1444505971771e5e..c39ff0609b7bf58f277d9fd15485418658435002 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