/*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

package org.opendaylight.controller.netconf.confignetconfconnector.osgi;

import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;

import javax.annotation.concurrent.GuardedBy;

public class YangStoreServiceImpl implements YangStoreService {
    private final SchemaContextProvider service;
    @GuardedBy("this")
    private YangStoreSnapshotImpl cache = null;

    public YangStoreServiceImpl(SchemaContextProvider service) {
        this.service = service;
    }

    @Override
    public synchronized YangStoreSnapshotImpl getYangStoreSnapshot() throws YangStoreException {
        if (cache == null) {
            cache = new YangStoreSnapshotImpl(service.getSchemaContext());
        }
        return cache;
    }

    /**
     * Called when schema context changes, invalidates cache.
     */
    public synchronized void refresh() {
        cache = null;
    }
}

@@ -376,16 +376,52 @@
 .osgi;%0A%0A
+import java.lang.ref.SoftReference;%0A
 import o
@@ -680,16 +680,30 @@
 private 
+SoftReference%3C
 YangStor
@@ -715,16 +715,17 @@
 shotImpl
+%3E
  cache =
@@ -725,20 +725,41 @@
 cache = 
+new SoftReference%3C%3E(
 null
+)
 ;%0A%0A    p
@@ -980,17 +980,92 @@
     
-if (cache
+YangStoreSnapshotImpl yangStoreSnapshot = cache.get();%0A        if (yangStoreSnapshot
  == 
@@ -1080,29 +1080,41 @@
             
-cache
+yangStoreSnapshot
  = new YangS
@@ -1171,30 +1171,102 @@
     
-%7D%0A        return cache
+    cache = new SoftReference%3C%3E(yangStoreSnapshot);%0A        %7D%0A        return yangStoreSnapshot
 ;%0A  
@@ -1406,15 +1406,16 @@
 ache
- = null
+.clear()
 ;%0A  

Store yang store snapshot cache using soft reference.