// // DataFace.cs // // Author: // Carsten Sonne Larsen // // Copyright (c) 2013 Carsten Sonne Larsen // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; using Ntp.Analyzer.Log; using Ntp.Analyzer.Data.Cache; using Ntp.Analyzer.Data.Static; namespace Ntp.Analyzer.Data { /// /// Singleton facade class used to access memory persistent data. /// public sealed class DataFace { private static readonly DataFace instance = new DataFace (); private readonly Object locker = new Object (); private readonly LogBase log; private NtpConfCache ntpConfigCache; private NtpqCache ntpqCache; private HostDatabaseMapper hostMapper; private PeerDatabaseMapper peerMapper; private TimeServerDatabaseMapper serverMapper; /// /// Initializes a new instance of the class. /// private DataFace () { log = DataConnection.Log; } /// /// Gets the Singleton instance. /// /// The instance. public static DataFace Instance { get { return instance; } } /// /// Gets the ntp config cache. /// /// The ntp config cache. public NtpConfCache NtpConfigCache { get { lock (locker) { if (ntpConfigCache == null) { ntpConfigCache = new NtpConfCache (log); } } return ntpConfigCache; } } /// /// Gets the ntpq cache. /// /// The ntpq cache. public NtpqCache NtpqCache { get { lock (locker) { if (ntpqCache == null) { ntpqCache = new NtpqCache (log); } } return ntpqCache; } } /// /// Gets the host mapper. /// /// The hosts. public HostDatabaseMapper Hosts { get { lock (locker) { if (hostMapper == null) { hostMapper = new HostDatabaseMapper (log); } } return hostMapper; } } /// /// Gets the peer mapper. /// /// The peers. public PeerDatabaseMapper Peers { get { lock (locker) { if (peerMapper == null) { peerMapper = new PeerDatabaseMapper (Servers, log); } } return peerMapper; } } /// /// Gets the time server mapper. /// /// The servers. public TimeServerDatabaseMapper Servers { get { lock (locker) { if (serverMapper == null) { serverMapper = new TimeServerDatabaseMapper (log); } } return serverMapper; } } /// /// Gets the host reading mapper. /// /// The host readings. public HostReadingDatabaseMapper HostReadings { get { return new HostReadingDatabaseMapper (Hosts, Peers, log); } } /// /// Gets the host IO reading mapper. /// /// The host IO reading mapper. public HostIOReadingDatabaseMapper HostIOReadings { get { return new HostIOReadingDatabaseMapper (Hosts, log); } } /// /// Gets the peer reading mapper. /// /// The peer readings. public PeerReadingDatabaseMapper PeerReadings { get { return new PeerReadingDatabaseMapper (Hosts, Peers, log); } } } }