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());
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project hazelcast by hazelcast.
the class ConsoleApp method handleCommand.
/**
* Handles a command.
*/
@SuppressFBWarnings("DM_EXIT")
@SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:methodlength" })
protected void handleCommand(String inputCommand) {
String command = inputCommand;
if (command == null) {
return;
}
command = command.trim();
if (command.length() == 0) {
return;
}
if (command.contains("__")) {
namespace = command.split("__")[0];
command = command.substring(command.indexOf("__") + 2);
}
if (echo) {
handleEcho(command);
}
if (command.startsWith("//")) {
return;
}
String first = command;
int spaceIndex = command.indexOf(' ');
String[] argsSplit = command.split(" ");
String[] args = new String[argsSplit.length];
for (int i = 0; i < argsSplit.length; i++) {
args[i] = argsSplit[i].trim();
}
if (spaceIndex != -1) {
first = args[0];
}
if (command.startsWith("help")) {
handleHelp(command);
} else if (first.startsWith("#") && first.length() > 1) {
int repeat = Integer.parseInt(first.substring(1));
long started = Clock.currentTimeMillis();
for (int i = 0; i < repeat; i++) {
handleCommand(command.substring(first.length()).replaceAll("\\$i", "" + i));
}
long elapsedSeconds = MILLISECONDS.toSeconds(Clock.currentTimeMillis() - started);
println("ops/s = " + repeat / elapsedSeconds);
} else if (first.startsWith("&") && first.length() > 1) {
final int fork = Integer.parseInt(first.substring(1));
final String threadCommand = command.substring(first.length());
ExecutorService pool = Executors.newFixedThreadPool(fork);
for (int i = 0; i < fork; i++) {
final int threadID = i;
pool.submit(new Runnable() {
@Override
public void run() {
String command = threadCommand;
String[] threadArgs = command.replaceAll("\\$t", "" + threadID).trim().split(" ");
// TODO &t #4 m.putmany x k
if ("m.putmany".equals(threadArgs[0]) || "m.removemany".equals(threadArgs[0])) {
if (threadArgs.length < 4) {
command += " " + Integer.parseInt(threadArgs[1]) * threadID;
}
}
handleCommand(command);
}
});
}
pool.shutdown();
try {
pool.awaitTermination(1, TimeUnit.HOURS);
} catch (Exception e) {
e.printStackTrace();
}
} else if (first.startsWith("@")) {
handleAt(first);
} else if (command.indexOf(';') != -1) {
handleColon(command);
} else if ("silent".equals(first)) {
silent = Boolean.parseBoolean(args[1]);
} else if ("shutdown".equals(first)) {
hazelcast.getLifecycleService().shutdown();
} else if ("echo".equals(first)) {
echo = Boolean.parseBoolean(args[1]);
println("echo: " + echo);
} else if ("ns".equals(first)) {
handleNamespace(command.substring(first.length()).trim());
} else if ("whoami".equals(first)) {
handleWhoami();
} else if ("who".equals(first)) {
handleWho();
} else if ("jvm".equals(first)) {
handleJvm();
} else if (first.contains("ock") && !first.contains(".")) {
handleLock(args);
} else if (first.contains(".size")) {
handleSize(args);
} else if (first.contains(".clear")) {
handleClear(args);
} else if (first.contains(".destroy")) {
handleDestroy(args);
} else if (first.contains(".iterator")) {
handleIterator(args);
} else if (first.contains(".contains")) {
handleContains(args);
} else if (first.contains(".stats")) {
handStats(args);
} else if ("t.publish".equals(first)) {
handleTopicPublish(args);
} else if ("q.offer".equals(first)) {
handleQOffer(args);
} else if ("q.take".equals(first)) {
handleQTake(args);
} else if ("q.poll".equals(first)) {
handleQPoll(args);
} else if ("q.peek".equals(first)) {
handleQPeek(args);
} else if ("q.capacity".equals(first)) {
handleQCapacity(args);
} else if ("q.offermany".equals(first)) {
handleQOfferMany(args);
} else if ("q.pollmany".equals(first)) {
handleQPollMany(args);
} else if ("s.add".equals(first)) {
handleSetAdd(args);
} else if ("s.remove".equals(first)) {
handleSetRemove(args);
} else if ("s.addmany".equals(first)) {
handleSetAddMany(args);
} else if ("s.removemany".equals(first)) {
handleSetRemoveMany(args);
} else if (first.equals("m.replace")) {
handleMapReplace(args);
} else if (first.equalsIgnoreCase("m.putIfAbsent")) {
handleMapPutIfAbsent(args);
} else if (first.equals("m.putAsync")) {
handleMapPutAsync(args);
} else if (first.equals("m.getAsync")) {
handleMapGetAsync(args);
} else if (first.equals("m.put")) {
handleMapPut(args);
} else if (first.equals("m.get")) {
handleMapGet(args);
} else if (first.equalsIgnoreCase("m.getMapEntry")) {
handleMapGetMapEntry(args);
} else if (first.equals("m.remove")) {
handleMapRemove(args);
} else if (first.equals("m.evict")) {
handleMapEvict(args);
} else if (first.equals("m.putmany") || first.equalsIgnoreCase("m.putAll")) {
handleMapPutMany(args);
} else if (first.equals("m.getmany")) {
handleMapGetMany(args);
} else if (first.equals("m.removemany")) {
handleMapRemoveMany(args);
} else if (command.equalsIgnoreCase("m.localKeys")) {
handleMapLocalKeys();
} else if (command.equalsIgnoreCase("m.localSize")) {
handleMapLocalSize();
} else if (command.equals("m.keys")) {
handleMapKeys();
} else if (command.equals("m.values")) {
handleMapValues();
} else if (command.equals("m.entries")) {
handleMapEntries();
} else if (first.equals("m.lock")) {
handleMapLock(args);
} else if (first.equalsIgnoreCase("m.tryLock")) {
handleMapTryLock(args);
} else if (first.equals("m.unlock")) {
handleMapUnlock(args);
} else if (first.contains(".addListener")) {
handleAddListener(args);
} else if (first.equals("m.removeMapListener")) {
handleRemoveListener(args);
} else if (first.equals("m.unlock")) {
handleMapUnlock(args);
} else if (first.equals("mm.put")) {
handleMultiMapPut(args);
} else if (first.equals("mm.get")) {
handleMultiMapGet(args);
} else if (first.equals("mm.remove")) {
handleMultiMapRemove(args);
} else if (command.equals("mm.keys")) {
handleMultiMapKeys();
} else if (command.equals("mm.values")) {
handleMultiMapValues();
} else if (command.equals("mm.entries")) {
handleMultiMapEntries();
} else if (first.equals("mm.lock")) {
handleMultiMapLock(args);
} else if (first.equalsIgnoreCase("mm.tryLock")) {
handleMultiMapTryLock(args);
} else if (first.equals("mm.unlock")) {
handleMultiMapUnlock(args);
} else if (first.equals("l.add")) {
handleListAdd(args);
} else if (first.equals("l.set")) {
handleListSet(args);
} else if ("l.addmany".equals(first)) {
handleListAddMany(args);
} else if (first.equals("l.remove")) {
handleListRemove(args);
} else if (first.equals("l.contains")) {
handleListContains(args);
} else if ("a.get".equals(first)) {
handleAtomicNumberGet(args);
} else if ("a.set".equals(first)) {
handleAtomicNumberSet(args);
} else if ("a.inc".equals(first)) {
handleAtomicNumberInc(args);
} else if ("a.dec".equals(first)) {
handleAtomicNumberDec(args);
} else if (first.equals("execute")) {
execute(args);
} else if (first.equals("partitions")) {
handlePartitions(args);
// } else if (first.equals("txn")) {
// hazelcast.getTransaction().begin();
// } else if (first.equals("commit")) {
// hazelcast.getTransaction().commit();
// } else if (first.equals("rollback")) {
// hazelcast.getTransaction().rollback();
} else if (first.equalsIgnoreCase("executeOnKey")) {
executeOnKey(args);
} else if (first.equalsIgnoreCase("executeOnMember")) {
executeOnMember(args);
} else if (first.equalsIgnoreCase("executeOnMembers")) {
executeOnMembers(args);
// } else if (first.equalsIgnoreCase("longOther") || first.equalsIgnoreCase("executeLongOther")) {
// executeLongTaskOnOtherMember(args);
// } else if (first.equalsIgnoreCase("long") || first.equalsIgnoreCase("executeLong")) {
// executeLong(args);
} else if (first.equalsIgnoreCase("instances")) {
handleInstances(args);
} else if (first.equalsIgnoreCase("quit") || first.equalsIgnoreCase("exit")) {
System.exit(0);
} else if (first.startsWith("e") && first.endsWith(".simulateLoad")) {
handleExecutorSimulate(args);
} else {
println("type 'help' for help");
}
}
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!");
}
}
}
}
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);
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project hazelcast by hazelcast.
the class AbstractCacheRecordStore method deleteAllCacheEntry.
@SuppressFBWarnings("WMI_WRONG_MAP_ITERATOR")
protected void deleteAllCacheEntry(Set<Data> keys) {
if (isWriteThrough() && cacheWriter != null && keys != null && !keys.isEmpty()) {
Map<Object, Data> keysToDelete = new HashMap<Object, Data>();
for (Data key : keys) {
Object localKeyObj = dataToValue(key);
keysToDelete.put(localKeyObj, key);
}
Set<Object> keysObject = keysToDelete.keySet();
try {
cacheWriter.deleteAll(keysObject);
} catch (Exception e) {
if (!(e instanceof CacheWriterException)) {
throw new CacheWriterException("Exception in CacheWriter during deleteAll", e);
} else {
throw (CacheWriterException) e;
}
} finally {
for (Object undeletedKey : keysObject) {
Data undeletedKeyData = keysToDelete.get(undeletedKey);
keys.remove(undeletedKeyData);
}
}
}
}
Aggregations