/**
   * Called immediately after an element has been put into the cache and the element already existed
   * in the cache. This is thus an update.
   *
   * <p>The {@link net.sf.ehcache.Cache#put(net.sf.ehcache.Element)} method will block until this
   * method returns.
   *
   * <p>Implementers may wish to have access to the Element's fields, including value, so the
   * element is provided. Implementers should be careful not to modify the element. The effect of
   * any modifications is undefined.
   *
   * @param cache the cache emitting the notification
   * @param element the element which was just put into the cache.
   */
  public final void notifyElementUpdated(final Ehcache cache, final Element element)
      throws CacheException {
    if (notAlive()) {
      return;
    }
    if (!replicateUpdates) {
      return;
    }

    if (replicateUpdatesViaCopy) {
      if (!element.isSerializable()) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              "Object with key "
                  + element.getObjectKey()
                  + " is not Serializable and cannot be updated via copy.");
        }
        return;
      }
      addToReplicationQueue(new CacheEventMessage(EventMessage.PUT, cache, element, null));
    } else {
      if (!element.isKeySerializable()) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              "Object with key "
                  + element.getObjectKey()
                  + " does not have a Serializable key and cannot be replicated via invalidate.");
        }
        return;
      }
      addToReplicationQueue(
          new CacheEventMessage(EventMessage.REMOVE, cache, null, element.getKey()));
    }
  }
Exemplo n.º 2
0
 /**
  * Spools all elements to disk, in preparation for shutdown.
  *
  * <p>Relies on being called from a synchronized method
  *
  * <p>This revised implementation is a little slower but avoids using increased memory during the
  * method.
  */
 protected final void spoolAllToDisk() {
   Object[] keys = getKeyArray();
   for (int i = 0; i < keys.length; i++) {
     Element element = (Element) map.get(keys[i]);
     if (element != null) {
       if (!element.isSerializable()) {
         if (LOG.isLoggable(Level.FINE)) {
           LOG.fine(
               "Object with key "
                   + element.getObjectKey()
                   + " is not Serializable and is not being overflowed to disk.");
         }
       } else {
         spoolToDisk(element);
         // Don't notify listeners. They are not being removed from the cache, only a store
         remove(keys[i]);
       }
     }
   }
 }
  /**
   * {@inheritDoc}
   *
   * <p>This implementation queues the put notification for in-order replication to peers.
   *
   * @param cache the cache emitting the notification
   * @param element the element which was just put into the cache.
   */
  public final void notifyElementPut(final Ehcache cache, final Element element)
      throws CacheException {
    if (notAlive()) {
      return;
    }

    if (!replicatePuts) {
      return;
    }

    if (!element.isSerializable()) {
      if (LOG.isWarnEnabled()) {
        LOG.warn(
            "Object with key "
                + element.getObjectKey()
                + " is not Serializable and cannot be replicated");
      }
      return;
    }
    addToReplicationQueue(new CacheEventMessage(EventMessage.PUT, cache, element, null));
  }
Exemplo n.º 4
0
  /**
   * Evict the <code>Element</code>.
   *
   * <p>Evict means that the <code>Element</code> is:
   *
   * <ul>
   *   <li>if, the store is diskPersistent, the <code>Element</code> is spooled to the DiskStore
   *   <li>if not, the <code>Element</code> is removed.
   * </ul>
   *
   * @param element the <code>Element</code> to be evicted.
   */
  protected final void evict(Element element) throws CacheException {
    boolean spooled = false;
    if (cache.getCacheConfiguration().isOverflowToDisk()) {
      if (!element.isSerializable()) {
        if (LOG.isLoggable(Level.FINE)) {
          LOG.log(
              Level.FINE,
              new StringBuffer("Object with key ")
                  .append(element.getObjectKey())
                  .append(" is not Serializable and cannot be overflowed to disk")
                  .toString());
        }
      } else {
        spoolToDisk(element);
        spooled = true;
      }
    }

    if (!spooled) {
      cache.getCacheEventNotificationService().notifyElementEvicted(element, false);
    }
  }