Skip to content

Commit

Permalink
Revert ISPN-3797: Put back the PassivationInterceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
pruivo authored and danberindei committed Sep 2, 2015
1 parent d42c54d commit b8f21d1
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 46 deletions.
22 changes: 4 additions & 18 deletions core/src/main/java/org/infinispan/eviction/PassivationManager.java
Expand Up @@ -26,11 +26,6 @@
import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
import org.infinispan.jmx.JmxStatisticsExposer;
import org.infinispan.jmx.annotations.MBean;
import org.infinispan.jmx.annotations.ManagedAttribute;
import org.infinispan.jmx.annotations.ManagedOperation;
import org.infinispan.jmx.annotations.MeasurementType;
import org.infinispan.loaders.CacheLoaderException;

/**
Expand All @@ -41,24 +36,15 @@
*/
@ThreadSafe
@Scope(Scopes.NAMED_CACHE)
@MBean(objectName = "Passivation", description = "Component that handles passivating entries to a CacheStore on eviction.")
public interface PassivationManager extends JmxStatisticsExposer {

public interface PassivationManager {

boolean isEnabled();

void passivate(InternalCacheEntry entry);

void passivateAll() throws CacheLoaderException;

@ManagedAttribute(
description = "Number of passivation events",
displayName = "Number of cache passivations",
measurementType = MeasurementType.TRENDSUP
)
long getPassivations();
long getPassivationCount();

@ManagedOperation(
description = "Resets statistics gathered by this component",
displayName = "Reset statistics")
void resetStatistics();
void resetPassivationCount();
}
Expand Up @@ -114,22 +114,12 @@ public void passivateAll() throws CacheLoaderException {
}

@Override
public long getPassivations() {
public long getPassivationCount() {
return passivations.get();
}

@Override
public boolean getStatisticsEnabled() {
return isEnabled();
}

@Override
public void setStatisticsEnabled(boolean enabled) {
this.statsEnabled = enabled;
}

@Override
public void resetStatistics() {
public void resetPassivationCount() {
passivations.set(0L);
}
}
Expand Up @@ -177,6 +177,7 @@ public InterceptorChain buildInterceptorChain() {
interceptorChain.appendInterceptor(createInterceptor(new ClusteredActivationInterceptor(), ClusteredActivationInterceptor.class), false);
else
interceptorChain.appendInterceptor(createInterceptor(new ActivationInterceptor(), ActivationInterceptor.class), false);
interceptorChain.appendInterceptor(createInterceptor(new PassivationInterceptor(), PassivationInterceptor.class), false);
} else {
if (configuration.clustering().cacheMode().isClustered())
interceptorChain.appendInterceptor(createInterceptor(new ClusteredCacheLoaderInterceptor(), ClusteredCacheLoaderInterceptor.class), false);
Expand Down
@@ -0,0 +1,74 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009 Red Hat Inc. and/or its affiliates and other
* contributors as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a full listing of
* individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.infinispan.interceptors;

import org.infinispan.container.DataContainer;
import org.infinispan.eviction.PassivationManager;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.interceptors.base.JmxStatsCommandInterceptor;
import org.infinispan.jmx.annotations.MBean;
import org.infinispan.jmx.annotations.ManagedAttribute;
import org.infinispan.jmx.annotations.ManagedOperation;
import org.infinispan.jmx.annotations.MeasurementType;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
/**
* Writes evicted entries back to the store on the way in through the CacheStore
*
* @since 4.0
*/
@MBean(objectName = "Passivation", description = "Component that handles passivating entries to a CacheStore on eviction.")
public class PassivationInterceptor extends JmxStatsCommandInterceptor {


PassivationManager passivator;

private static final Log log = LogFactory.getLog(PassivationInterceptor.class);

@Override
protected Log getLog() {
return log;
}

@Inject
public void setDependencies(PassivationManager passivator, DataContainer dataContainer) {
this.passivator = passivator;
}

@Override
@ManagedOperation(
description = "Resets statistics gathered by this component", displayName = "Reset statistics")
public void resetStatistics() {
passivator.resetPassivationCount();
}

@ManagedAttribute(
description = "Number of passivation events",
displayName = "Number of cache passivations",
measurementType = MeasurementType.TRENDSUP
)
public String getPassivations() {
if (!getStatisticsEnabled()) return "N/A";
return String.valueOf(passivator.getPassivationCount());
}
}
Expand Up @@ -77,12 +77,12 @@ public void testInMemoryEntryNotLostWithConcurrentActivePassive() throws Excepti
cache.addListener(new SlowPassivator());

assertEquals(0, activation.getActivationCount());
assertEquals(0, passivation.getPassivations());
assertEquals(0, passivation.getPassivationCount());

// 1. Store an entry in the cache
cache.put(1, "v1");
assertEquals(0, activation.getActivationCount());
assertEquals(0, passivation.getPassivations());
assertEquals(0, passivation.getPassivationCount());

ExecutorService exec = Executors.newFixedThreadPool(2);

Expand Down Expand Up @@ -114,7 +114,7 @@ public Object call() throws Exception {

activatorFuture.get(30, TimeUnit.SECONDS);
assertEquals(0, activation.getActivationCount());
assertEquals(1, passivation.getPassivations());
assertEquals(1, passivation.getPassivationCount());

// 4. With entry stored, then removed, now let the passivator thread
// remove the entry from memory
Expand All @@ -127,7 +127,7 @@ public Object call() throws Exception {
assertEquals("v1", cache.get(1));
assertEquals(1, activation.getActivationCount());
// Second key gets passivated now to make space for the 1st one
assertEquals(2, passivation.getPassivations());
assertEquals(2, passivation.getPassivationCount());
}

@Listener
Expand Down
Expand Up @@ -493,24 +493,16 @@ public void passivateAll() throws CacheLoaderException {
}

@Override
public long getPassivations() {
return delegate.getPassivations();
public long getPassivationCount() {
return delegate.getPassivationCount();
}

@Override
public boolean getStatisticsEnabled() {
return delegate.getStatisticsEnabled();
public void resetPassivationCount() {
delegate.resetPassivationCount();
}

@Override
public void setStatisticsEnabled(boolean enabled) {
delegate.setStatisticsEnabled(enabled);
}

@Override
public void resetStatistics() {
delegate.resetStatistics();
}
}

@Listener(sync = true)
Expand Down

0 comments on commit b8f21d1

Please sign in to comment.