blob: 643ad14cae0c338d810e46a6b1923af2d58f29de [file] [log] [blame]
/*=========================================================================
* Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
* This product is protected by U.S. and international copyright
* and intellectual property laws. Pivotal products are covered by
* one or more patents listed at http://www.pivotal.io/patents.
*=========================================================================
*/
/**
* File comment
*/
package com.gemstone.gemfire.internal.cache.xmlcache;
import java.util.Set;
import com.gemstone.gemfire.cache.control.RebalanceFactory;
import com.gemstone.gemfire.cache.control.RebalanceOperation;
import com.gemstone.gemfire.cache.control.ResourceManager;
import com.gemstone.gemfire.internal.cache.control.MemoryThresholds;
/**
* @author Mitch Thomas
* @since 6.0
*/
public class ResourceManagerCreation implements ResourceManager {
private volatile float criticalHeapPercentage;
private boolean criticalHeapSet = false;
private volatile float evictionHeapPercentage;
private boolean evictionHeapSet = false;
private volatile float criticalOffHeapPercentage;
private boolean criticalOffHeapSet = false;
private volatile float evictionOffHeapPercentage;
private boolean evictionOffHeapSet = false;
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#createRebalanceFactory()
*/
public RebalanceFactory createRebalanceFactory() {
throw new IllegalArgumentException("Unused");
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#getRebalanceOperations()
*/
public Set<RebalanceOperation> getRebalanceOperations() {
throw new IllegalArgumentException("Unused");
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#getCriticalHeapPercentage()
*/
public float getCriticalHeapPercentage() {
return this.criticalHeapPercentage;
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#setCriticalHeapPercentage(int)
*/
public void setCriticalHeapPercentage(float heapPercentage) {
this.criticalHeapSet = true;
this.criticalHeapPercentage = heapPercentage;
}
public void setCriticalHeapPercentageToDefault() {
this.criticalHeapPercentage = MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE;
}
/**
* Determine if the critical heap was configured
* @return true if it was configured
*/
public boolean hasCriticalHeap() {
return this.criticalHeapSet;
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#getCriticalOffHeapPercentage()
*/
@Override
public float getCriticalOffHeapPercentage() {
return this.criticalOffHeapPercentage;
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#setCriticalOffHeapPercentage(int)
*/
@Override
public void setCriticalOffHeapPercentage(final float offHeapPercentage) {
this.criticalOffHeapSet = true;
this.criticalOffHeapPercentage = offHeapPercentage;
}
public void setCriticalOffHeapPercentageToDefault() {
this.criticalOffHeapPercentage = MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE;
}
/**
* Determine if the critical off-heap was configured
* @return true if it was configured
*/
public boolean hasCriticalOffHeap() {
return this.criticalOffHeapSet;
}
public void configure(ResourceManager r) {
if (hasCriticalHeap()) {
r.setCriticalHeapPercentage(this.criticalHeapPercentage);
}
if (hasCriticalOffHeap()) {
r.setCriticalOffHeapPercentage(this.criticalOffHeapPercentage);
}
if (hasEvictionHeap()) {
r.setEvictionHeapPercentage(this.evictionHeapPercentage);
}
if (hasEvictionOffHeap()) {
r.setEvictionOffHeapPercentage(this.evictionOffHeapPercentage);
}
}
/**
* @param other the other ResourceManager with which to compare
*/
public void sameAs(ResourceManager other) {
if (getCriticalHeapPercentage() != other.getCriticalHeapPercentage()) {
throw new RuntimeException("Resource Manager critical heap percentages differ: "
+ getCriticalHeapPercentage() + " != " + other.getCriticalHeapPercentage());
}
if (getCriticalOffHeapPercentage() != other.getCriticalOffHeapPercentage()) {
throw new RuntimeException("Resource Manager critical off-heap percentages differ: "
+ getCriticalOffHeapPercentage() + " != " + other.getCriticalOffHeapPercentage());
}
if (hasEvictionHeap()) {
// If we don't have it set don't compare since other may have been set to
// a smart default.
if (getEvictionHeapPercentage() != other.getEvictionHeapPercentage()) {
throw new RuntimeException("Resource Manager eviction heap percentages differ: "
+ getEvictionHeapPercentage() + " != " + other.getEvictionHeapPercentage());
}
}
if (hasEvictionOffHeap()) {
// If we don't have it set don't compare since other may have been set to
// a smart default.
if (getEvictionOffHeapPercentage() != other.getEvictionOffHeapPercentage()) {
throw new RuntimeException("Resource Manager eviction off-heap percentages differ: "
+ getEvictionOffHeapPercentage() + " != " + other.getEvictionOffHeapPercentage());
}
}
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#getEvictionHeapPercentage()
*/
public float getEvictionHeapPercentage() {
return this.evictionHeapPercentage;
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#setEvictionHeapPercentage(int)
*/
public void setEvictionHeapPercentage(float heapPercentage) {
this.evictionHeapSet = true;
this.evictionHeapPercentage = heapPercentage;
}
public void setEvictionHeapPercentageToDefault() {
this.evictionHeapPercentage = MemoryThresholds.DEFAULT_EVICTION_PERCENTAGE;
}
/**
* Determine if the eviction heap was configured
* @return true if the eviction heap was configured
*/
public boolean hasEvictionHeap() {
return this.evictionHeapSet;
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#getEvictionOffHeapPercentage()
*/
public float getEvictionOffHeapPercentage() {
return this.evictionOffHeapPercentage;
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.control.ResourceManager#setEvictionOffHeapPercentage(int)
*/
public void setEvictionOffHeapPercentage(final float offHeapPercentage) {
this.evictionOffHeapSet = true;
this.evictionOffHeapPercentage = offHeapPercentage;
}
public void setEvictionOffHeapPercentageToDefault() {
this.evictionOffHeapPercentage = MemoryThresholds.DEFAULT_EVICTION_PERCENTAGE;
}
/**
* Determine if the eviction off-heap was configured
* @return true if the eviction off-heap was configured
*/
public boolean hasEvictionOffHeap() {
return this.evictionOffHeapSet;
}
}