public ConsistentHash setConsistentHash(ConsistentHash consistentHash) {
   if (trace) log.tracef("Installing new consistent hash %s", consistentHash);
   cacheNotifier.notifyTopologyChanged(lastSuccessfulCH, consistentHash, true);
   this.consistentHash = consistentHash;
   cacheNotifier.notifyTopologyChanged(lastSuccessfulCH, consistentHash, false);
   return lastSuccessfulCH;
 }
示例#2
0
 private MVCCEntry newMvccEntryForPut(InvocationContext ctx, Object key) {
   MVCCEntry mvccEntry;
   if (trace) log.trace("Creating new entry.");
   notifier.notifyCacheEntryCreated(key, true, ctx);
   mvccEntry = createWrappedEntry(key, null, null, true, false, -1);
   mvccEntry.setCreated(true);
   ctx.putLookedUpEntry(key, mvccEntry);
   notifier.notifyCacheEntryCreated(key, false, ctx);
   return mvccEntry;
 }
 @Stop
 @SuppressWarnings("unused")
 private void stop() {
   if (clustered) {
     notifier.removeListener(cleanupService);
     cleanupService.stop();
     notifier.removeListener(this);
     currentTopologyId = CACHE_STOPPED_TOPOLOGY_ID; // indicate that the cache has stopped
   }
   shutDownGracefully();
 }
 @Start(priority = 9) // Start before cache loader manager
 @SuppressWarnings("unused")
 private void start() {
   final int concurrencyLevel = configuration.locking().concurrencyLevel();
   localTransactions =
       ConcurrentMapFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
   globalToLocalTransactions =
       ConcurrentMapFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
   if (configuration.clustering().cacheMode().isClustered()) {
     minTopologyRecalculationLock = new ReentrantLock();
     // Only initialize this if we are clustered.
     remoteTransactions =
         ConcurrentMapFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
     cleanupService.start(cacheName, rpcManager, configuration);
     notifier.addListener(cleanupService);
     notifier.addListener(this);
     clustered = true;
   }
 }
示例#5
0
 @Stop
 private void stop() {
   if (clustered) {
     notifier.removeListener(cleanupService);
     cm.removeListener(cleanupService);
     cleanupService.stop();
     cm.removeListener(this);
     currentViewId = CACHE_STOPPED_VIEW_ID; // indicate that the cache has stopped
   }
   shutDownGracefully();
 }
  @Stop
  @SuppressWarnings("unused")
  private void stop() {
    cacheManagerNotifier.removeListener(this);
    if (executorService != null) executorService.shutdownNow();

    if (clustered) {
      notifier.removeListener(this);
      currentTopologyId = CACHE_STOPPED_TOPOLOGY_ID; // indicate that the cache has stopped
    }
    shutDownGracefully();
  }
 private void commitClearCommand(
     DataContainer<Object, Object> dataContainer,
     ClearCacheEntry<Object, Object> cacheEntry,
     InvocationContext context,
     FlagAffectedCommand command) {
   List<InternalCacheEntry<Object, Object>> copyEntries =
       new ArrayList<>(dataContainer.entrySet());
   cacheEntry.commit(dataContainer, null);
   for (InternalCacheEntry entry : copyEntries) {
     notifier.notifyCacheEntryRemoved(
         entry.getKey(), entry.getValue(), entry.getMetadata(), false, context, command);
   }
 }
示例#8
0
 /**
  * Returns the {@link org.infinispan.transaction.xa.TransactionXaAdapter} corresponding to the
  * supplied transaction. If none exists, will be created first.
  */
 public LocalTransaction getOrCreateLocalTransaction(
     Transaction transaction, TxInvocationContext ctx) {
   LocalTransaction current = localTransactions.get(transaction);
   if (current == null) {
     Address localAddress = rpcManager != null ? rpcManager.getTransport().getAddress() : null;
     GlobalTransaction tx = txFactory.newGlobalTransaction(localAddress, false);
     current =
         txFactory.newLocalTransaction(
             transaction, tx, ctx.isImplicitTransaction(), currentViewId);
     log.tracef("Created a new local transaction: %s", current);
     localTransactions.put(transaction, current);
     notifier.notifyTransactionRegistered(tx, ctx);
   }
   return current;
 }
示例#9
0
  private Object returnValue(Object beingReplaced, boolean successful, InvocationContext ctx) {
    this.successful = successful;

    Object previousValue = oldValue == null ? beingReplaced : oldValue;

    if (successful) {
      notifier.notifyCacheEntryModified(key, previousValue, previousValue == null, true, ctx, this);
    }

    if (oldValue == null) {
      return beingReplaced;
    } else {
      return successful;
    }
  }
 /**
  * Returns the {@link org.infinispan.transaction.xa.TransactionXaAdapter} corresponding to the
  * supplied transaction. If none exists, will be created first.
  */
 public LocalTransaction getOrCreateLocalTransaction(
     Transaction transaction, boolean implicitTransaction) {
   LocalTransaction current = localTransactions.get(transaction);
   if (current == null) {
     Address localAddress = rpcManager != null ? rpcManager.getTransport().getAddress() : null;
     GlobalTransaction tx = txFactory.newGlobalTransaction(localAddress, false);
     current =
         txFactory.newLocalTransaction(transaction, tx, implicitTransaction, currentTopologyId);
     if (trace) log.tracef("Created a new local transaction: %s", current);
     localTransactions.put(transaction, current);
     globalToLocalTransactions.put(current.getGlobalTransaction(), current);
     notifier.notifyTransactionRegistered(tx, true);
   }
   return current;
 }
示例#11
0
  @Start(priority = 9) // Start before cache loader manager
  @SuppressWarnings("unused")
  private void start() {
    final int concurrencyLevel = configuration.locking().concurrencyLevel();
    localTransactions =
        CollectionFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
    globalToLocalTransactions =
        CollectionFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
    if (configuration.clustering().cacheMode().isClustered()) {
      minTopologyRecalculationLock = new ReentrantLock();
      // Only initialize this if we are clustered.
      remoteTransactions =
          CollectionFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
      notifier.addListener(this);
      clustered = true;
    }

    totalOrder = configuration.transaction().transactionProtocol().isTotalOrder();
    if (!totalOrder) {
      // Periodically run a task to cleanup the transaction table from completed transactions.
      ThreadFactory tf =
          new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
              String address =
                  rpcManager != null ? rpcManager.getTransport().getAddress().toString() : "local";
              Thread th = new Thread(r, "TxCleanupService," + cacheName + "," + address);
              th.setDaemon(true);
              return th;
            }
          };

      executorService = Executors.newSingleThreadScheduledExecutor(tf);

      long interval = configuration.transaction().reaperWakeUpInterval();
      executorService.scheduleAtFixedRate(
          new Runnable() {
            @Override
            public void run() {
              cleanupCompletedTransactions();
            }
          },
          interval,
          interval,
          TimeUnit.MILLISECONDS);
    }
  }
示例#12
0
 @Start
 private void start() {
   final int concurrencyLevel = configuration.locking().concurrencyLevel();
   localTransactions =
       ConcurrentMapFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
   if (configuration.clustering().cacheMode().isClustered()) {
     minViewRecalculationLock = new ReentrantLock();
     // Only initialize this if we are clustered.
     remoteTransactions =
         ConcurrentMapFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);
     cleanupService.start(cacheName, rpcManager, invoker);
     cm.addListener(cleanupService);
     cm.addListener(this);
     notifier.addListener(cleanupService);
     minTxViewId = rpcManager.getTransport().getViewId();
     currentViewId = minTxViewId;
     log.debugf("Min view id set to %s", minTxViewId);
     clustered = true;
   }
 }
    protected void notifyCommitEntry(
        boolean created,
        boolean removed,
        boolean expired,
        CacheEntry entry,
        InvocationContext ctx,
        FlagAffectedCommand command,
        Object previousValue,
        Metadata previousMetadata) {
      boolean isWriteOnly =
          (command instanceof WriteCommand) && ((WriteCommand) command).isWriteOnly();
      if (removed) {
        if (command instanceof RemoveCommand) {
          ((RemoveCommand) command).notify(ctx, previousValue, previousMetadata, false);
        } else {
          if (expired) {
            notifier.notifyCacheEntryExpired(entry.getKey(), previousValue, previousMetadata, ctx);
          } else {
            notifier.notifyCacheEntryRemoved(
                entry.getKey(), previousValue, previousMetadata, false, ctx, command);
          }

          // A write-only command only writes and so can't 100% guarantee
          // to be able to retrieve previous value when removed, so only
          // send remove event when the command is read-write.
          if (!isWriteOnly)
            functionalNotifier.notifyOnRemove(
                EntryViews.readOnly(entry.getKey(), previousValue, previousMetadata));

          functionalNotifier.notifyOnWrite(() -> EntryViews.noValue(entry.getKey()));
        }
      } else {
        // Notify entry event after container has been updated
        if (created) {
          notifier.notifyCacheEntryCreated(
              entry.getKey(), entry.getValue(), entry.getMetadata(), false, ctx, command);

          // A write-only command only writes and so can't 100% guarantee
          // that an entry has been created, so only send create event
          // when the command is read-write.
          if (!isWriteOnly) functionalNotifier.notifyOnCreate(EntryViews.readOnly(entry));

          functionalNotifier.notifyOnWrite(() -> EntryViews.readOnly(entry));
        } else {
          notifier.notifyCacheEntryModified(
              entry.getKey(),
              entry.getValue(),
              entry.getMetadata(),
              previousValue,
              previousMetadata,
              false,
              ctx,
              command);

          // A write-only command only writes and so can't 100% guarantee
          // that an entry has been created, so only send modify when the
          // command is read-write.
          if (!isWriteOnly)
            functionalNotifier.notifyOnModify(
                EntryViews.readOnly(entry.getKey(), previousValue, previousMetadata),
                EntryViews.readOnly(entry));

          functionalNotifier.notifyOnWrite(() -> EntryViews.readOnly(entry));
        }
      }
    }
示例#14
0
 public Set<Object> getListeners() {
   return notifier.getListeners();
 }
示例#15
0
 public void removeListener(Object listener) {
   notifier.removeListener(listener);
 }
示例#16
0
 public void addListener(Object listener) {
   notifier.addListener(listener);
 }
示例#17
0
 private void notifyCacheEntryVisit(
     InvocationContext ctx, FlagAffectedCommand command, Object key, Object value) {
   notifier.notifyCacheEntryVisited(key, value, true, ctx, command);
   notifier.notifyCacheEntryVisited(key, value, false, ctx, command);
 }
示例#18
0
 public void notify(
     InvocationContext ctx, Object removedValue, Metadata removedMetadata, boolean isPre) {
   notifier.notifyCacheEntryRemoved(key, removedValue, removedMetadata, isPre, ctx, this);
 }
  @Start(priority = 9) // Start before cache loader manager
  @SuppressWarnings("unused")
  public void start() {
    final int concurrencyLevel = configuration.locking().concurrencyLevel();
    // use the IdentityEquivalence because some Transaction implementation does not have a stable
    // hash code function
    // and it can cause some leaks in the concurrent map.
    localTransactions =
        CollectionFactory.makeConcurrentMap(
            concurrencyLevel,
            0.75f,
            concurrencyLevel,
            new IdentityEquivalence<Transaction>(),
            AnyEquivalence.getInstance());
    globalToLocalTransactions =
        CollectionFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);

    boolean transactional = configuration.transaction().transactionMode().isTransactional();
    if (clustered && transactional) {
      minTopologyRecalculationLock = new ReentrantLock();
      remoteTransactions =
          CollectionFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);

      ThreadFactory tf =
          new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
              String address =
                  rpcManager != null ? rpcManager.getTransport().getAddress().toString() : "local";
              Thread th = new Thread(r, "TxCleanupService," + cacheName + "," + address);
              th.setDaemon(true);
              return th;
            }
          };
      executorService = Executors.newSingleThreadScheduledExecutor(tf);

      notifier.addListener(this);
      cacheManagerNotifier.addListener(this);

      boolean totalOrder = configuration.transaction().transactionProtocol().isTotalOrder();
      if (!totalOrder) {
        completedTransactionsInfo = new CompletedTransactionsInfo();

        // Periodically run a task to cleanup the transaction table of completed transactions.
        long interval = configuration.transaction().reaperWakeUpInterval();
        executorService.scheduleAtFixedRate(
            new Runnable() {
              @Override
              public void run() {
                completedTransactionsInfo.cleanupCompletedTransactions();
              }
            },
            interval,
            interval,
            TimeUnit.MILLISECONDS);

        executorService.scheduleAtFixedRate(
            new Runnable() {
              @Override
              public void run() {
                cleanupTimedOutTransactions();
              }
            },
            interval,
            interval,
            TimeUnit.MILLISECONDS);
      }
    }
  }