/** * copy constructor */ public EvictionAttributesImpl(EvictionAttributes other) { this.algorithm = other.getAlgorithm(); this.sizer = other.getObjectSizer(); this.maximum = other.getMaximum(); this.action = other.getAction(); }
public EvictionAttributes convertToEvictionAttributes() { EvictionAction action = EvictionAction.parseAction(evictionAction); ObjectSizer sizer; if (objectSizer != null) { try { Class<ObjectSizer> sizerClass = (Class<ObjectSizer>) ClassPathLoader.getLatest().forName(objectSizer); sizer = sizerClass.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException( "Unable to instantiate class " + objectSizer + " - " + e.toString()); } } else { sizer = ObjectSizer.DEFAULT; } if (maxMemory == null && maxEntryCount == null) { return EvictionAttributes.createLRUHeapAttributes(sizer, action); } else if (maxMemory != null) { return EvictionAttributes.createLRUMemoryAttributes(maxMemory, sizer, action); } else { return EvictionAttributes.createLRUEntryAttributes(maxEntryCount, action); } } }
@Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (!(obj instanceof EvictionAttributes)) { return false; } final EvictionAttributes other = (EvictionAttributes) obj; if (!getAlgorithm().equals(other.getAlgorithm())) { return false; } if (!getAction().equals(other.getAction())) { return false; } if (getMaximum() != other.getMaximum()) { return false; } return true; }
@Override public int hashCode() { return this.getAlgorithm().hashCode() ^ this.getMaximum(); }
public boolean isNoEviction() { return getAction() == EvictionAction.NONE; }
static void validateRegionAttributes(RegionAttributes attrs) { if (!attrs.getDataPolicy().withPartitioning()) { // replicated region throw new UnsupportedOperationException( "Lucene indexes on replicated regions are not supported"); } // For now we cannot support eviction with local destroy. // Eviction with overflow to disk still needs to be supported EvictionAttributes evictionAttributes = attrs.getEvictionAttributes(); EvictionAlgorithm evictionAlgorithm = evictionAttributes.getAlgorithm(); if (evictionAlgorithm != EvictionAlgorithm.NONE && evictionAttributes.getAction().isLocalDestroy()) { throw new UnsupportedOperationException( "Lucene indexes on regions with eviction and action local destroy are not supported"); } }
private boolean isMemoryEvictionConfigured() { boolean result = false; EvictionAttributes ea = region.getAttributes().getEvictionAttributes(); if (ea != null && ea.getAlgorithm().isLRUMemory()) { result = true; } return result; }
/** * Start the configuration of a <code>lru-memory-size</code> eviction controller. Allow for any of * the attributes to be missing. Store the attributes on the stack anticipating the declaration of * an {@link ObjectSizer}. * */ private void startLRUMemorySize(Attributes atts) { String lruAction = atts.getValue(ACTION); EvictionAction action = EvictionAction.DEFAULT_EVICTION_ACTION; if (lruAction != null) { action = EvictionAction.parseAction(lruAction); } String maximum = atts.getValue(MAXIMUM); int max = EvictionAttributes.DEFAULT_MEMORY_MAXIMUM; if (maximum != null) { max = parseInt(maximum); } // Store for later addition of ObjectSizer, if any (the cast is for clarity sake) stack.push(EvictionAttributes.createLRUMemoryAttributes(max, null, action)); }
/** * Create an <code>lru-heap-percentage</code> eviction controller, assigning it to the enclosed * <code>region-attributes</code> * */ private void startLRUHeapPercentage(Attributes atts) { final String lruAction = atts.getValue(ACTION); EvictionAction action = EvictionAction.DEFAULT_EVICTION_ACTION; if (lruAction != null) { action = EvictionAction.parseAction(lruAction); } // Store for later addition of ObjectSizer, if any stack.push(EvictionAttributes.createLRUHeapAttributes(null, action)); }
int capacity = diskProps.getOverFlowCapacity(); factory.setEvictionAttributes( EvictionAttributes.createLRUEntryAttributes(capacity, EvictionAction.OVERFLOW_TO_DISK)); factory.setEvictionAttributes(EvictionAttributes.createLRUHeapAttributes(ObjectSizer.DEFAULT, EvictionAction.OVERFLOW_TO_DISK));
/** * Create an <code>lru-entry-count</code> eviction controller, assigning it to the enclosed * <code>region-attributes</code>. Allow any combination of attributes to be provided. Use the * default values for any attribute that is not provided. * */ private void startLRUEntryCount(Attributes atts) { final String maximum = atts.getValue(MAXIMUM); int max = EvictionAttributes.DEFAULT_ENTRIES_MAXIMUM; if (maximum != null) { max = parseInt(maximum); } final String lruAction = atts.getValue(ACTION); EvictionAction action = EvictionAction.DEFAULT_EVICTION_ACTION; if (lruAction != null) { action = EvictionAction.parseAction(lruAction); } RegionAttributesCreation regAttrs = peekRegionAttributesContext(LRU_ENTRY_COUNT); regAttrs.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(max, action)); }
public EvictionAttributesInfo(EvictionAttributes ea) { EvictionAction evictAction = ea.getAction(); if (evictAction != null) { evictionAction = evictAction.toString(); } EvictionAlgorithm evictionAlgo = ea.getAlgorithm(); if (evictionAlgo != null) { evictionAlgorithm = evictionAlgo.toString(); } evictionMaxValue = ea.getMaximum(); }
protected boolean isEntryEvictDestroyEnabled() { return getEvictionAttributes() != null && EvictionAction.LOCAL_DESTROY.equals(getEvictionAttributes().getAction()); }
public int getSizeForEviction() { EvictionAttributes ea = this.getAttributes().getEvictionAttributes(); if (ea == null) return 0; EvictionAlgorithm algo = ea.getAlgorithm(); if (!algo.isLRUHeap()) return 0; EvictionAction action = ea.getAction(); int size = action.isLocalDestroy() ? this.getRegionMap().sizeInVM() : (int) this.getNumEntriesInVM(); return size; }
private static EvictionController createEvictionController() { EvictionController result = mock(EvictionController.class); when(result.getEvictionAlgorithm()).thenReturn(evictionAttributes.getAlgorithm()); EvictionCounters evictionCounters = mock(EvictionCounters.class); when(result.getCounters()).thenReturn(evictionCounters); return result; }
public static PartitionedRegion createMockQueueRegion(GemFireCacheImpl cache, String regionName) { // Mock queue region PartitionedRegion queueRegion = mock(PartitionedRegion.class); when(queueRegion.getFullPath()).thenReturn(regionName); when(queueRegion.getPrStats()).thenReturn(mock(PartitionedRegionStats.class)); when(queueRegion.getDataStore()).thenReturn(mock(PartitionedRegionDataStore.class)); when(queueRegion.getCache()).thenReturn(cache); EvictionAttributesImpl ea = (EvictionAttributesImpl) EvictionAttributes .createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK); EvictionController eviction = AbstractEvictionController.create(ea, false, cache.getDistributedSystem(), "queueRegion"); when(queueRegion.getEvictionController()).thenReturn(eviction); return queueRegion; }
EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK)); factory.setDiskSynchronous(true); factory.setDiskStoreName(cache.createDiskStoreFactory()
.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes( ManagementConstants.NOTIF_REGION_MAX_ENTRIES, EvictionAction.LOCAL_DESTROY));
@Override public String toString() { final StringBuilder buffer = new StringBuilder(128); buffer.append(" algorithm=").append(this.getAlgorithm()); if (!this.getAlgorithm().isNone()) { buffer.append("; action=").append(this.getAction()); if (!getAlgorithm().isLRUHeap()) { buffer.append("; maximum=").append(this.getMaximum()); } if (this.getObjectSizer() != null) { buffer.append("; sizer=").append(this.getObjectSizer()); } } return buffer.toString(); }
public EvictionAttributesInfo(EvictionAttributes ea) { EvictionAction evictAction = ea.getAction(); if (evictAction != null) { evictionAction = evictAction.toString(); } EvictionAlgorithm evictionAlgo = ea.getAlgorithm(); if (evictionAlgo != null) { evictionAlgorithm = evictionAlgo.toString(); } evictionMaxValue = ea.getMaximum(); }