All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.hibernate.cache.v53.impl.TombstoneAccessDelegate Maven / Gradle / Ivy

There is a newer version: 14.0.0.Dev02
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.infinispan.hibernate.cache.v53.impl;

import java.util.concurrent.CompletableFuture;

import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.infinispan.hibernate.cache.commons.InfinispanDataRegion;
import org.infinispan.hibernate.cache.commons.util.Tombstone;

/**
 * @author Radim Vansa <[email protected]>
 */
public class TombstoneAccessDelegate extends org.infinispan.hibernate.cache.commons.access.TombstoneAccessDelegate {
   public TombstoneAccessDelegate(InfinispanDataRegion region) {
      super(region);
   }

   @Override
   protected void write(Object session, Object key, Object value) {
      Sync sync = (Sync) ((SharedSessionContractImplementor) session).getCacheTransactionSynchronization();
      FutureUpdateInvocation invocation = new FutureUpdateInvocation(asyncWriteMap, key, value, region, sync.getCurrentTransactionStartTimestamp());
      sync.registerAfterCommit(invocation);
      // The update will be invalidating all putFromLoads for the duration of expiration or until removed by the synchronization
      Tombstone tombstone = new Tombstone(invocation.getUuid(), region.nextTimestamp() + region.getTombstoneExpiration());
      CompletableFuture future = writeMap.eval(key, tombstone);
      if (tombstone.isComplete()) {
         sync.registerBeforeCommit(future);
      } else {
         log.trace("Tombstone was not applied immediately, waiting.");
         // Slow path: there's probably a locking conflict and we need to wait
         // until the command gets applied (and replicated, too!).
         future.join();
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy