Example #1
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);
        }
      }
    }
  }
Example #2
0
  /**
   * Dispatch a cache group event to all registered listeners.
   *
   * @param eventType The type of event (this is used to branch to the correct method handler)
   * @param group The cache group that the event applies to
   * @param origin The origin of this event (optional)
   */
  private void dispatchCacheGroupEvent(CacheEntryEventType eventType, String group, String origin) {
    CacheGroupEvent event = new CacheGroupEvent(this, group, 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 + 1] instanceof CacheEntryEventListener) {
        CacheEntryEventListener listener = (CacheEntryEventListener) listeners[i + 1];
        if (eventType.equals(CacheEntryEventType.GROUP_FLUSHED)) {
          listener.cacheGroupFlushed(event);
        }
      }
    }
  }