Search in sources :

Example 66 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings 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)

Example 67 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project hazelcast by hazelcast.

the class MapProxySupport method putAllInternal.

/**
     * This method will group all puts per partition and send a
     * {@link com.hazelcast.map.impl.operation.PutAllPartitionAwareOperationFactory} per member.
     * <p/>
     * If there are e.g. five keys for a single member, there will only be a single remote invocation
     * instead of having five remote invocations.
     * <p/>
     * There is also an optional support for batching to send smaller packages.
     * Takes care about {@code null} checks for keys and values.
     */
@SuppressWarnings({ "checkstyle:npathcomplexity", "UnnecessaryBoxing" })
@SuppressFBWarnings(value = "DM_NUMBER_CTOR", justification = "we need a shared counter object for each member per partition")
protected void putAllInternal(Map<?, ?> map) {
    try {
        int mapSize = map.size();
        if (mapSize == 0) {
            return;
        }
        boolean useBatching = isPutAllUseBatching(mapSize);
        int partitionCount = partitionService.getPartitionCount();
        int initialSize = getPutAllInitialSize(useBatching, mapSize, partitionCount);
        Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
        // init counters for batching
        MutableLong[] counterPerMember = null;
        Address[] addresses = null;
        if (useBatching) {
            counterPerMember = new MutableLong[partitionCount];
            addresses = new Address[partitionCount];
            for (Entry<Address, List<Integer>> addressListEntry : memberPartitionsMap.entrySet()) {
                MutableLong counter = new MutableLong();
                Address address = addressListEntry.getKey();
                for (int partitionId : addressListEntry.getValue()) {
                    counterPerMember[partitionId] = counter;
                    addresses[partitionId] = address;
                }
            }
        }
        // fill entriesPerPartition
        MapEntries[] entriesPerPartition = new MapEntries[partitionCount];
        for (Entry entry : map.entrySet()) {
            checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED);
            checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED);
            Data keyData = toData(entry.getKey(), partitionStrategy);
            int partitionId = partitionService.getPartitionId(keyData);
            MapEntries entries = entriesPerPartition[partitionId];
            if (entries == null) {
                entries = new MapEntries(initialSize);
                entriesPerPartition[partitionId] = entries;
            }
            entries.add(keyData, toData(entry.getValue()));
            if (useBatching) {
                long currentSize = ++counterPerMember[partitionId].value;
                if (currentSize % putAllBatchSize == 0) {
                    List<Integer> partitions = memberPartitionsMap.get(addresses[partitionId]);
                    invokePutAllOperation(addresses[partitionId], partitions, entriesPerPartition);
                }
            }
        }
        // invoke operations for entriesPerPartition
        for (Entry<Address, List<Integer>> entry : memberPartitionsMap.entrySet()) {
            invokePutAllOperation(entry.getKey(), entry.getValue(), entriesPerPartition);
        }
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : Address(com.hazelcast.nio.Address) Data(com.hazelcast.nio.serialization.Data) MutableLong(com.hazelcast.util.MutableLong) Entry(java.util.Map.Entry) MapEntries(com.hazelcast.map.impl.MapEntries) List(java.util.List) ArrayList(java.util.ArrayList) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 68 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project hazelcast by hazelcast.

the class ClientCacheProxyFactory method findCacheConfig.

@SuppressFBWarnings("RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED")
private CacheConfig findCacheConfig(String cacheName) {
    CacheConfig cacheConfig = configs.get(cacheName);
    if (cacheConfig != null) {
        return cacheConfig;
    }
    // otherwise, request it from server
    String simpleCacheName = cacheName.substring(HazelcastCacheManager.CACHE_MANAGER_PREFIX.length());
    cacheConfig = ClientCacheHelper.getCacheConfig(client, cacheName, simpleCacheName);
    if (cacheConfig != null) {
        configs.putIfAbsent(cacheName, cacheConfig);
    }
    return cacheConfig;
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 69 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project hazelcast by hazelcast.

the class ClientConsoleApp method handleAt.

@SuppressFBWarnings("DM_DEFAULT_ENCODING")
private void handleAt(String first) {
    if (first.length() == 1) {
        println("usage: @<file-name>");
        return;
    }
    File f = new File(first.substring(1));
    println("Executing script file " + f.getAbsolutePath());
    if (f.exists()) {
        try {
            BufferedReader br = new BufferedReader(new FileReader(f));
            String l = br.readLine();
            while (l != null) {
                handleCommand(l);
                l = br.readLine();
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        println("File not found! " + f.getAbsolutePath());
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 70 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project hazelcast by hazelcast.

the class HazelcastManifestTransformer method precompileOverrideInstructions.

@SuppressFBWarnings(value = "NP_UNWRITTEN_FIELD", justification = "Field is set by Maven")
private void precompileOverrideInstructions() {
    String importPackageInstructions = overrideInstructions.get(IMPORT_PACKAGE);
    if (importPackageInstructions != null) {
        List<String> packageInstructions = ElementParser.parseDelimitedString(importPackageInstructions, ',', true);
        for (String packageInstruction : packageInstructions) {
            PackageDefinition packageDefinition = new PackageDefinition(packageInstruction);
            Instruction instruction = Instruction.getPattern(packageDefinition.packageName);
            System.out.println("Compiled import instruction '" + packageInstruction + "' -> " + instruction);
            importOverrideInstructions.add(new InstructionDefinition(packageDefinition, instruction));
        }
    }
    String exportPackageInstructions = overrideInstructions.get(EXPORT_PACKAGE);
    if (exportPackageInstructions != null) {
        List<String> packageInstructions = ElementParser.parseDelimitedString(exportPackageInstructions, ',', true);
        for (String packageInstruction : packageInstructions) {
            PackageDefinition packageDefinition = new PackageDefinition(packageInstruction);
            Instruction instruction = Instruction.getPattern(packageDefinition.packageName);
            System.out.println("Compiled export instruction '" + packageInstruction + "' -> " + instruction);
            exportOverrideInstructions.add(new InstructionDefinition(packageDefinition, instruction));
        }
    }
}
Also used : Instruction(aQute.lib.osgi.Instruction) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)142 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)20 JPanel (javax.swing.JPanel)14 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)13 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)13 FlowLayout (java.awt.FlowLayout)8 BoxLayout (javax.swing.BoxLayout)7 Location (jmri.jmrit.operations.locations.Location)7 Dimension (java.awt.Dimension)5 FileOutputStream (java.io.FileOutputStream)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 Iterator (java.util.Iterator)5 JScrollPane (javax.swing.JScrollPane)5 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 Entry (java.util.Map.Entry)4