/** * Create a lease time collection with java util timer. */ public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, ICommand<E> removecmd) { return new SynchronizedLeaseTimeCollection<E>(new LeaseTimeSet(leasetime, removecmd)); }
/** * Put an entry in the cache. * @param key The key. * @param value The value. * @param now The current time (-1 for never expire). */ public void put(Object key, Object value, long now, long ttl) { CacheEntry ce = new CacheEntry(value, now, ttl); lru.put(key, ce); }
/** * Create a new cache. */ public Cache(int max, long ttl) { this(new LRU(max), ttl); }
/** * Return a fresh index map. */ public static IndexMap createIndexMap() { IndexMap ret = new IndexMap(); if(DEBUG) addCollection(ret); return ret; }
/** * Remove a special object from the * collection of a defined key. */ public void removeObject(Object key, Object value) { reverse._remove(value, key); super.removeObject(key, value); }
/** * Remove the eldest entry. * @param eldest The eldest entry. * @return True if need to be removed. */ public boolean removeEldestEntry(Map.Entry<K, V> eldest) { // if(size() > max) // System.out.println("removing: "+eldest); if(cleaner!=null && size() > max) cleaner.cleanupEldestEntry(eldest); return size() > max; } }
/** * Remove an entry. * @param key The key. */ public boolean remove(Object key) { return lru.remove(key)!=null; }
/** * Get the size. * @return The size. */ public int size() { return lru.size(); } }
/** * Dequeue an element. * @return The element. When queue is empty * the methods blocks until an element is added. */ public T dequeue() throws ClosedException { return dequeue(-1); }
/** * Test if a key is contained. * @param key The key. * @return True if contained. */ public boolean containsKey(Object key) { return lru.containsKey(key); }
/** * Update the timestamp of e. * @param entry The entry. */ public void touch(E e) { touch(e, getLeaseTime()); }
/** * Create a new lease time handling object. */ protected LeaseTimeSet(long leasetime, ICommand<E> removecmd, IDelayRunner timer) { this.leasetime = leasetime; this.removecmd = removecmd; this.timer = timer!=null? timer: new TimerDelayRunner(); }
/** * Set the remove cmd. */ public void setRemoveCommand(ICommand<E> cmd) { synchronized (mutex) {c.setRemoveCommand(cmd);} }
/** * Get the values as array. * @return The array of values. */ public Object[] getObjects() { return getObjects(Object.class); }
/** * Create a lease time collection with java util timer. */ public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, ICommand<E> removecmd, Object mutex) { return new SynchronizedLeaseTimeCollection<E>(new LeaseTimeSet(leasetime, removecmd), mutex); }
/** * Create a lease time collection with java util timer. */ public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime) { return new SynchronizedLeaseTimeCollection<E>(new LeaseTimeSet(leasetime)); }
/** * Create a lease time collection with java util timer. */ public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, ICommand<E> removecmd, IDelayRunner timer, boolean sync, Object mutex) { return sync? new SynchronizedLeaseTimeCollection<E>(new LeaseTimeSet(leasetime, removecmd, timer), mutex): new LeaseTimeSet(leasetime, removecmd, timer); }