Search in sources :

Example 1 with MemoryUnit

use of com.hazelcast.memory.MemoryUnit in project hazelcast by hazelcast.

the class AbstractDomConfigProcessor method createMemorySize.

protected MemorySize createMemorySize(Node node) {
    final String value = getTextContent(getNamedItemNode(node, "value"));
    final MemoryUnit unit = MemoryUnit.valueOf(getTextContent(getNamedItemNode(node, "unit")));
    return new MemorySize(Long.parseLong(value), unit);
}
Also used : MemoryUnit(com.hazelcast.memory.MemoryUnit) MemorySize(com.hazelcast.memory.MemorySize)

Example 2 with MemoryUnit

use of com.hazelcast.memory.MemoryUnit in project hazelcast by hazelcast.

the class AbstractXmlConfigHelper method fillNativeMemoryConfig.

@SuppressFBWarnings("DM_BOXED_PRIMITIVE_FOR_PARSING")
protected void fillNativeMemoryConfig(Node node, NativeMemoryConfig nativeMemoryConfig) {
    final NamedNodeMap atts = node.getAttributes();
    final Node enabledNode = atts.getNamedItem("enabled");
    final boolean enabled = enabledNode != null && getBooleanValue(getTextContent(enabledNode).trim());
    nativeMemoryConfig.setEnabled(enabled);
    final Node allocTypeNode = atts.getNamedItem("allocator-type");
    final String allocType = getTextContent(allocTypeNode);
    if (allocType != null && !"".equals(allocType)) {
        nativeMemoryConfig.setAllocatorType(NativeMemoryConfig.MemoryAllocatorType.valueOf(upperCaseInternal(allocType)));
    }
    for (Node n : childElements(node)) {
        final String nodeName = cleanNodeName(n);
        if ("size".equals(nodeName)) {
            final NamedNodeMap attrs = n.getAttributes();
            final String value = getTextContent(attrs.getNamedItem("value"));
            final MemoryUnit unit = MemoryUnit.valueOf(getTextContent(attrs.getNamedItem("unit")));
            MemorySize memorySize = new MemorySize(Long.valueOf(value), unit);
            nativeMemoryConfig.setSize(memorySize);
        } else if ("min-block-size".equals(nodeName)) {
            String value = getTextContent(n);
            nativeMemoryConfig.setMinBlockSize(Integer.parseInt(value));
        } else if ("page-size".equals(nodeName)) {
            String value = getTextContent(n);
            nativeMemoryConfig.setPageSize(Integer.parseInt(value));
        } else if ("metadata-space-percentage".equals(nodeName)) {
            String value = getTextContent(n);
            try {
                Number percentage = new DecimalFormat("##.#").parse(value);
                nativeMemoryConfig.setMetadataSpacePercentage(percentage.floatValue());
            } catch (ParseException e) {
                LOGGER.info("Metadata space percentage, [" + value + "], is not a proper value. Default value will be used!");
            }
        }
    }
}
Also used : MemoryUnit(com.hazelcast.memory.MemoryUnit) MemorySize(com.hazelcast.memory.MemorySize) NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) DecimalFormat(java.text.DecimalFormat) ParseException(java.text.ParseException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

MemorySize (com.hazelcast.memory.MemorySize)2 MemoryUnit (com.hazelcast.memory.MemoryUnit)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 DecimalFormat (java.text.DecimalFormat)1 ParseException (java.text.ParseException)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1