Esempio n. 1
0
 /**
  * Requests a RrdDb reference for the given RRD file path.<p>
  * <ul>
  * <li>If the file is already open, previously returned RrdDb reference will be returned. Its usage count
  * will be incremented by one.
  * <li>If the file is not already open and the number of already open RRD files is less than
  * {@link #INITIAL_CAPACITY}, the file will be open and a new RrdDb reference will be returned.
  * If the file is not already open and the number of already open RRD files is equal to
  * {@link #INITIAL_CAPACITY}, the method blocks until some RRD file is closed.
  * </ul>
  *
  * @param path Path to existing RRD file
  * @return reference for the give RRD file
  * @  Thrown in case of I/O error
  */
 public RrdDb requestRrdDb(String path)
 {
     lock (sync)
     {
         String canonicalPath = Util.getCanonicalPath(path);
         while (!rrdMap.ContainsKey(canonicalPath) && rrdMap.Count >= capacity)
         {
             Thread.Sleep(10);
         }
         if (rrdMap.ContainsKey(canonicalPath))
         {
             // already open, just increase usage count
             RrdEntry entry = rrdMap[canonicalPath];
             entry.count++;
             return(entry.rrdDb);
         }
         else
         {
             // not open, open it now and add to the map
             RrdDb rrdDb = new RrdDb(canonicalPath);
             rrdMap.Add(canonicalPath, new RrdEntry(rrdDb));
             return(rrdDb);
         }
     }
 }
Esempio n. 2
0
        /**
         * Requests a RrdDb reference for the given path. The file will be created from
         * external data (from XML dump, RRD file or RRDTool's binary RRD file).<p>
         * <ul>
         * <li>If the file with the path specified is already open,
         * the method blocks until the file is closed.
         * <li>If the file is not already open and the number of already open RRD files is less than
         * {@link #INITIAL_CAPACITY}, a new RRD file will be created and a its RrdDb reference will be returned.
         * If the file is not already open and the number of already open RRD files is equal to
         * {@link #INITIAL_CAPACITY}, the method blocks until some RRD file is closed.
         * </ul>
         *
         * @param path Path to RRD file which should be created
         * @param sourcePath Path to external data which is to be converted to Rrd4n's native RRD file format
         * @return Reference to the newly created RRD file
         * @  Thrown in case of I/O error
         */
        //public RrdDb requestRrdDb(String path, String sourcePath)  {
        //            lock (sync)
        //    {

        //    String canonicalPath = Util.getCanonicalPath(path);
        //    while (rrdMap.containsKey(canonicalPath) || rrdMap.size() >= capacity)
        //    {
        //        Thread.Sleep(10);
        //    }
        //    RrdDb rrdDb = new RrdDb(canonicalPath, sourcePath);
        //    rrdMap.put(canonicalPath, new RrdEntry(rrdDb));
        //    return rrdDb;
        //            }
        //}

        /**
         * Releases RrdDb reference previously obtained from the pool. When a reference is released, its usage
         * count is decremented by one. If usage count drops to zero, the underlying RRD file will be closed.
         *
         * @param rrdDb RrdDb reference to be returned to the pool
         * @  Thrown in case of I/O error
         */
        public void release(RrdDb rrdDb)
        {
            lock (sync)
            {
                // null pointer should not kill the thread, just ignore it
                if (rrdDb == null)
                {
                    return;
                }
                String canonicalPath = Util.getCanonicalPath(rrdDb.getPath());
                if (!rrdMap.ContainsKey(canonicalPath))
                {
                    throw new ApplicationException("Could not release [" + canonicalPath + "], the file was never requested");
                }
                RrdEntry entry = rrdMap[canonicalPath];
                if (--entry.count <= 0)
                {
                    // no longer used
                    rrdMap.Remove(canonicalPath);
                    entry.rrdDb.close();
                }
            }
        }
Esempio n. 3
0
 private void Add(string keypath, RrdDb rrdDb)
 {
     RrdEntry newEntry = new RrdEntry(rrdDb);
     Debug("NEW: " + newEntry.Dump());
     rrdMap.Add(keypath, newEntry);
     GC();
 }