Merge pull request #968 from sameeragunarathne/master

fixes https://github.com/wso2/product-iots/issues/1417
revert-70aa11f8
Harshan Liyanage 7 years ago committed by GitHub
commit 455f56405b

@ -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;
}
}

@ -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.<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE))).
setCapacity(deviceCacheCapacity);
}
} else {
manager.<DeviceCacheKey, Device>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.<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE))).
setCapacity(deviceCacheCapacity);
} else {
Caching.getCacheManager().<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE);
}

@ -77,6 +77,7 @@
<DeviceCacheConfiguration>
<Enable>true</Enable>
<ExpiryTime>600</ExpiryTime>
<Capacity>10000</Capacity>
</DeviceCacheConfiguration>
<CertificateCacheConfiguration>
<Enable>true</Enable>

@ -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,

Loading…
Cancel
Save