com-sun-tools-visualvm-api-caching

16:33:40.350 INFO  jd.cli.Main - Decompiling com-sun-tools-visualvm-api-caching.jar
package com.sun.tools.visualvm.api.caching;

public abstract class Cache<K, V>
{
  public abstract V retrieveObject(K paramK);
  
  public abstract V invalidateObject(K paramK);
  
  public abstract long getTTL();
  
  public abstract void setTTL(long paramLong);
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.Cache
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching;

class CacheFactory$1 {}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.CacheFactory.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching;

final class CacheFactory$Singleton
{
  private static final CacheFactory INSTANCE = new CacheFactory(null);
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.CacheFactory.Singleton
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching;

import com.sun.tools.visualvm.api.caching.impl.CacheFactoryImpl;
import org.openide.util.Lookup;

public final class CacheFactory
{
  private final CacheFactoryImpl delegate;
  
  private static final class Singleton
  {
    private static final CacheFactory INSTANCE = new CacheFactory(null);
  }
  
  private CacheFactory()
  {
    delegate = ((CacheFactoryImpl)Lookup.getDefault().lookup(CacheFactoryImpl.class));
  }
  
  public static CacheFactory getInstance()
  {
    return Singleton.INSTANCE;
  }
  
  public <K, V> Cache<K, V> weakMapCache()
  {
    return delegate.weakMapCache();
  }
  
  public <K, V> Cache<K, V> weakMapCache(EntryFactory<K, V> resolver, Persistor<K, V> persistor)
  {
    return delegate.weakMapCache(resolver, persistor);
  }
  
  public <K, V> Cache<K, V> weakMapCache(Persistor<K, V> persistor)
  {
    return delegate.weakMapCache(persistor);
  }
  
  public <K, V> Cache<K, V> weakMapCache(EntryFactory<K, V> resolver)
  {
    return delegate.weakMapCache(resolver);
  }
  
  public <K, V> Cache<K, V> softMapCache()
  {
    return delegate.softMapCache();
  }
  
  public <K, V> Cache<K, V> softMapCache(EntryFactory<K, V> resolver, Persistor<K, V> persistor)
  {
    return delegate.softMapCache(resolver, persistor);
  }
  
  public <K, V> Cache<K, V> softMapCache(Persistor<K, V> persistor)
  {
    return delegate.softMapCache(persistor);
  }
  
  public <K, V> Cache<K, V> softMapCache(EntryFactory<K, V> resolver)
  {
    return delegate.softMapCache(resolver);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.CacheFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching;

public final class Entry<T>
{
  private long accessTs;
  private long updateTs;
  private T object;
  
  public Entry(T content)
  {
    this(content, System.currentTimeMillis());
  }
  
  public Entry(T content, long lastModified)
  {
    object = content;
    accessTs = lastModified;
    updateTs = accessTs;
  }
  
  public long getAccessTimeStamp()
  {
    return accessTs;
  }
  
  public T getContent()
  {
    return (T)object;
  }
  
  public long getUpdateTimeStamp()
  {
    return updateTs;
  }
  
  void setAccessTimeStamp(long ts)
  {
    accessTs = ts;
  }
  
  public boolean equals(Object obj)
  {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    Entry other = (Entry)obj;
    if (accessTs != accessTs) {
      return false;
    }
    if (updateTs != updateTs) {
      return false;
    }
    if ((object != object) && ((object == null) || (!object.equals(object)))) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    int hash = 5;
    hash = 61 * hash + (int)(accessTs ^ accessTs >>> 32);
    hash = 61 * hash + (int)(updateTs ^ updateTs >>> 32);
    hash = 61 * hash + (object != null ? object.hashCode() : 0);
    return hash;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.Entry
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching;

final class EntryFactory$1
  implements EntryFactory
{
  public Entry createEntry(Object key)
  {
    return new Entry(key);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.EntryFactory.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching;

public abstract interface EntryFactory<K, V>
{
  public static final EntryFactory DEFAULT = new EntryFactory()
  {
    public Entry createEntry(Object key)
    {
      return new Entry(key);
    }
  };
  
  public abstract Entry<V> createEntry(K paramK);
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.EntryFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching;

final class Persistor$1
  implements Persistor
{
  public Entry retrieve(Object key)
  {
    return null;
  }
  
  public void store(Object key, Entry value) {}
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.Persistor.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching;

public abstract interface Persistor<K, V>
{
  public static final Persistor DEFAULT = new Persistor()
  {
    public Entry retrieve(Object key)
    {
      return null;
    }
    
    public void store(Object key, Entry value) {}
  };
  
  public abstract Entry<V> retrieve(K paramK);
  
  public abstract void store(K paramK, Entry<V> paramEntry);
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.Persistor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching.impl;

import com.sun.tools.visualvm.api.caching.Cache;
import com.sun.tools.visualvm.api.caching.EntryFactory;
import com.sun.tools.visualvm.api.caching.Persistor;

public class CacheFactoryImpl
{
  public <K, V> Cache<K, V> weakMapCache()
  {
    return new CacheImpl(new WeakKeyFactory());
  }
  
  public <K, V> Cache<K, V> weakMapCache(EntryFactory<K, V> resolver, Persistor<K, V> persistor)
  {
    return new CacheImpl(resolver, new WeakKeyFactory(), persistor);
  }
  
  public <K, V> Cache<K, V> weakMapCache(Persistor<K, V> persistor)
  {
    return new CacheImpl(new WeakKeyFactory(), persistor);
  }
  
  public <K, V> Cache<K, V> weakMapCache(EntryFactory<K, V> resolver)
  {
    return new CacheImpl(resolver, new WeakKeyFactory());
  }
  
  public <K, V> Cache<K, V> softMapCache()
  {
    return new CacheImpl(new SoftKeyFactory());
  }
  
  public <K, V> Cache<K, V> softMapCache(EntryFactory<K, V> resolver, Persistor<K, V> persistor)
  {
    return new CacheImpl(resolver, new SoftKeyFactory(), persistor);
  }
  
  public <K, V> Cache<K, V> softMapCache(Persistor<K, V> persistor)
  {
    return new CacheImpl(new SoftKeyFactory(), persistor);
  }
  
  public <K, V> Cache<K, V> softMapCache(EntryFactory<K, V> resolver)
  {
    return new CacheImpl(resolver, new SoftKeyFactory());
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.impl.CacheFactoryImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching.impl;

import com.sun.tools.visualvm.api.caching.Cache;
import com.sun.tools.visualvm.api.caching.Entry;
import com.sun.tools.visualvm.api.caching.EntryFactory;
import com.sun.tools.visualvm.api.caching.Persistor;
import java.lang.ref.Reference;
import java.util.HashMap;
import java.util.Map;

final class CacheImpl<K, V>
  extends Cache<K, V>
{
  private final Map<Reference<K>, Entry<V>> objectCache = new HashMap();
  private long update_interval = 60480000L;
  private Persistor<K, V> persistor = Persistor.DEFAULT;
  private KeyFactory<K> keyFactory = KeyFactory.DEFAULT;
  private EntryFactory<K, V> resolver = EntryFactory.DEFAULT;
  
  CacheImpl() {}
  
  CacheImpl(EntryFactory<K, V> resolver)
  {
    this.resolver = resolver;
  }
  
  CacheImpl(Persistor<K, V> persistor)
  {
    this.persistor = persistor;
  }
  
  CacheImpl(KeyFactory<K> keyFactory)
  {
    this.keyFactory = keyFactory;
  }
  
  CacheImpl(EntryFactory<K, V> resolver, Persistor<K, V> persistor)
  {
    this.resolver = resolver;
    this.persistor = persistor;
  }
  
  CacheImpl(EntryFactory<K, V> resolver, KeyFactory<K> keyFactory)
  {
    this.resolver = resolver;
    this.keyFactory = keyFactory;
  }
  
  CacheImpl(KeyFactory<K> keyFactory, Persistor<K, V> persistor)
  {
    this.persistor = persistor;
    this.keyFactory = keyFactory;
  }
  
  CacheImpl(EntryFactory<K, V> resolver, KeyFactory<K> keyFactory, Persistor<K, V> persistor)
  {
    this.resolver = resolver;
    this.persistor = persistor;
    this.keyFactory = keyFactory;
  }
  
  public final V retrieveObject(K key)
  {
    Reference<K> softKey = keyFactory.createKey(key);
    synchronized (objectCache)
    {
      Entry<V> entry = (Entry)objectCache.get(softKey);
      if (entry == null) {
        entry = persistor.retrieve(key);
      }
      if (entry == null)
      {
        entry = cacheMiss(key);
        if ((entry != null) && (entry.getContent() != null))
        {
          persistor.store(key, entry);
          objectCache.put(softKey, entry);
        }
      }
      else
      {
        long timestamp = System.currentTimeMillis();
        if (timestamp - entry.getUpdateTimeStamp() > update_interval)
        {
          Entry<V> newEntry = cacheMiss(key);
          if ((newEntry != null) && (newEntry.getContent() != null))
          {
            persistor.store(key, entry);
            objectCache.put(softKey, newEntry);
            entry = newEntry;
          }
        }
      }
      return (V)(entry != null ? entry.getContent() : null);
    }
  }
  
  public final V invalidateObject(K key)
  {
    Reference<K> softKey = keyFactory.createKey(key);
    synchronized (objectCache)
    {
      Entry<V> entry = (Entry)objectCache.remove(softKey);
      return (V)(entry != null ? entry.getContent() : null);
    }
  }
  
  public final long getTTL()
  {
    return update_interval;
  }
  
  public final void setTTL(long ttl)
  {
    update_interval = ttl;
  }
  
  private Entry<V> cacheMiss(K key)
  {
    return resolver.createEntry(key);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.impl.CacheImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching.impl;

import java.lang.ref.Reference;

final class KeyFactory$1
  implements KeyFactory
{
  public Reference createKey(Object obj)
  {
    return new SoftReferenceEx(obj);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.impl.KeyFactory.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching.impl;

import java.lang.ref.Reference;

abstract interface KeyFactory<K>
{
  public static final KeyFactory DEFAULT = new KeyFactory()
  {
    public Reference createKey(Object obj)
    {
      return new SoftReferenceEx(obj);
    }
  };
  
  public abstract Reference<K> createKey(K paramK);
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.impl.KeyFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching.impl;

import java.lang.ref.Reference;

public class SoftKeyFactory<K>
  implements KeyFactory<K>
{
  public Reference<K> createKey(K obj)
  {
    return new SoftReferenceEx(obj);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.impl.SoftKeyFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching.impl;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;

class SoftReferenceEx<T>
  extends SoftReference<T>
{
  private int hashCode;
  
  public SoftReferenceEx(T referent, ReferenceQueue<? super T> q)
  {
    super(referent, q);
    hashCode = (referent != null ? referent.hashCode() : 0);
  }
  
  public SoftReferenceEx(T referent)
  {
    super(referent);
    hashCode = (referent != null ? referent.hashCode() : 0);
  }
  
  public boolean equals(Object obj)
  {
    if (!(obj instanceof SoftReferenceEx)) {
      return false;
    }
    SoftReferenceEx other = (SoftReferenceEx)obj;
    if ((get() == null) || (other.get() == null)) {
      return false;
    }
    return get().equals(other.get());
  }
  
  public int hashCode()
  {
    return hashCode;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.impl.SoftReferenceEx
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching.impl;

import java.lang.ref.Reference;

public class WeakKeyFactory<K>
  implements KeyFactory<K>
{
  public Reference<K> createKey(K obj)
  {
    return new WeakReferenceEx(obj);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.impl.WeakKeyFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching.impl;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

class WeakReferenceEx<T>
  extends WeakReference<T>
{
  private int hashCode;
  
  public WeakReferenceEx(T referent, ReferenceQueue<? super T> q)
  {
    super(referent, q);
    hashCode = (referent != null ? referent.hashCode() : 0);
  }
  
  public WeakReferenceEx(T referent)
  {
    super(referent);
    hashCode = (referent != null ? referent.hashCode() : 0);
  }
  
  public boolean equals(Object obj)
  {
    if (!(obj instanceof WeakReferenceEx)) {
      return false;
    }
    WeakReferenceEx other = (WeakReferenceEx)obj;
    if ((get() == null) || (other.get() == null)) {
      return false;
    }
    return get().equals(other.get());
  }
  
  public int hashCode()
  {
    return hashCode;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.impl.WeakReferenceEx
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching.impl;

interface package-info {}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.impl.package-info
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.api.caching;

interface package-info {}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.api.caching.package-info
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd