コード例 #1
0
ファイル: Cache.java プロジェクト: pertyjons/infoglue
  /**
   * Put an 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 groups The cache groups to add the object to
   * @param content The object to cache
   * @param policy Object that implements the refresh policy logic
   */
  public void putInCache(
      String key, Object content, String[] groups, EntryRefreshPolicy policy, String origin) {
    CacheEntry cacheEntry = this.getCacheEntry(key, policy, origin);
    boolean isNewEntry = cacheEntry.isNew();

    // [CACHE-118] If we have an existing entry, create a new CacheEntry so we can still access the
    // old one later
    if (!isNewEntry) {
      cacheEntry = new CacheEntry(key, policy);
    }

    cacheEntry.setContent(content);
    cacheEntry.setGroups(groups);
    cacheMap.put(key, cacheEntry);

    // Signal to any threads waiting on this update that it's now ready for them
    // in the cache!
    completeUpdate(key);

    if (listenerList.getListenerCount() > 0) {
      CacheEntryEvent event = new CacheEntryEvent(this, cacheEntry, origin);

      if (isNewEntry) {
        dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_ADDED, event);
      } else {
        dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_UPDATED, event);
      }
    }
  }
コード例 #2
0
ファイル: Cache.java プロジェクト: pertyjons/infoglue
  /**
   * Flush all entries with keys that match a given pattern
   *
   * @param pattern The key must contain this given value
   * @param origin The origin of this flush request
   * @deprecated For performance and flexibility reasons it is preferable to store cache entries in
   *     groups and use the {@link #flushGroup(String, String)} method instead of relying on pattern
   *     flushing.
   */
  public void flushPattern(String pattern, String origin) {
    // Check the pattern
    if ((pattern != null) && (pattern.length() > 0)) {
      String key = null;
      CacheEntry entry = null;
      Iterator itr = cacheMap.keySet().iterator();

      while (itr.hasNext()) {
        key = (String) itr.next();

        if (key.indexOf(pattern) >= 0) {
          entry = (CacheEntry) cacheMap.get(key);

          if (entry != null) {
            flushEntry(entry, origin);
          }
        }
      }

      if (listenerList.getListenerCount() > 0) {
        dispatchCachePatternEvent(CacheEntryEventType.PATTERN_FLUSHED, pattern, origin);
      }
    } else {
      // Empty pattern, nothing to do
    }
  }
コード例 #3
0
ファイル: Cache.java プロジェクト: pertyjons/infoglue
  /**
   * Flush all entries in the cache on the given date/time.
   *
   * @param date The date at which all cache entries will be flushed.
   * @param origin The origin of this flush request (optional)
   */
  public void flushAll(Date date, String origin) {
    flushDateTime = date;

    if (listenerList.getListenerCount() > 0) {
      dispatchCachewideEvent(CachewideEventType.CACHE_FLUSHED, date, origin);
    }
  }
コード例 #4
0
ファイル: Cache.java プロジェクト: pertyjons/infoglue
  /**
   * Completely removes a cache entry from the cache and its associated cache groups.
   *
   * @param key The key of the entry to remove.
   * @param origin The origin of this remove request.
   */
  protected void removeEntry(String key, String origin) {
    CacheEntry cacheEntry = (CacheEntry) cacheMap.get(key);
    cacheMap.remove(key);

    if (listenerList.getListenerCount() > 0) {
      CacheEntryEvent event = new CacheEntryEvent(this, cacheEntry, origin);
      dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_REMOVED, event);
    }
  }
コード例 #5
0
ファイル: Cache.java プロジェクト: pertyjons/infoglue
  /**
   * Flush a cache entry. On completion of the flush, a <tt>CacheEntryEventType.ENTRY_FLUSHED</tt>
   * event is fired.
   *
   * @param entry The entry to flush
   * @param origin The origin of this flush event (optional)
   */
  private void flushEntry(CacheEntry entry, String origin) {
    String key = entry.getKey();

    // Flush the object itself
    entry.flush();

    if (!entry.isNew()) {
      // Update the entry's state in the map
      cacheMap.put(key, entry);
    }

    // Trigger an ENTRY_FLUSHED event. [CACHE-107] Do this for all flushes.
    if (listenerList.getListenerCount() > 0) {
      CacheEntryEvent event = new CacheEntryEvent(this, entry, origin);
      dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_FLUSHED, event);
    }
  }
コード例 #6
0
ファイル: Cache.java プロジェクト: pertyjons/infoglue
  /**
   * Flushes all unexpired objects that belong to the supplied group. On completion this method
   * fires a <tt>CacheEntryEventType.GROUP_FLUSHED</tt> event.
   *
   * @param group The group to flush
   * @param origin The origin of this flush event (optional)
   */
  public void flushGroup(String group, String origin) {
    // Flush all objects in the group
    Set groupEntries = cacheMap.getGroup(group);

    if (groupEntries != null) {
      Iterator itr = groupEntries.iterator();
      String key;
      CacheEntry entry;

      while (itr.hasNext()) {
        key = (String) itr.next();
        entry = (CacheEntry) cacheMap.get(key);

        if ((entry != null) && !entry.needsRefresh(CacheEntry.INDEFINITE_EXPIRY)) {
          flushEntry(entry, NESTED_EVENT);
        }
      }
    }

    if (listenerList.getListenerCount() > 0) {
      dispatchCacheGroupEvent(CacheEntryEventType.GROUP_FLUSHED, group, origin);
    }
  }
コード例 #7
0
 public void dispose() {
   destroySession();
   while (listeners.getListenerCount() > 0)
     removeSessionListener(listeners.getListeners(SessionListener.class)[0]);
   listeners = null;
 }