Change-Id: I9b159db83ba204b4a636f2314fd4fc2e7b6f654c
Signed-off-by: Tomas Olvecky <tolvecky@cisco.com>
package org.opendaylight.controller.netconf.confignetconfconnector.osgi;
package org.opendaylight.controller.netconf.confignetconfconnector.osgi;
+import java.lang.ref.SoftReference;
import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
import javax.annotation.concurrent.GuardedBy;
public class YangStoreServiceImpl implements YangStoreService {
private final SchemaContextProvider service;
@GuardedBy("this")
public class YangStoreServiceImpl implements YangStoreService {
private final SchemaContextProvider service;
@GuardedBy("this")
- private YangStoreSnapshotImpl cache = null;
+ private SoftReference<YangStoreSnapshotImpl> cache = new SoftReference<>(null);
public YangStoreServiceImpl(SchemaContextProvider service) {
this.service = service;
public YangStoreServiceImpl(SchemaContextProvider service) {
this.service = service;
@Override
public synchronized YangStoreSnapshotImpl getYangStoreSnapshot() throws YangStoreException {
@Override
public synchronized YangStoreSnapshotImpl getYangStoreSnapshot() throws YangStoreException {
- if (cache == null) {
- cache = new YangStoreSnapshotImpl(service.getSchemaContext());
+ YangStoreSnapshotImpl yangStoreSnapshot = cache.get();
+ if (yangStoreSnapshot == null) {
+ yangStoreSnapshot = new YangStoreSnapshotImpl(service.getSchemaContext());
+ cache = new SoftReference<>(yangStoreSnapshot);
+ return yangStoreSnapshot;
}
/**
* Called when schema context changes, invalidates cache.
*/
public synchronized void refresh() {
}
/**
* Called when schema context changes, invalidates cache.
*/
public synchronized void refresh() {