2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.confignetconfconnector.osgi;
11 import java.lang.ref.SoftReference;
12 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
14 import javax.annotation.concurrent.GuardedBy;
16 public class YangStoreServiceImpl implements YangStoreService {
17 private final SchemaContextProvider service;
19 private SoftReference<YangStoreSnapshotImpl> cache = new SoftReference<>(null);
21 public YangStoreServiceImpl(SchemaContextProvider service) {
22 this.service = service;
26 public synchronized YangStoreSnapshotImpl getYangStoreSnapshot() throws YangStoreException {
27 YangStoreSnapshotImpl yangStoreSnapshot = cache.get();
28 if (yangStoreSnapshot == null) {
29 yangStoreSnapshot = new YangStoreSnapshotImpl(service.getSchemaContext());
30 cache = new SoftReference<>(yangStoreSnapshot);
32 return yangStoreSnapshot;
36 * Called when schema context changes, invalidates cache.
38 public synchronized void refresh() {