Skip to content

Package: DatastoreCacheManager

DatastoreCacheManager

nameinstructionbranchcomplexitylinemethod
DatastoreCacheManager()
M: 51 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getChannelsCache()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getClientsCache()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getInstance()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMetadataCache()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMetricsCache()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.datastore.internal;
14:
15: import org.eclipse.kapua.commons.cache.LocalCache;
16: import org.eclipse.kapua.service.datastore.internal.schema.Metadata;
17: import org.eclipse.kapua.service.datastore.internal.setting.DatastoreSettings;
18: import org.eclipse.kapua.service.datastore.internal.setting.DatastoreSettingsKey;
19:
20: /**
21: * Datastore cache manager.<br>
22: * It keeps informations about channels, metrics and clients to speed up the store operation and avoid time consuming unnecessary operations.
23: *
24: * @since 1.0.0
25: */
26: public class DatastoreCacheManager {
27:
28: private static final DatastoreCacheManager INSTANCE = new DatastoreCacheManager();
29:
30: private final LocalCache<String, Metadata> schemaCache;
31: private final LocalCache<String, Boolean> channelsCache;
32: private final LocalCache<String, Boolean> metricsCache;
33: private final LocalCache<String, Boolean> clientsCache;
34:
35: private DatastoreCacheManager() {
36: DatastoreSettings config = DatastoreSettings.getInstance();
37: int expireAfter = config.getInt(DatastoreSettingsKey.CONFIG_CACHE_LOCAL_EXPIRE_AFTER);
38: int sizeMax = config.getInt(DatastoreSettingsKey.CONFIG_CACHE_LOCAL_SIZE_MAXIMUM);
39: int sizeMaxMetadata = config.getInt(DatastoreSettingsKey.CONFIG_CACHE_METADATA_LOCAL_SIZE_MAXIMUM);
40:
41: // TODO set expiration to happen frequently because the reset cache method will not get
42: // called from service clients any more
43: channelsCache = new LocalCache<>(sizeMax, expireAfter, false);
44: metricsCache = new LocalCache<>(sizeMax, expireAfter, false);
45: clientsCache = new LocalCache<>(sizeMax, expireAfter, false);
46: schemaCache = new LocalCache<>(sizeMaxMetadata, null);
47: }
48:
49: /**
50: * Get the cache manager instance
51: *
52: * @return
53: * @since 1.0.0
54: */
55: public static DatastoreCacheManager getInstance() {
56: return INSTANCE;
57: }
58:
59: /**
60: * Get the channels informations cache
61: *
62: * @return
63: * @since 1.0.0
64: */
65: public LocalCache<String, Boolean> getChannelsCache() {
66: return channelsCache;
67: }
68:
69: /**
70: * Get the metrics informations cache
71: *
72: * @return
73: * @since 1.0.0
74: */
75: public LocalCache<String, Boolean> getMetricsCache() {
76: return metricsCache;
77: }
78:
79: /**
80: * Get the clients informations cache
81: *
82: * @return
83: * @since 1.0.0
84: */
85: public LocalCache<String, Boolean> getClientsCache() {
86: return clientsCache;
87: }
88:
89: /**
90: * Get the metadata informations cache
91: *
92: * @return
93: * @since 1.0.0
94: */
95: public LocalCache<String, Metadata> getMetadataCache() {
96: return schemaCache;
97: }
98: }