| | |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.SortedSet; |
| | | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageDescriptor; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.AttributeValue; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.ResultCode; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.messages.MessageDescriptor; |
| | | |
| | | import static org.opends.server.loggers.ErrorLogger.logError; |
| | | import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString; |
| | | |
| | | |
| | | /** |
| | | * This class provides some common tools to all entry cache implementations. |
| | |
| | | { |
| | | ArrayList<Attribute> attrs = new ArrayList<Attribute>(); |
| | | |
| | | if (cacheHits != null) { |
| | | AttributeType hitsAttrType = |
| | | DirectoryServer.getDefaultAttributeType("entryCacheHits"); |
| | | LinkedHashSet<AttributeValue> hitsValues = |
| | | new LinkedHashSet<AttributeValue>(); |
| | | hitsValues.add(new AttributeValue(hitsAttrType, |
| | | cacheHits.toString())); |
| | | attrs.add(new Attribute(hitsAttrType, "entryCacheHits", |
| | | hitsValues)); |
| | | // Cache misses is required to get cache tries and hit ratio. |
| | | if (cacheMisses != null) { |
| | | AttributeType triesAttrType = |
| | | DirectoryServer.getDefaultAttributeType("entryCacheTries"); |
| | | LinkedHashSet<AttributeValue> triesValues = |
| | | new LinkedHashSet<AttributeValue>(); |
| | | Long cacheTries = cacheHits + cacheMisses; |
| | | triesValues.add(new AttributeValue(triesAttrType, |
| | | cacheTries.toString())); |
| | | attrs.add(new Attribute(triesAttrType, "entryCacheTries", |
| | | triesValues)); |
| | | if (cacheHits != null) |
| | | { |
| | | attrs |
| | | .add(Attributes.create("entryCacheHits", cacheHits.toString())); |
| | | |
| | | AttributeType hitRatioAttrType = |
| | | DirectoryServer.getDefaultAttributeType("entryCacheHitRatio"); |
| | | LinkedHashSet<AttributeValue> hitRatioValues = |
| | | new LinkedHashSet<AttributeValue>(); |
| | | Double hitRatioRaw = cacheTries > 0 ? |
| | | cacheHits.doubleValue() / cacheTries.doubleValue() : |
| | | cacheHits.doubleValue() / 1; |
| | | // Cache misses is required to get cache tries and hit ratio. |
| | | if (cacheMisses != null) |
| | | { |
| | | Long cacheTries = cacheHits + cacheMisses; |
| | | attrs.add(Attributes.create("entryCacheTries", cacheTries |
| | | .toString())); |
| | | |
| | | Double hitRatioRaw = cacheTries > 0 ? cacheHits.doubleValue() |
| | | / cacheTries.doubleValue() : cacheHits.doubleValue() / 1; |
| | | Double hitRatio = hitRatioRaw * 100D; |
| | | hitRatioValues.add(new AttributeValue(hitRatioAttrType, |
| | | Long.toString(hitRatio.longValue()))); |
| | | attrs.add(new Attribute(hitRatioAttrType, "entryCacheHitRatio", |
| | | hitRatioValues)); |
| | | attrs.add(Attributes.create("entryCacheHitRatio", Long |
| | | .toString(hitRatio.longValue()))); |
| | | } |
| | | } |
| | | |
| | | if (cacheSize != null) { |
| | | AttributeType memoryAttrType = |
| | | DirectoryServer.getDefaultAttributeType("currentEntryCacheSize"); |
| | | LinkedHashSet<AttributeValue> memoryValues = |
| | | new LinkedHashSet<AttributeValue>(); |
| | | memoryValues.add(new AttributeValue(memoryAttrType, |
| | | cacheSize.toString())); |
| | | attrs.add(new Attribute(memoryAttrType, "currentEntryCacheSize", |
| | | memoryValues)); |
| | | if (cacheSize != null) |
| | | { |
| | | attrs.add(Attributes.create("currentEntryCacheSize", cacheSize |
| | | .toString())); |
| | | } |
| | | |
| | | if (maxCacheSize != null) { |
| | | AttributeType maxMemoryAttrType = |
| | | DirectoryServer.getDefaultAttributeType("maxEntryCacheSize"); |
| | | LinkedHashSet<AttributeValue> maxMemoryValues = |
| | | new LinkedHashSet<AttributeValue>(); |
| | | maxMemoryValues.add(new AttributeValue(maxMemoryAttrType, |
| | | maxCacheSize.toString())); |
| | | attrs.add(new Attribute(maxMemoryAttrType, "maxEntryCacheSize", |
| | | maxMemoryValues)); |
| | | if (maxCacheSize != null) |
| | | { |
| | | attrs.add(Attributes.create("maxEntryCacheSize", maxCacheSize |
| | | .toString())); |
| | | } |
| | | |
| | | if (cacheCount != null) { |
| | | AttributeType entriesAttrType = |
| | | DirectoryServer.getDefaultAttributeType("currentEntryCacheCount"); |
| | | LinkedHashSet<AttributeValue> entriesValues = |
| | | new LinkedHashSet<AttributeValue>(); |
| | | entriesValues.add(new AttributeValue(entriesAttrType, |
| | | cacheCount.toString())); |
| | | attrs.add(new Attribute(entriesAttrType, "currentEntryCacheCount", |
| | | entriesValues)); |
| | | if (cacheCount != null) |
| | | { |
| | | attrs.add(Attributes.create("currentEntryCacheCount", cacheCount |
| | | .toString())); |
| | | } |
| | | |
| | | if (maxCacheCount != null) { |
| | | AttributeType maxEntriesAttrType = |
| | | DirectoryServer.getDefaultAttributeType("maxEntryCacheCount"); |
| | | LinkedHashSet<AttributeValue> maxEntriesValues = |
| | | new LinkedHashSet<AttributeValue>(); |
| | | maxEntriesValues.add(new AttributeValue(maxEntriesAttrType, |
| | | maxCacheCount.toString())); |
| | | attrs.add(new Attribute(maxEntriesAttrType, "maxEntryCacheCount", |
| | | maxEntriesValues)); |
| | | if (maxCacheCount != null) |
| | | { |
| | | attrs.add(Attributes.create("maxEntryCacheCount", maxCacheCount |
| | | .toString())); |
| | | } |
| | | |
| | | return attrs; |