// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 10/2/2001 11:03:21
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/protocol/fgjdbc/FgjdbcCache

package com.macromedia.generator.protocol.fgjdbc;

import java.util.Enumeration;
import java.util.Hashtable;

// Referenced classes of package com.macromedia.generator.protocol.fgjdbc:
//            FgjdbcCacheEntry

public class FgjdbcCache
    implements Runnable
{

    protected FgjdbcCache()
    {
        _fld0180 = 0;
        _fld0181 = null;
        _fld0182 = null;
        _fld0181 = new Hashtable();
        _fld0182 = new Thread(this, "FgjdbcCache");
        _fld0182.setDaemon(true);
        _fld0182.start();
    }

    private synchronized void _mth017E()
    {
        long l = System.currentTimeMillis();
        for(Enumeration enumeration = _fld0181.elements(); enumeration.hasMoreElements();)
        {
            FgjdbcCacheEntry fgjdbccacheentry = (FgjdbcCacheEntry)enumeration.nextElement();
            if(fgjdbccacheentry.expires < l)
            {
                _fld0181.remove(fgjdbccacheentry.key);
                _fld0180 -= fgjdbccacheentry.length;
            }
        }

    }

    protected void finalize()
        throws Throwable
    {
    }

    public static FgjdbcCache getCache()
    {
        return _fld017F;
    }

    public synchronized String getCacheValue(String s, String s1, String s2, String s3, String s4)
    {
        String s5 = s + "|" + s1 + "|" + s2 + "|" + s3 + "|" + s4;
        FgjdbcCacheEntry fgjdbccacheentry = (FgjdbcCacheEntry)_fld0181.get(s5);
        return fgjdbccacheentry == null ? null : fgjdbccacheentry.value;
    }

    public void run()
    {
        while(_fld0182 != null) 
            try
            {
                Thread.sleep(1000L);
                _mth017E();
            }
            catch(InterruptedException _ex) { }
    }

    public synchronized void setCacheValue(String s, String s1, String s2, String s3, String s4, String s5, int i)
    {
        String s6 = s + "|" + s1 + "|" + s2 + "|" + s3 + "|" + s4;
        int j = s5.length();
        if(_fld0180 + j < _fld017E && getCacheValue(s, s1, s2, s3, s4) == null)
        {
            FgjdbcCacheEntry fgjdbccacheentry = new FgjdbcCacheEntry();
            fgjdbccacheentry.key = s6;
            fgjdbccacheentry.value = s5;
            fgjdbccacheentry.length = j;
            fgjdbccacheentry.expires = System.currentTimeMillis() + (long)i * 1000L;
            _fld0181.put(fgjdbccacheentry.key, fgjdbccacheentry);
            _fld0180 += j;
        }
    }

    private static int _fld017E = 0xf4240;
    private static FgjdbcCache _fld017F;
    private int _fld0180;
    private Hashtable _fld0181;
    private Thread _fld0182;

    static 
    {
        _fld017F = null;
        if(_fld017F == null)
            _fld017F = new FgjdbcCache();
    }
}