Пример #1
0
  /**
   * Dispatches a cache-wide event to all registered listeners.
   *
   * @param eventType The type of event (this is used to branch to the correct method handler)
   * @param origin The origin of this event (optional)
   */
  private void dispatchCachewideEvent(CachewideEventType eventType, Date date, String origin) {
    CachewideEvent event = new CachewideEvent(this, date, origin);

    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();

    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
      if (listeners[i] instanceof CacheEntryEventListener) {
        if (eventType.equals(CachewideEventType.CACHE_FLUSHED)) {
          CacheEntryEventListener listener = (CacheEntryEventListener) listeners[i + 1];
          listener.cacheFlushed(event);
        }
      }
    }
  }
Пример #2
0
  /**
   * Dispatch a cache entry event to all registered listeners.
   *
   * @param eventType The type of event (used to branch on the proper method)
   * @param event The event that was fired
   */
  private void dispatchCacheEntryEvent(CacheEntryEventType eventType, CacheEntryEvent event) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();

    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
      if (listeners[i + 1] instanceof CacheEntryEventListener) {
        CacheEntryEventListener listener = (CacheEntryEventListener) listeners[i + 1];
        if (eventType.equals(CacheEntryEventType.ENTRY_ADDED)) {
          listener.cacheEntryAdded(event);
        } else if (eventType.equals(CacheEntryEventType.ENTRY_UPDATED)) {
          listener.cacheEntryUpdated(event);
        } else if (eventType.equals(CacheEntryEventType.ENTRY_FLUSHED)) {
          listener.cacheEntryFlushed(event);
        } else if (eventType.equals(CacheEntryEventType.ENTRY_REMOVED)) {
          listener.cacheEntryRemoved(event);
        }
      }
    }
  }