Example #1
0
        /// <summary>
        /// Removes the given key from the dictionary.
        /// </summary>
        public bool TryRemove(TKey key, out TValue value)
        {
            if (map.ContainsKey(key))
            {
                value = map.Remove(key);
                return(true);
            }

            value = default(TValue);
            return(false);
        }
Example #2
0
 /// <summary>
 /// Calls provided <seealso cref="Pruner"/> to prune entries.  The
 ///  entries are passed to the Pruner in sorted (newest to
 ///  oldest IndexSearcher) order.
 ///
 ///  <p><b>NOTE</b>: you must peridiocally call this, ideally
 ///  from the same background thread that opens new
 ///  searchers.
 /// </summary>
 public virtual void Prune(Pruner pruner)
 {
     lock (this)
     {
         // Cannot just pass searchers.values() to ArrayList ctor
         // (not thread-safe since the values can change while
         // ArrayList is init'ing itself); must instead iterate
         // ourselves:
         List <SearcherTracker> trackers = new List <SearcherTracker>();
         foreach (SearcherTracker tracker in Searchers.Values)
         {
             trackers.Add(tracker);
         }
         trackers.Sort();
         double lastRecordTimeSec = 0.0;
         double now = DateTime.Now.ToFileTime() / 100.0d / NANOS_PER_SEC;
         foreach (SearcherTracker tracker in trackers)
         {
             double ageSec;
             if (lastRecordTimeSec == 0.0)
             {
                 ageSec = 0.0;
             }
             else
             {
                 ageSec = now - lastRecordTimeSec;
             }
             // First tracker is always age 0.0 sec, since it's
             // still "live"; second tracker's age (= seconds since
             // it was "live") is now minus first tracker's
             // recordTime, etc:
             if (pruner.DoPrune(ageSec, tracker.Searcher))
             {
                 //System.out.println("PRUNE version=" + tracker.version + " age=" + ageSec + " ms=" + System.currentTimeMillis());
                 Searchers.Remove(tracker.Version);
                 tracker.Dispose();
             }
             lastRecordTimeSec = tracker.RecordTimeSec;
         }
     }
 }
Example #3
0
        /// <summary>
        /// Removes a module from this channel.
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        public ISockNetChannel RemoveModule(ISockNetChannelModule module)
        {
            if (modules.Remove(module.GetType().Name))
            {
                SockNetLogger.Log(SockNetLogger.LogLevel.DEBUG, this, "Uninstalling module: [{0}]", module);

                module.Uninstall(this);
            }
            else
            {
                throw new Exception("Module [" + module + "] not installed.");
            }

            return(this);
        }
Example #4
0
File: XMap.cs Project: slagusev/api
        /// <summary>
        /// Try to get an entry from the map.
        /// </summary>
        internal T TryGet(string key)
        {
            var entry = map.Get(key);

            if (entry == null)
            {
                return(default(T));
            }
            var result = entry.Get();

            if (result == null)
            {
                map.Remove(key, entry);
                return(null);
            }
            return(result);
        }
Example #5
0
 /// <summary>
 /// Notifies this server of a disconnected channel.
 /// </summary>
 /// <param name="channel"></param>
 internal void RemoteChannelDisconnected(RemoteSockNetChannel channel)
 {
     remoteChannels.Remove(channel.Id);
 }
        public void TestSetValueWriteThrough()
        {
            ConcurrentHashMap<Object, Object> map = new ConcurrentHashMap<Object, Object>(2, 5.0f, 1);
            Assert.IsTrue(map.IsEmpty());
            for (int i = 0; i < 20; i++)
            {
                map.Put(i, i);
            }
            Assert.IsFalse(map.IsEmpty());
            Entry<Object, Object> entry1 = map.EntrySet().Iterator().Next();

            // assert that entry1 is not 16
            Assert.IsTrue(!entry1.Key.Equals(16), "entry is 16, test not valid");

            // remove 16 (a different key) from map
            // which just happens to cause entry1 to be cloned in map
            map.Remove(16);

            entry1.Value = "XYZ";

            Assert.IsTrue(map.ContainsValue("XYZ"));
        }
 public void TestRemove3()
 {
     try
     {
         ConcurrentHashMap<Object, Object> c = new ConcurrentHashMap<Object, Object>(5);
         c.Put("sadsdf", "asdads");
         Assert.IsFalse(c.Remove("sadsdf", null));
     }
     catch(NullReferenceException)
     {
         Assert.Fail();
     }
 }
 public void TestRemove2_NullReferenceException()
 {
     try
     {
         ConcurrentHashMap<Object, Object> c = new ConcurrentHashMap<Object, Object>(5);
         c.Put("sadsdf", "asdads");
         c.Remove(null, "whatever");
         ShouldThrow();
     }
     catch(NullReferenceException)
     {
     }
 }
Example #9
0
 /// <summary>
 /// Removes an attribute.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="value"></param>
 /// <param name="upsert"></param>
 /// <returns></returns>
 public bool RemoveAttribute(string name)
 {
     return(attributes.Remove(name));
 }