Commits

Anonymous committed f414e1e

Submitter: Andres March

added some missing API methods

Comments (0)

Files changed (11)

src/core/java/com/opensymphony/oscache/core/AbstractCacheAdministrator.java

 		}
 	}
 
-	public Object get(String regionName, Object key) {
-		return getCache(regionName).get(key);
-	}
-
 	private Cache getCache(String regionName) {
 		
 		return (Cache) regions.get(regionName);
 	}
 
-	public Object get(String regionName, Object key, int refreshPeriod) {
-		return getCache(regionName).get(key, refreshPeriod);
-	}
-
-	public Object get(String regionName, Object key, int refreshPeriod,
-			String cronExpiry) {
-
-		Object value = getCache(regionName).get(key, refreshPeriod, cronExpiry);
-
-		return value;
-	}
-
-	protected void put(String regionName, Object key, Object value) {
-		getCache(regionName).put(key, value);
-
-	}
 
 	/**
 	 * Sets the algorithm to use for the cache.

src/core/java/com/opensymphony/oscache/core/BaseCache.java

 import java.util.Properties;
 import java.util.Set;
 
+import com.opensymphony.oscache.core.EntryRefreshPolicy;
+import com.opensymphony.oscache.core.CacheEntry;
 import com.opensymphony.oscache.events.CacheEntryEvent;
 import com.opensymphony.oscache.events.CacheEvent;
 import com.opensymphony.oscache.events.CacheGroupEvent;
 	 *         be found and could not be loaded.
 	 */
 	public synchronized Object get(Object key) {
-		return get(key, 0);
+		return get(key, CacheEntry.INDEFINITE_EXPIRY);
 	}
 
 	/**
 	 *         be found and could not be loaded.
 	 */
 	public synchronized Object get(Object key, int refreshPeriod) {
-		return get(key, 0, null);
+		return get(key, refreshPeriod, null);
 	}
-	
+
 	/**
 	 * Retrieves an object from the cache.
 	 * 
 	}
 
 	/**
+	 * Put an object in the cache specifying the key to use.
+	 * 
+	 * @param key
+	 *            Key of the object in the cache.
+	 * @param content
+	 *            The object to cache.
+	 */
+	public synchronized Object put(Object key, Object content) {
+		return put(key, content, null, null);
+	}
+
+	/**
+	 * Put an object in the cache specifying the key and refresh policy to use.
+	 * 
+	 * @param key
+	 *            Key of the object in the cache.
+	 * @param content
+	 *            The object to cache.
+	 * @param policy
+	 *            Object that implements refresh policy logic
+	 */
+	public synchronized Object put(Object key, Object content,
+			EntryRefreshPolicy policy) {
+		return put(key, content, null, policy);
+	}
+
+	/**
+	 * Put in object into the cache, specifying both the key to use and the
+	 * cache groups the object belongs to.
+	 * 
+	 * @param key
+	 *            Key of the object in the cache
+	 * @param content
+	 *            The object to cache
+	 * @param groups
+	 *            The cache groups to add the object to
+	 */
+	public synchronized Object put(Object key, Object content, String[] groups) {
+		return put(key, content, groups, null);
+	}
+
+	/**
 	 * Store the supplied entry in the cache.
 	 * 
 	 * @param key
 	 *            the object to store.
 	 * @return the previous object that was stored under this key, if any.
 	 */
-	public synchronized Object put(Object key, Object value) {
-		CacheEntry newEntry = new CacheEntry(key, value);
+	public synchronized Object put(Object key, Object value, String[] groups,
+			EntryRefreshPolicy policy) {
+		CacheEntry newEntry = new CacheEntry(key, value, groups, policy);
 		CacheEntry oldEntry = putInternal(newEntry);
 		algorithm.put(key, newEntry);
 
-		// Remove an entry from the cache if the eviction algorithm says we need to
+		// Remove an entry from the cache if the eviction algorithm says we need
+		// to
 		Object evictionKey = algorithm.evict();
 		if (evictionKey != null) {
 			remove(evictionKey);
-		}		
+		}
 
 		addGroupMappings(newEntry);
 
 		return oldEntry.getValue();
 	}
 
-
 	/**
 	 * Get an entry from this cache.
 	 * 
 			return false;
 		}
 	}
-	
+
 	/**
-     * Flushes all unexpired objects that belong to the supplied group. On
-     * completion this method fires a <tt>CacheEntryEvent.GROUP_FLUSHED</tt>
-     * event.
-     *
-     * @param group The group to flush
-     */
-    public void removeGroup(String group) {
-        // Flush all objects in the group
-        Set groupEntries = (Set) groupMap.get(group);
+	 * Flushes all unexpired objects that belong to the supplied group. On
+	 * completion this method fires a <tt>CacheEntryEvent.GROUP_FLUSHED</tt>
+	 * event.
+	 * 
+	 * @param group
+	 *            The group to flush
+	 */
+	public void removeGroup(String group) {
+		// Flush all objects in the group
+		Set groupEntries = (Set) groupMap.get(group);
 
-        if (groupEntries != null) {
-            Iterator itr = groupEntries.iterator();
-            Object key;
-            CacheEntry entry;
+		if (groupEntries != null) {
+			Iterator itr = groupEntries.iterator();
+			Object key;
+			CacheEntry entry;
 
-            while (itr.hasNext()) {
-            		key = itr.next();
-                entry = getEntry(key);
+			while (itr.hasNext()) {
+				key = itr.next();
+				entry = getEntry(key);
 
-                if ((entry != null) && !entry.needsRefresh(CacheEntry.INDEFINITE_EXPIRY)) {
-                    remove(key);
-                }
-            }
-        }
-        fireEvent(new CacheGroupEvent(this, group));
-        
-    }
+				if ((entry != null)
+						&& !entry.needsRefresh(CacheEntry.INDEFINITE_EXPIRY)) {
+					remove(key);
+				}
+			}
+		}
+		fireEvent(new CacheGroupEvent(this, group));
+
+	}
 
 	/**
 	 * Indicates whether or not the cache entry is stale.
 	protected abstract void clearInternal();
 
 	public void flushAll(Date date) {
-		flushDateTime = date;
-		fireEvent(new CachewideEvent(this, date));
+		synchronized (flushDateTime) {
+			flushDateTime = date;
+			fireEvent(new CachewideEvent(this, date));
+		}
 	}
 
 	/**
-	 * Add this entry's key to the groups specified by the entry's groups. 
+	 * Add this entry's key to the groups specified by the entry's groups.
 	 * 
 	 */
 	protected void addGroupMappings(CacheEntry entry) {
 		// Add this CacheEntry to the groups that it is now a member of
 		for (Iterator it = entry.getGroups().iterator(); it.hasNext();) {
 			String groupName = (String) it.next();
-	
+
 			if (groupMap == null) {
 				groupMap = new HashMap();
 			}
-	
+
 			Set group = (Set) groupMap.get(groupName);
-	
+
 			if (group == null) {
 				group = new HashSet();
 				groupMap.put(groupName, group);
 			}
-	
+
 			group.add(entry.getKey());
 		}
 	}

src/core/java/com/opensymphony/oscache/core/CacheEntry.java

 import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
 /**
- * A CacheEntry instance represents one entry in the cache. It holds the object that
- * is being cached, along with a host of information about that entry such as the
- * cache key, the time it was cached, whether the entry has been flushed or not and
- * the groups it belongs to.
- *
- * @author        <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
- * @author        <a href="mailto:tgochenour@peregrine.com">Todd Gochenour</a>
+ * A CacheEntry instance represents one entry in the cache. It holds the object
+ * that is being cached, along with a host of information about that entry such
+ * as the cache key, the time it was cached, whether the entry has been flushed
+ * or not and the groups it belongs to.
+ * 
+ * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
+ * @author <a href="mailto:tgochenour@peregrine.com">Todd Gochenour</a>
  * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
  * @author <a href="mailto:oscache@andresmarch.com">Andres March</a>
  */
 public class CacheEntry implements Map.Entry, Serializable {
-    /**
+	/**
 	 * 
 	 */
 	private static final long serialVersionUID = -3776911995865680219L;
 
 	/**
- * Default initialization value for the creation time and the last
- * update time. This is a placeholder that indicates the value has
- * not been set yet.
- */
-    private static final byte NOT_YET = -1;
+	 * Default initialization value for the creation time and the last update
+	 * time. This is a placeholder that indicates the value has not been set
+	 * yet.
+	 */
+	private static final byte NOT_YET = -1;
 
-    /**
- * Specifying this as the refresh period for the
- * {@link #needsRefresh(int)} method will ensure
- * an entry does not become stale until it is
- * either explicitly flushed or a custom refresh
- * policy causes the entry to expire.
- */
-    public static final int INDEFINITE_EXPIRY = -1;
+	/**
+	 * Specifying this as the refresh period for the {@link #needsRefresh(int)}
+	 * method will ensure an entry does not become stale until it is either
+	 * explicitly flushed or a custom refresh policy causes the entry to expire.
+	 */
+	public static final int INDEFINITE_EXPIRY = -1;
 
+	/**
+	 * The entry refresh policy object to use for this cache entry. This is
+	 * optional.
+	 */
+	private EntryRefreshPolicy policy = null;
+
+	private int state;
+
+	public static final int STATE_VALID = 0;
+
+	public static final int STATE_UPDATING = 1;
+
+	/**
+	 * The actual content that is being cached. Wherever possible this object
+	 * should be serializable. This allows <code>PersistenceListener</code>s
+	 * to serialize the cache entries to disk or database.
+	 */
+	private Object content = null;
+
+	/**
+	 * The unique cache key for this entry
+	 */
+	private Object key;
+
+	/**
+	 * <code>true</code> if this entry was flushed
+	 */
+	private boolean wasFlushed = false;
+
+	/**
+	 * The time this entry was created.
+	 */
+	private long created = NOT_YET;
+
+	/**
+	 * The time this emtry was last updated.
+	 */
+	private long lastUpdate = NOT_YET;
+
+	/**
+	 * The set of cache groups that this cache entry belongs to, if any.
+	 */
+	private Set groups = null;
+
+	/**
+	 * Construct a new CacheEntry using the key provided.
+	 * 
+	 * @param key
+	 *            The key of this CacheEntry
+	 */
+	public CacheEntry(Object key, Object value) {
+		this(key, value, null, null);
+	}
+
+	/**
+	 * Construct a CacheEntry.
+	 * 
+	 * @param key
+	 *            The unique key for this <code>CacheEntry</code>.
+	 * @param policy
+	 *            The object that implements the refresh policy logic. This
+	 *            parameter is optional.
+	 */
+	public CacheEntry(Object key, Object value, EntryRefreshPolicy policy) {
+		this(key, value, null, policy);
+	}
+	/**
+	 * Construct a CacheEntry.
+	 * 
+	 * @param key
+	 *            The unique key for this <code>CacheEntry</code>.
+	 * @param policy
+	 *            The object that implements the refresh policy logic. This
+	 *            parameter is optional.
+	 */
+	public CacheEntry(Object key, Object value,  String[] groups) {
+		this(key, value, groups, null);
+	}
 	
 
-    /**
- * The entry refresh policy object to use for this cache entry. This is optional.
- */
-    private EntryRefreshPolicy policy = null;
-    
-    
-    
-    private int state;
-    
-    public static final int STATE_VALID = 0;
-    public static final int STATE_UPDATING = 1;
-
-    /**
- * The actual content that is being cached. Wherever possible this object
- * should be serializable. This allows <code>PersistenceListener</code>s
- * to serialize the cache entries to disk or database.
- */
-    private Object content = null;
-
-
-    /**
- *  The unique cache key for this entry
- */
-    private Object key;
-
-    /**
- * <code>true</code> if this entry was flushed
- */
-    private boolean wasFlushed = false;
-
-    /**
- * The time this entry was created.
- */
-    private long created = NOT_YET;
-
-    /**
- * The time this emtry was last updated.
- */
-    private long lastUpdate = NOT_YET;
-    
-    /**
-     * The set of cache groups that this cache entry belongs to, if any.
-     */
-    private Set groups = null;
-
-    
-
-    /**
-     * Construct a new CacheEntry using the key provided.
-     *
-     * @param key    The key of this CacheEntry
-     */
-    public CacheEntry(Object key, Object value) {
-		this(key, null, value);		
-}
-    
-    /**
- * Construct a CacheEntry.
- *
- * @param key     The unique key for this <code>CacheEntry</code>.
- * @param policy  The object that implements the refresh policy logic. This
- * parameter is optional.
- */
-    public CacheEntry(Object key, EntryRefreshPolicy policy, Object value) {
-        this.key = key;
-
-        this.policy = policy;
-        this.created = System.currentTimeMillis();
-        this.state = STATE_VALID;
-        setValue(value);
-    }
-
-    
-
+	public CacheEntry(Object key, Object value, String[] groups,
+			EntryRefreshPolicy policy) {
+		this.key = key;
+		this.groups = new HashSet(Arrays.asList(groups));
+		this.policy = policy;
+		this.created = System.currentTimeMillis();
+		this.state = STATE_VALID;
+		setValue(value);
+	}
 
 	/**
- * Sets the actual content that is being cached. Wherever possible this
- * object should be <code>Serializable</code>, however it is not an
- * absolute requirement when using a memory-only cache. Being <code>Serializable</code>
- * allows <code>PersistenceListener</code>s to serialize the cache entries to disk
- * or database.
- *
- * @param value The content to store in this CacheEntry.
- */
-    public Object setValue(Object value) {
-        content = value;
-        lastUpdate = System.currentTimeMillis();
-        wasFlushed = false;
+	 * Sets the actual content that is being cached. Wherever possible this
+	 * object should be <code>Serializable</code>, however it is not an
+	 * absolute requirement when using a memory-only cache. Being
+	 * <code>Serializable</code> allows <code>PersistenceListener</code>s
+	 * to serialize the cache entries to disk or database.
+	 * 
+	 * @param value
+	 *            The content to store in this CacheEntry.
+	 */
+	public Object setValue(Object value) {
+		content = value;
+		lastUpdate = System.currentTimeMillis();
+		wasFlushed = false;
 		return value;
-    }
+	}
 
-    /**
- * Get the cached content from this CacheEntry.
- *
- * @return The content of this CacheEntry.
- */
-    public Object getValue() {
-        return content;
-    }
+	/**
+	 * Get the cached content from this CacheEntry.
+	 * 
+	 * @return The content of this CacheEntry.
+	 */
+	public Object getValue() {
+		return content;
+	}
 
-    /**
- * Get the date this CacheEntry was created.
- *
- * @return The date this CacheEntry was created.
- */
-    public long getCreated() {
-        return created;
-    }
+	/**
+	 * Get the date this CacheEntry was created.
+	 * 
+	 * @return The date this CacheEntry was created.
+	 */
+	public long getCreated() {
+		return created;
+	}
 
+	/**
+	 * Get the key of this CacheEntry
+	 * 
+	 * @return The key of this CacheEntry
+	 */
+	public Object getKey() {
+		return key;
+	}
 
-    /**
- * Get the key of this CacheEntry
- *
- * @return The key of this CacheEntry
- */
-    public Object getKey() {
-        return key;
-    }
+	/**
+	 * Set the date this CacheEntry was last updated.
+	 * 
+	 * @param update
+	 *            The time (in milliseconds) this CacheEntry was last updated.
+	 */
+	public void setLastUpdate(long update) {
+		lastUpdate = update;
+	}
 
-    /**
- * Set the date this CacheEntry was last updated.
- *
- * @param update The time (in milliseconds) this CacheEntry was last updated.
- */
-    public void setLastUpdate(long update) {
-        lastUpdate = update;
-    }
+	/**
+	 * Get the date this CacheEntry was last updated.
+	 * 
+	 * @return The date this CacheEntry was last updated.
+	 */
+	public long getLastUpdate() {
+		return lastUpdate;
+	}
 
-    /**
- * Get the date this CacheEntry was last updated.
- *
- * @return The date this CacheEntry was last updated.
- */
-    public long getLastUpdate() {
-        return lastUpdate;
-    }
+	/**
+	 * Indicates whether this CacheEntry is a freshly created one and has not
+	 * yet been assigned content or placed in a cache.
+	 * 
+	 * @return <code>true</code> if this entry is newly created
+	 */
+	public boolean isNew() {
+		return lastUpdate == NOT_YET;
+	}
 
-    /**
- * Indicates whether this CacheEntry is a freshly created one and
- * has not yet been assigned content or placed in a cache.
- *
- * @return <code>true</code> if this entry is newly created
- */
-    public boolean isNew() {
-        return lastUpdate == NOT_YET;
-    }
-
-    /**
- * Get the size of the cache entry in bytes (roughly).<p>
- *
- *
- * @return The approximate size of the entry in bytes, or -1 if the
- * size could not be estimated.
- */
-    public int getSize() {
-    		ByteArrayOutputStream bout = new ByteArrayOutputStream();
-        ObjectOutputStream out;
+	/**
+	 * Get the size of the cache entry in bytes (roughly).
+	 * <p>
+	 * 
+	 * 
+	 * @return The approximate size of the entry in bytes, or -1 if the size
+	 *         could not be estimated.
+	 */
+	public int getSize() {
+		ByteArrayOutputStream bout = new ByteArrayOutputStream();
+		ObjectOutputStream out;
 		try {
 			out = new ObjectOutputStream(bout);
-			out.writeObject(this);			
+			out.writeObject(this);
 		} catch (IOException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
 		byte[] bytes = bout.toByteArray();
 		return bytes.length;
-        
-    }
 
-    /**
- * Flush the entry from cache.
- * note that flushing the cache doesn't actually remove the cache contents
- * it just tells the CacheEntry that it needs a refresh next time it is asked
- * this is so that the content is still there for a <usecached />.
- */
-    public void flush() {
-        wasFlushed = true;
-    }
+	}
 
-    /**
- * Check if this CacheEntry needs to be refreshed.
- *
- * @param refreshPeriod The period of refresh (in seconds). Passing in
- * {@link #INDEFINITE_EXPIRY} will result in the content never becoming
- * stale unless it is explicitly flushed, or expired by a custom
- * {@link EntryRefreshPolicy}. Passing in 0 will always result in a
- * refresh being required.
- *
- * @return Whether or not this CacheEntry needs refreshing.
- */
-    public boolean needsRefresh(int refreshPeriod) {
-        boolean needsRefresh;
+	/**
+	 * Flush the entry from cache. note that flushing the cache doesn't actually
+	 * remove the cache contents it just tells the CacheEntry that it needs a
+	 * refresh next time it is asked this is so that the content is still there
+	 * for a <usecached />.
+	 */
+	public void flush() {
+		wasFlushed = true;
+	}
 
-        // needs a refresh if it has never been updated
-        if (lastUpdate == NOT_YET) {
-            needsRefresh = true;
-        }
-        // Was it flushed from cache?
-        else if (wasFlushed) {
-            needsRefresh = true;
-        } else if (refreshPeriod == 0) {
-            needsRefresh = true;
-        }
-        // check what the policy has to say if there is one
-        else if (policy != null) {
-            needsRefresh = policy.needsRefresh(this);
-        }
-        // check if the last update + update period is in the past
-        else if ((refreshPeriod >= 0) && (System.currentTimeMillis() >= (lastUpdate + (refreshPeriod * 1000L)))) {
-            needsRefresh = true;
-        } else {
-            needsRefresh = false;
-        }
+	/**
+	 * Check if this CacheEntry needs to be refreshed.
+	 * 
+	 * @param refreshPeriod
+	 *            The period of refresh (in seconds). Passing in
+	 *            {@link #INDEFINITE_EXPIRY} will result in the content never
+	 *            becoming stale unless it is explicitly flushed, or expired by
+	 *            a custom {@link EntryRefreshPolicy}. Passing in 0 will always
+	 *            result in a refresh being required.
+	 * 
+	 * @return Whether or not this CacheEntry needs refreshing.
+	 */
+	public boolean needsRefresh(int refreshPeriod) {
+		boolean needsRefresh;
 
-        return needsRefresh;
-    }
+		// needs a refresh if it has never been updated
+		if (lastUpdate == NOT_YET) {
+			needsRefresh = true;
+		}
+		// Was it flushed from cache?
+		else if (wasFlushed) {
+			needsRefresh = true;
+		} else if (refreshPeriod == 0) {
+			needsRefresh = true;
+		}
+		// check what the policy has to say if there is one
+		else if (policy != null) {
+			needsRefresh = policy.needsRefresh(this);
+		}
+		// check if the last update + update period is in the past
+		else if ((refreshPeriod >= 0)
+				&& (System.currentTimeMillis() >= (lastUpdate + (refreshPeriod * 1000L)))) {
+			needsRefresh = true;
+		} else {
+			needsRefresh = false;
+		}
 
-    public int getState() {
-        return state;
-    }
+		return needsRefresh;
+	}
 
+	public int getState() {
+		return state;
+	}
 
 	public boolean isUpdating() {
 		return state == STATE_UPDATING;
 	}
 
+	public void startUpdate() {
 
-	public void startUpdate() {
-		
 		state = STATE_UPDATING;
 	}
-	
+
 	/**
-     * Updates the state to <code>UPDATE_CANCELLED</code>. This should <em>only<em>
-     * be called by the thread that managed to get the update lock.
-     */
-    public void cancelUpdate() {
-        if (state != STATE_UPDATING) {
-            throw new IllegalStateException("Cannot cancel cache update - current state (" + state + ") is not UPDATE_IN_PROGRESS");
-        }
+	 * Updates the state to <code>UPDATE_CANCELLED</code>. This should
+	 * <em>only<em>
+	 * be called by the thread that managed to get the update lock.
+	 */
+	public void cancelUpdate() {
+		if (state != STATE_UPDATING) {
+			throw new IllegalStateException(
+					"Cannot cancel cache update - current state (" + state
+							+ ") is not UPDATE_IN_PROGRESS");
+		}
 
-        state = STATE_VALID;
-    }
-    
-    /**
-     * Updates the state to <code>UPDATE_COMPLETE</code>. This should <em>only</em>
-     * be called by the thread that managed to get the update lock.
-     */
-    public void completeUpdate() {
-        if (state != STATE_UPDATING) {
-            throw new IllegalStateException("Cannot complete cache update - current state (" + state + ") is not UPDATE_IN_PROGRESS");
-        }
+		state = STATE_VALID;
+	}
 
-        state = STATE_VALID;
-    }
+	/**
+	 * Updates the state to <code>UPDATE_COMPLETE</code>. This should
+	 * <em>only</em> be called by the thread that managed to get the update
+	 * lock.
+	 */
+	public void completeUpdate() {
+		if (state != STATE_UPDATING) {
+			throw new IllegalStateException(
+					"Cannot complete cache update - current state (" + state
+							+ ") is not UPDATE_IN_PROGRESS");
+		}
+
+		state = STATE_VALID;
+	}
 
 	/**
 	 * @return Returns the content.
 	}
 
 	/**
-	 * @param content The content to set.
+	 * @param content
+	 *            The content to set.
 	 */
 	public void setContent(Object content) {
 		this.content = content;
 	 * @return Returns the groups.
 	 */
 	public Set getGroups() {
-		if (groups == null) groups = new HashSet();
+		if (groups == null)
+			groups = new HashSet();
 		return groups;
 	}
 
 	/**
-	 * @param groups The groups to set.
+	 * @param groups
+	 *            The groups to set.
 	 */
 	public void setGroups(Set groups) {
 		this.groups = groups;
 	}
 
 	/**
-	 * @param policy The policy to set.
+	 * @param policy
+	 *            The policy to set.
 	 */
 	public void setPolicy(EntryRefreshPolicy policy) {
 		this.policy = policy;

src/core/java/com/opensymphony/oscache/events/CacheEntryEvent.java

  * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
  */
 public class CacheEntryEvent extends CacheEvent {
+	
+	/**
+     * Get an event type for an entry added.
+     */
+    public static int ENTRY_ADDED = 0;
+
     /**
-     * The cache where the entry resides.
+     * Get an event type for an entry updated.
      */
-    private Cache map = null;
+    public static int ENTRY_UPDATED = 1;
+
+    /**
+     * Get an event type for an entry flushed.
+     */
+    public static int ENTRY_FLUSHED = 2;
+
+    /**
+     * Get an event type for an entry removed.
+     */
+    public static int ENTRY_REMOVED = 4;
+
+    /**
+     * Get an event type for a group flush event.
+     */
+    public static int GROUP_FLUSHED = 8;
+
+    /**
+     * Get an event type for a pattern flush event.
+     */
+    public static int PATTERN_FLUSHED = 16;
+    
 
     /**
      * The entry that the event applies to.
      * @param eventType 
      */
     public CacheEntryEvent(Cache map, CacheEntry entry, int eventType) {
-        this(map, entry, eventType, null);
+        super(map, eventType);
+        this.entry = entry;
     }
 
-    /**
-     * Constructs a cache entry event object
-     *
-     * @param map     The cache map of the cache entry
-     * @param entry   The cache entry that the event applies to
-     * @param origin  The origin of this event
-     */
-    public CacheEntryEvent(Cache map, CacheEntry entry, int eventType, String origin) {
-        super(origin);
-        this.map = map;
-        this.entry = entry;
-    }
 
     /**
      * Retrieve the cache entry that the event applies to.
         return entry;
     }
 
-    /**
-     * Retrieve the cache map where the entry resides.
-     */
-    public Cache getMap() {
-        return map;
-    }
+    
 
     public String toString() {
         return "key=" + entry.getKey();

src/core/java/com/opensymphony/oscache/events/CacheEntryEventType.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.events;
-
-
-/**
- * This is all the possible events that may occur on a cache entry or
- * collection of cache entries.<p>
- * There is a corresponding interface {@link CacheEntryEventListener} for
- * handling these events.
- *
- * @version        $Revision$
- * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
- */
-public final class CacheEntryEventType {
-    /**
-     * Get an event type for an entry added.
-     */
-    public static CacheEntryEventType ENTRY_ADDED = new CacheEntryEventType();
-
-    /**
-     * Get an event type for an entry updated.
-     */
-    public static CacheEntryEventType ENTRY_UPDATED = new CacheEntryEventType();
-
-    /**
-     * Get an event type for an entry flushed.
-     */
-    public static CacheEntryEventType ENTRY_FLUSHED = new CacheEntryEventType();
-
-    /**
-     * Get an event type for an entry removed.
-     */
-    public static CacheEntryEventType ENTRY_REMOVED = new CacheEntryEventType();
-
-    /**
-     * Get an event type for a group flush event.
-     */
-    public static CacheEntryEventType GROUP_FLUSHED = new CacheEntryEventType();
-
-    /**
-     * Get an event type for a pattern flush event.
-     */
-    public static CacheEntryEventType PATTERN_FLUSHED = new CacheEntryEventType();
-
-    /**
-     * Private constructor to ensure that no object of that type are
-     * created externally.
-     */
-    private CacheEntryEventType() {
-    }
-}

src/core/java/com/opensymphony/oscache/events/CacheMapAccessEvent.java

 	  /**
      * Get an event type for a cache hit.
      */
-    public static int HIT = 16;
+    public static int HIT = 0;
 
     /**
      * Get an event type for a cache miss.
      */
-    public static int MISS = 32;
+    public static int MISS = 1;
 
     /**
      * Get an event type for when the data was found in the cache but was stale.
      */
-    public static int STALE_HIT = 64;
+    public static int STALE_HIT = 2;
 
     /**
      * Constructor.

src/core/java/com/opensymphony/oscache/events/CachewideEvent.java

     /**
      * Get an event type for a cache flush event.
      */
-    public static int CACHE_FLUSHED = 2048;
+    public static int CACHE_FLUSHED = 0;
 
     /**
      * Constructs a cachewide event with the specified origin.

src/core/java/com/opensymphony/oscache/events/ScopeEvent.java

 
 import java.util.Date;
 
+import com.opensymphony.oscache.core.Cache;
+
 /**
  * A <code>ScopeEvent</code> is created when an event occurs across one or all scopes.
  * This type of event is only applicable to the <code>ServletCacheAdministrator</code>.
  * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
  */
 public final class ScopeEvent extends CacheEvent {
+    
+	/**
+     * Specifies an event type for the all scope flushed event.
+     */
+    public static int ALL_SCOPES_FLUSHED = 0;
+
     /**
+     * Specifies an event type for the flushing of a  specific scope.
+     */
+    public static int SCOPE_FLUSHED = 1;
+	
+	
+	/**
      * Date that the event applies to.
      */
     private Date date = null;
 
-    /**
-     * Type of the event.
-     */
-    private ScopeEventType eventType = null;
 
     /**
      * Scope that applies to this event.
      * @param scope       Scope that applies to the event.
      * @param date        Date that the event applies to.
      */
-    public ScopeEvent(ScopeEventType eventType, int scope, Date date) {
-        this(eventType, scope, date, null);
-    }
-
-    /**
-     * Constructs a scope event object.
-     *
-     * @param eventType   Type of the event.
-     * @param scope       Scope that applies to the event.
-     * @param date        Date that the event applies to.
-     * @param origin      The origin of this event.
-     */
-    public ScopeEvent(ScopeEventType eventType, int scope, Date date, String origin) {
-        super(origin);
-        this.eventType = eventType;
+    public ScopeEvent(Cache cache, int eventType, int scope, Date date) {
+        super(cache, eventType);
         this.scope = scope;
         this.date = date;
     }

src/core/java/com/opensymphony/oscache/events/ScopeEventType.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.events;
-
-
-/**
- * This is an enumeration of all the possible events that may occur
- * at the scope level. Scope-level events are only relevant to the
- * <code>ServletCacheAdministrator</code>.
- *
- * @version        $Revision$
- * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
- */
-public final class ScopeEventType {
-    /**
-     * Specifies an event type for the all scope flushed event.
-     */
-    public static ScopeEventType ALL_SCOPES_FLUSHED = new ScopeEventType();
-
-    /**
-     * Specifies an event type for the flushing of a  specific scope.
-     */
-    public static ScopeEventType SCOPE_FLUSHED = new ScopeEventType();
-
-    /**
-     * Private constructor to ensure that no object of that type are
-     * created externally.
-     */
-    private ScopeEventType() {
-    }
-}

src/core/java/com/opensymphony/oscache/extra/CacheEntryEventListenerImpl.java

     public String toString() {
         return ("Added " + entryAddedCount + ", Updated " + entryUpdatedCount + ", Flushed " + entryFlushedCount + ", Removed " + entryRemovedCount + ", Groups Flushed " + groupFlushedCount + ", Patterns Flushed " + patternFlushedCount + ", Cache Flushed " + cacheFlushedCount);
     }
+
+	public void onChange(CacheEvent event) {
+		// TODO Auto-generated method stub
+		
+	}
 }

src/core/java/com/opensymphony/oscache/extra/CacheMapAccessEventListenerImpl.java

  */
 package com.opensymphony.oscache.extra;
 
+import com.opensymphony.oscache.events.CacheEvent;
 import com.opensymphony.oscache.events.CacheMapAccessEvent;
 import com.opensymphony.oscache.events.CacheMapAccessEventListener;
-import com.opensymphony.oscache.events.CacheMapAccessEventType;
 
 /**
  * Implementation of a CacheMapAccessEventListener. It uses the events to count
      */
     public void accessed(CacheMapAccessEvent event) {
         // Retrieve the event type and update the counters
-        CacheMapAccessEventType type = event.getEventType();
+        int type = event.getEventType();
 
         // Handles a hit event
-        if (type == CacheMapAccessEventType.HIT) {
+        if (type == CacheMapAccessEvent.HIT) {
             hitCount++;
         }
         // Handles a stale hit event
-        else if (type == CacheMapAccessEventType.STALE_HIT) {
+        else if (type == CacheMapAccessEvent.STALE_HIT) {
             staleHitCount++;
         }
         // Handles a miss event
-        else if (type == CacheMapAccessEventType.MISS) {
+        else if (type == CacheMapAccessEvent.MISS) {
             missCount++;
         } else {
             // Unknown event!
     public String toString() {
         return ("Hit count = " + hitCount + ", stale hit count = " + staleHitCount + " and miss count = " + missCount);
     }
+
+	public void onChange(CacheEvent event) {
+		// TODO Auto-generated method stub
+		
+	}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.