Exemplo n.º 1
0
 private void  InitBlock(CacheTable enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
Exemplo n.º 2
0
            public virtual void  Run()
            {
                List <Integer> toRemove = new List <Integer>();

                while (true)
                {
                    try
                    {
                        toRemove.removeAllElements();
                        for (int i = 0; i < caches.size(); ++i)
                        {
                            CacheTable cache = (CacheTable)caches.elementAt(i).get_Renamed();
                            if (cache == null)
                            {
                                toRemove.addElement(DataUtil.integer(i));
                            }
                            else
                            {
                                Hashtable <Integer, WeakReference> table = cache.currentTable;
                                //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
                                for (System.Collections.IEnumerator en = table.keys(); en.MoveNext();)
                                {
                                    //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
                                    System.Object key = en.Current;

                                    lock (cache)
                                    {
                                        //See whether or not the cached reference has been cleared by the GC
                                        //UPGRADE_ISSUE: Method 'java.lang.ref.Reference.get' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangrefReference'"
                                        if (((System.WeakReference)table.get_Renamed(key)).get_Renamed() == null)
                                        {
                                            //If so, remove the entry, it's no longer useful.
                                            table.remove(key);
                                        }
                                    }
                                }

                                lock (cache)
                                {
                                    //See if our current size is 25% the size of the largest size we've been
                                    //and compact (clone to a new table) if so, since the table maintains the
                                    //largest size it has ever been.
                                    //TODO: 50 is a super arbitrary upper bound
                                    if (cache.totalAdditions > 50 && cache.totalAdditions - cache.currentTable.size() > (cache.currentTable.size() >> 2))
                                    {
                                        System.Collections.Hashtable newTable = new Hashtable(cache.currentTable.size());
                                        int oldMax = cache.totalAdditions;
                                        //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
                                        for (System.Collections.IEnumerator en = table.keys(); en.MoveNext();)
                                        {
                                            //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
                                            System.Object key = en.Current;
                                            newTable[key] = cache.currentTable.get_Renamed(key);
                                        }
                                        cache.currentTable   = newTable;
                                        cache.totalAdditions = cache.currentTable.size();
                                    }
                                }
                            }
                        }
                        for (int id = toRemove.size() - 1; id >= 0; --id)
                        {
                            caches.removeElementAt(toRemove.elementAt(id));
                        }
                        try
                        {
                            //UPGRADE_TODO: Method 'java.lang.Thread.sleep' was converted to 'System.Threading.Thread.Sleep' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangThreadsleep_long'"
                            System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 3000));
                        }
                        catch (System.Threading.ThreadInterruptedException e)
                        {
                            // TODO Auto-generated catch block
                            SupportClass.WriteStackTrace(e, Console.Error);
                        }
                    }
                    catch (System.Exception e)
                    {
                        if (e is org.javarosa.core.io.StreamsUtil.DirectionalIOException)
                        {
                            ((org.javarosa.core.io.StreamsUtil.DirectionalIOException)e).printStackTrace();
                        }
                        else
                        {
                            SupportClass.WriteStackTrace(e, Console.Error);
                        }
                    }
                }
            }
Exemplo n.º 3
0
 public AnonymousClassRunnable(CacheTable enclosingInstance)
 {
     InitBlock(enclosingInstance);
 }