From 2938eaf93df945f617256164cf6c9229788d6373 Mon Sep 17 00:00:00 2001 From: sameera910409 Date: Mon, 18 Sep 2017 14:13:49 +0530 Subject: [PATCH] fixes https://github.com/wso2/product-iots/issues/1417 --- .../core/config/cache/DeviceCacheConfiguration.java | 10 ++++++++++ .../carbon/device/mgt/core/util/DeviceManagerUtil.java | 8 ++++++++ .../src/main/resources/conf/cdm-config.xml | 1 + .../src/main/resources/dbscripts/cdm/mysql.sql | 2 ++ 4 files changed, 21 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/cache/DeviceCacheConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/cache/DeviceCacheConfiguration.java index 34a813fbcfb..e4c100760c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/cache/DeviceCacheConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/cache/DeviceCacheConfiguration.java @@ -26,6 +26,7 @@ public class DeviceCacheConfiguration { private boolean isEnabled; private int expiryTime; + private long capacity; @XmlElement(name = "Enable", required = true) public boolean isEnabled() { @@ -44,4 +45,13 @@ public class DeviceCacheConfiguration { public void setExpiryTime(int expiryTime) { this.expiryTime = expiryTime; } + + @XmlElement(name = "Capacity", required = true) + public long getCapacity() { + return capacity; + } + + public void setCapacity(long capacity) { + this.capacity = capacity; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index c3ceec40b76..19ab94ca8a6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.caching.impl.CacheImpl; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService; import org.wso2.carbon.device.mgt.common.Device; @@ -492,6 +493,7 @@ public final class DeviceManagerUtil { public static void initializeDeviceCache() { DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); int deviceCacheExpiry = config.getDeviceCacheConfiguration().getExpiryTime(); + long deviceCacheCapacity = config.getDeviceCacheConfiguration().getCapacity(); CacheManager manager = getCacheManager(); if (config.getDeviceCacheConfiguration().isEnabled()) { if(!isDeviceCacheInitialized) { @@ -502,6 +504,10 @@ public final class DeviceManagerUtil { setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.SECONDS, deviceCacheExpiry)).setExpiry(CacheConfiguration.ExpiryType.ACCESSED, new CacheConfiguration. Duration(TimeUnit.SECONDS, deviceCacheExpiry)).setStoreByValue(true).build(); + if(deviceCacheCapacity > 0 ) { + ((CacheImpl)(manager.getCache(DeviceManagementConstants.DEVICE_CACHE))). + setCapacity(deviceCacheCapacity); + } } else { manager.getCache(DeviceManagementConstants.DEVICE_CACHE); } @@ -512,6 +518,8 @@ public final class DeviceManagerUtil { setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.SECONDS, deviceCacheExpiry)).setExpiry(CacheConfiguration.ExpiryType.ACCESSED, new CacheConfiguration. Duration(TimeUnit.SECONDS, deviceCacheExpiry)).setStoreByValue(true).build(); + ((CacheImpl)(manager.getCache(DeviceManagementConstants.DEVICE_CACHE))). + setCapacity(deviceCacheCapacity); } else { Caching.getCacheManager().getCache(DeviceManagementConstants.DEVICE_CACHE); } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 1368469451b..1e0097f7f18 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -77,6 +77,7 @@ true 600 + 10000 true diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 7fb1098521a..be0586cd733 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -9,6 +9,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( )ENGINE = InnoDB; CREATE INDEX IDX_DEVICE_TYPE ON DM_DEVICE_TYPE (NAME, PROVIDER_TENANT_ID); +CREATE INDEX IDX_DEVICE_NAME ON DM_DEVICE_TYPE (NAME); +CREATE INDEX IDX_DEVICE_TYPE_DEVICE_NAME ON DM_DEVICE_TYPE(ID, NAME); CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL,