@Override
  public void put(K k, V v, Metadata metadata) {
    boolean l1Entry = false;
    if (metadata instanceof L1Metadata) {
      metadata = ((L1Metadata) metadata).metadata();
      l1Entry = true;
    }
    InternalCacheEntry<K, V> e = entries.get(k);

    if (trace) {
      log.tracef(
          "Creating new ICE for writing. Existing=%s, metadata=%s, new value=%s",
          e, metadata, toStr(v));
    }
    final InternalCacheEntry<K, V> copy;
    if (l1Entry) {
      copy = entryFactory.createL1(k, v, metadata);
    } else if (e != null) {
      copy = entryFactory.update(e, v, metadata);
    } else {
      // this is a brand-new entry
      copy = entryFactory.create(k, v, metadata);
    }

    if (trace) log.tracef("Store %s in container", copy);

    entries.compute(
        copy.getKey(),
        (key, entry) -> {
          activator.onUpdate(key, entry == null);
          return copy;
        });
  }
 @Override
 public InternalCacheEntry<K, V> compute(K key, ComputeAction<K, V> action) {
   return entries.compute(
       key,
       (k, oldEntry) -> {
         InternalCacheEntry<K, V> newEntry = action.compute(k, oldEntry, entryFactory);
         if (newEntry == oldEntry) {
           return oldEntry;
         } else if (newEntry == null) {
           activator.onRemove(k, false);
           return null;
         }
         activator.onUpdate(k, oldEntry == null);
         if (trace) log.tracef("Store %s in container", newEntry);
         return newEntry;
       });
 }
 @Override
 public InternalCacheEntry<K, V> remove(Object k) {
   final InternalCacheEntry<K, V>[] reference = new InternalCacheEntry[1];
   entries.compute(
       (K) k,
       (key, entry) -> {
         activator.onRemove(key, entry == null);
         reference[0] = entry;
         return null;
       });
   InternalCacheEntry<K, V> e = reference[0];
   if (trace) {
     log.tracef("Removed %s from container", e);
   }
   return e == null || (e.canExpire() && e.isExpired(timeService.wallClockTime())) ? null : e;
 }
    @Override
    public Map<String, Number> call() throws Exception {

      Map<String, Number> map = new HashMap<>();
      Stats stats = remoteCache.getStats();
      map.put(AVERAGE_READ_TIME, stats.getAverageReadTime());
      map.put(AVERAGE_WRITE_TIME, stats.getAverageWriteTime());
      map.put(AVERAGE_REMOVE_TIME, stats.getAverageRemoveTime());
      map.put(EVICTIONS, stats.getEvictions());
      map.put(HITS, stats.getHits());
      map.put(MISSES, stats.getMisses());
      final CacheMode cacheMode = getCacheMode(remoteCache);
      // for replicated caches, we don't need to send the number of entries since it is the same in
      // all the nodes.
      if (cacheMode.isDistributed()) {
        map.put(NUMBER_OF_ENTRIES, stats.getCurrentNumberOfEntries() / numOwners());
      } else if (!cacheMode.isReplicated()) {
        map.put(NUMBER_OF_ENTRIES, stats.getCurrentNumberOfEntries());
      }
      map.put(STORES, stats.getStores());
      map.put(REMOVE_HITS, stats.getRemoveHits());
      map.put(REMOVE_MISSES, stats.getRemoveMisses());
      map.put(TIME_SINCE_START, stats.getTimeSinceStart());

      LockManager lockManager = remoteCache.getLockManager();
      map.put(NUMBER_OF_LOCKS_HELD, lockManager.getNumberOfLocksHeld());

      // number of locks available is not exposed through the LockManager interface
      map.put(NUMBER_OF_LOCKS_AVAILABLE, 0);

      // invalidations
      InvalidationInterceptor invalidationInterceptor =
          getFirstInterceptorWhichExtends(remoteCache, InvalidationInterceptor.class);
      if (invalidationInterceptor != null) {
        map.put(INVALIDATIONS, invalidationInterceptor.getInvalidations());
      } else {
        map.put(INVALIDATIONS, 0);
      }

      // passivations
      PassivationManager pManager =
          remoteCache.getComponentRegistry().getComponent(PassivationManager.class);
      if (pManager != null) {
        map.put(PASSIVATIONS, pManager.getPassivations());
      } else {
        map.put(PASSIVATIONS, 0);
      }

      // activations
      ActivationManager aManager =
          remoteCache.getComponentRegistry().getComponent(ActivationManager.class);
      if (pManager != null) {
        map.put(ACTIVATIONS, aManager.getActivationCount());
      } else {
        map.put(ACTIVATIONS, 0);
      }

      // cache loaders
      ActivationInterceptor aInterceptor =
          getFirstInterceptorWhichExtends(remoteCache, ActivationInterceptor.class);
      if (aInterceptor != null) {
        map.put(CACHE_LOADER_LOADS, aInterceptor.getCacheLoaderLoads());
        map.put(CACHE_LOADER_MISSES, aInterceptor.getCacheLoaderMisses());
      } else {
        map.put(CACHE_LOADER_LOADS, 0);
        map.put(CACHE_LOADER_MISSES, 0);
      }
      // cache store
      CacheWriterInterceptor interceptor =
          getFirstInterceptorWhichExtends(remoteCache, CacheWriterInterceptor.class);
      if (interceptor != null) {
        map.put(CACHE_WRITER_STORES, interceptor.getWritesToTheStores());
      } else {
        map.put(CACHE_WRITER_STORES, 0);
      }
      return map;
    }