Formatted with Google Java Style
This commit is contained in:
parent
1e2b04a75c
commit
7c283aa827
21 changed files with 872 additions and 816 deletions
3
.sonarlint/modules/bfclient/issues/index.pb
Normal file
3
.sonarlint/modules/bfclient/issues/index.pb
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
@
|
||||
src/bfclient.cpp,4/6/4680e865da2ad46d274693738207d7b9d80f04ae
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
msquid:S1118":Add a private constructor to hide the implicit public one.(ôÒÿùüÿÿÿÿHÓ•RMAJORZ
|
||||
CODE_SMELL
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
Œ
|
||||
squid:S135œ"YReduce the total number of break and continue statements in this loop to use at most one.(ÊÑ€ÄûÿÿÿÿHÈ•RMINORZ
|
||||
CODE_SMELL
|
||||
Œ
|
||||
squid:S135Ä"YReduce the total number of break and continue statements in this loop to use at most one.(ÊÑ€ÄûÿÿÿÿHÉ•RMINORZ
|
||||
CODE_SMELL
|
||||
ˆsquid:S14885"ZImmediately return this expression instead of assigning it to the temporary variable "kr".(·“žÉHÊ•RMINORZ
|
||||
CODE_SMELL
|
||||
wsquid:HiddenFieldChecké"8Rename "root" which hides the field declared at line 20.(Ë·Þ÷ÿÿÿÿÿHË•RMAJORZ
|
||||
CODE_SMELL
|
||||
„squid:S3776<18>"RRefactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed.(¨îïƒHÌ•RCRITICALZ
|
||||
CODE_SMELL
|
||||
’squid:S1149Q"_Replace the synchronized class "StringBuffer" by an unsynchronized one such as "StringBuilder".(¨âà<C3A2>øÿÿÿÿHÍ•RMAJORZ
|
||||
CODE_SMELL
|
||||
Ssquid:S3457#"%String contains no format specifiers.(Ï·Ž®HΕRMAJORZ
|
||||
CODE_SMELL
|
||||
Ssquid:S3457'"%String contains no format specifiers.(<28>¹ÓáHÏ•RMAJORZ
|
||||
CODE_SMELL
|
||||
Ysquid:S3457ê"%String contains no format specifiers.(óŠ¡ËþÿÿÿÿHЕRMAJORZ
|
||||
CODE_SMELL
|
||||
Tsquid:S3457ì"%String contains no format specifiers.(ÐÒ̉HÑ•RMAJORZ
|
||||
CODE_SMELL
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
Œsquid:UselessImportCheck "QRemove this unused import 'org.btcollider.cnc.keysrv.impl.keytree.KeyTreeServer'.(‹Ö†’H¶•RMINORZ
|
||||
CODE_SMELL
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
j"squid:SwitchLastCaseIsDefaultChecky""Add a default case to this switch.(¬ý<C2AC>½HÝ•RCRITICALZ
|
||||
CODE_SMELL
|
||||
Xsquid:S3457."%String contains no format specifiers.(’†þ‡ùÿÿÿÿHß•RMAJORZ
|
||||
CODE_SMELL
|
||||
osquid:S2259y"AA "NullPointerException" could be thrown; "suc" is nullable here.(¬ý<C2AC>½8¤ð’ä°,Hà•RMAJORZBUG
|
||||
ysquid:S1301y"KReplace this "switch" statement by "if" statements to increase readability.(¬ý<C2AC>½HÞ•RMINORZ
|
||||
CODE_SMELL
|
13
.sonarlint/modules/cnc/issues/index.pb
Normal file
13
.sonarlint/modules/cnc/issues/index.pb
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
g
|
||||
7src/main/java/org/btcollider/cnc/comm/ClientWorker.java,f/b/fb0de740b71d2edb598c4f3deb39da1c59c1ec4f
|
||||
Y
|
||||
)src/main/java/org/btcollider/cnc/CnC.java,e/c/ecc7f16c71ca2f68bf6a65ea47837815c0ff6322
|
||||
w
|
||||
Gsrc/main/java/org/btcollider/cnc/keysrv/impl/keytree/KeyTreeServer.java,7/c/7c3c3c10537a28026398df21221528f81672fc33
|
||||
f
|
||||
6src/main/java/org/btcollider/cnc/keysrv/KSFactory.java,1/3/136c36f2bf1690ff10397e07c3d82baa9b298770
|
||||
q
|
||||
Asrc/main/java/org/btcollider/cnc/keysrv/impl/keytree/KeyTree.java,b/a/ba1dbf788a980366658d348281a337f09d5317fc
|
||||
~
|
||||
Nsrc/main/java/org/btcollider/cnc/keysrv/impl/multistage/MultiStagedServer.java,3/8/3893e371f649cb23d5f6428b3ca5eeae3bd4979f
|
|
@ -1,12 +1,10 @@
|
|||
package org.btcollider.cnc;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.btcollider.cnc.comm.CommException;
|
||||
import org.btcollider.cnc.comm.CommServer;
|
||||
import org.btcollider.cnc.keysrv.KSFactory;
|
||||
import org.btcollider.cnc.keysrv.KeyServer;
|
||||
import org.btcollider.cnc.keysrv.impl.keytree.KeyTreeServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.io.InputStreamReader;
|
|||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.btcollider.cnc.dto.KeyRange;
|
||||
import org.btcollider.cnc.keysrv.KeyServer;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -92,9 +91,9 @@ public class ClientWorker implements Runnable {
|
|||
if (kr == null) {
|
||||
out.println("NIL");
|
||||
log.debug("Stop work sent to {}", clientSocket.getInetAddress());
|
||||
}
|
||||
else {
|
||||
String work = Long.toHexString(kr.getStart()) + " " + Long.toHexString(kr.getEnd()) + " " + kr.getTotal();
|
||||
} else {
|
||||
String work = Long.toHexString(kr.getStart()) + " " + Long.toHexString(kr.getEnd()) + " "
|
||||
+ kr.getTotal();
|
||||
out.println(work);
|
||||
log.debug("Work <{}> sent to {}", work, clientSocket.getInetAddress());
|
||||
}
|
||||
|
@ -114,6 +113,12 @@ public class ClientWorker implements Runnable {
|
|||
out.println("ACK");
|
||||
|
||||
String suc = in.readLine();
|
||||
if (suc == null) {
|
||||
log.warn("Result retrieved from {} for {} but couldn't read success status",
|
||||
clientSocket.getRemoteSocketAddress(), kr);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (suc) {
|
||||
case "NIL":
|
||||
log.debug("Keyrange {} unsuccessful", kr);
|
||||
|
@ -126,6 +131,8 @@ public class ClientWorker implements Runnable {
|
|||
writeKey(suc);
|
||||
out.println("ACK");
|
||||
break;
|
||||
default:
|
||||
assert (false);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -21,8 +21,7 @@ public class CommException extends Exception {
|
|||
super(cause);
|
||||
}
|
||||
|
||||
protected CommException(String message, Throwable cause,
|
||||
boolean enableSuppression,
|
||||
protected CommException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.net.Socket;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.btcollider.cnc.keysrv.KeyServer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.btcollider.cnc.dto;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
import org.btcollider.cnc.CnC;
|
||||
|
||||
public class KeyRange {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.btcollider.cnc.keysrv;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.btcollider.cnc.keysrv.impl.keytree.KeyTreeServer;
|
||||
import org.btcollider.cnc.keysrv.impl.multistage.MultiStagedServer;
|
||||
|
||||
|
@ -15,7 +14,8 @@ public class KSFactory {
|
|||
return build(index, depth, maxWorkSpan, timeUnit, 0);
|
||||
}
|
||||
|
||||
public static KeyServer build(int index, int depth, long maxWorkSpan, TimeUnit timeUnit, float pruneFraction) {
|
||||
public static KeyServer build(int index, int depth, long maxWorkSpan, TimeUnit timeUnit,
|
||||
float pruneFraction) {
|
||||
assert (pruneFraction >= 0.0 && pruneFraction <= 1.0);
|
||||
|
||||
long maxKey = ((long) 1 << index) | (((long) 1 << index) - 1);
|
||||
|
@ -24,7 +24,8 @@ public class KSFactory {
|
|||
return build(index, depth, maxWorkSpan, timeUnit, pruneKey);
|
||||
}
|
||||
|
||||
public static KeyServer build(int index, int depth, long maxWorkSpan, TimeUnit timeUnit, long pruneKey) {
|
||||
public static KeyServer build(int index, int depth, long maxWorkSpan, TimeUnit timeUnit,
|
||||
long pruneKey) {
|
||||
if (depth == 25) {
|
||||
return new KeyTreeServer(index, depth, timeUnit.toMillis(maxWorkSpan), pruneKey);
|
||||
} else {
|
||||
|
|
|
@ -4,8 +4,7 @@ import org.btcollider.cnc.dto.KeyRange;
|
|||
|
||||
public interface KeyServer {
|
||||
/**
|
||||
* Gets a free (= not setInWork and not setSearched)
|
||||
* KeyRange from the pool of possible key ranges
|
||||
* Gets a free (= not setInWork and not setSearched) KeyRange from the pool of possible key ranges
|
||||
*
|
||||
* @return A free KeyRange or null if none such exists
|
||||
*/
|
||||
|
@ -14,20 +13,17 @@ public interface KeyServer {
|
|||
/**
|
||||
* Sets a KeyRange as being currently worked on.
|
||||
*
|
||||
* As long as a KeyRange is not setSearched, there
|
||||
* is no guarantee that an inWork KeyRange will be finished
|
||||
* in any specific time frame.
|
||||
* The KeyServer has to clean up dangling inWorks in good
|
||||
* faith. Unexpected setSearched of already cleaned-up inWorks
|
||||
* must not be of any harm.
|
||||
* As long as a KeyRange is not setSearched, there is no guarantee that an inWork KeyRange will be
|
||||
* finished in any specific time frame. The KeyServer has to clean up dangling inWorks in good
|
||||
* faith. Unexpected setSearched of already cleaned-up inWorks must not be of any harm.
|
||||
*
|
||||
* @param keyRange The KeyRange to be set as being worked on, not null
|
||||
*/
|
||||
void setInWork(KeyRange keyRange);
|
||||
|
||||
/**
|
||||
* Sets a KeyRange as being searched, finalizing this range
|
||||
* A searched KeyRange need not be processed any more
|
||||
* Sets a KeyRange as being searched, finalizing this range A searched KeyRange need not be
|
||||
* processed any more
|
||||
*
|
||||
* @param keyRange The KeyRange to be set as searched, not null
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,8 @@ public class KTConcierge implements Runnable {
|
|||
}
|
||||
|
||||
private void recCheckInWork(KeyTree node) {
|
||||
if (node == null) return;
|
||||
if (node == null)
|
||||
return;
|
||||
|
||||
if (node.inWork()) {
|
||||
long inWorkSpan = System.currentTimeMillis() - node.inWorkSince();
|
||||
|
@ -33,7 +34,8 @@ public class KTConcierge implements Runnable {
|
|||
key.insert(0, parent.getValue() ? "1" : "0");
|
||||
parent = parent.getParent();
|
||||
}
|
||||
log.debug("{}: Retracting Work for key {}, inWorkSince: {}", System.currentTimeMillis(), key, node.inWorkSince());
|
||||
log.debug("{}: Retracting Work for key {}, inWorkSince: {}", System.currentTimeMillis(),
|
||||
key, node.inWorkSince());
|
||||
}
|
||||
node.clearInWork();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Random;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.btcollider.cnc.CnC;
|
||||
import org.btcollider.cnc.dto.KeyRange;
|
||||
import org.btcollider.cnc.keysrv.KeyServer;
|
||||
|
@ -29,7 +28,8 @@ public class KeyTreeServer implements KeyServer {
|
|||
this.index = index;
|
||||
this.root = generateKeyTree(depth);
|
||||
|
||||
if (pruneKey > 0) prune(pruneKey);
|
||||
if (pruneKey > 0)
|
||||
prune(pruneKey);
|
||||
|
||||
if (maxWorkSpan > 0) {
|
||||
log.info("Starting KeyTree concierge");
|
||||
|
@ -40,6 +40,7 @@ public class KeyTreeServer implements KeyServer {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyRange getRange() {
|
||||
BitSet keyStart = new BitSet(CnC.MAX_BITS);
|
||||
|
||||
|
@ -66,10 +67,12 @@ public class KeyTreeServer implements KeyServer {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSearched(KeyRange keyRange) {
|
||||
markSearched(BitSet.valueOf(new long[] {keyRange.getStart()}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInWork(KeyRange keyRange) {
|
||||
if (keyRange == null)
|
||||
return;
|
||||
|
@ -118,10 +121,8 @@ public class KeyTreeServer implements KeyServer {
|
|||
/**
|
||||
* Prunes every branch strictly smaller than pruneKey
|
||||
*
|
||||
* @param prune
|
||||
* The smallest valid key in the keyspace Must be at least as large
|
||||
* as the smallest key in the tree Must be at most as large as the
|
||||
* largest key in the tree
|
||||
* @param prune The smallest valid key in the keyspace Must be at least as large as the smallest
|
||||
* key in the tree Must be at most as large as the largest key in the tree
|
||||
*/
|
||||
private void prune(Long pruneKey) {
|
||||
BitSet pkBS = BitSet.valueOf(new long[] {pruneKey});
|
||||
|
@ -133,10 +134,12 @@ public class KeyTreeServer implements KeyServer {
|
|||
}
|
||||
|
||||
private void recPrune(BitSet pruneKey, KeyTree node, int curIdx) {
|
||||
if (node.getValue() && !pruneKey.get(curIdx)) { // node[ix] = 0 and pruneK[ix] = 1 -> path smaller
|
||||
if (node.getValue() && !pruneKey.get(curIdx)) { // node[ix] = 0 and pruneK[ix] = 1 -> path
|
||||
// smaller
|
||||
node.setSearched(true);
|
||||
return;
|
||||
} else if (!node.getValue() && pruneKey.get(curIdx)) { // node[ix] = 1 and pruneK[ix] = 0 -> path
|
||||
} else if (!node.getValue() && pruneKey.get(curIdx)) { // node[ix] = 1 and pruneK[ix] = 0 ->
|
||||
// path
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,18 +2,16 @@ package org.btcollider.cnc.keysrv.impl.multistage;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.btcollider.cnc.dto.KeyRange;
|
||||
|
||||
/**
|
||||
* The MultiStagedServer may switch partitions while there are still KeyRanges
|
||||
* from the old partition that are currently worked on.
|
||||
* The MultiStagedServer may switch partitions while there are still KeyRanges from the old
|
||||
* partition that are currently worked on.
|
||||
*
|
||||
* This buffer stores the state of unfinished KeyRanges from old partitions in
|
||||
* order to handle them correctly.
|
||||
* This buffer stores the state of unfinished KeyRanges from old partitions in order to handle them
|
||||
* correctly.
|
||||
*
|
||||
* Aborted KeyRanges from this Buffer should be always preferred to getting new
|
||||
* ranges.
|
||||
* Aborted KeyRanges from this Buffer should be always preferred to getting new ranges.
|
||||
*
|
||||
* @author armin
|
||||
*/
|
||||
|
|
|
@ -7,8 +7,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Not entirely random KeyServer that handles very large trees in multiple stages
|
||||
* to reduce memory and processing time consumption
|
||||
* Not entirely random KeyServer that handles very large trees in multiple stages to reduce memory
|
||||
* and processing time consumption
|
||||
*
|
||||
* @author armin
|
||||
*
|
||||
|
@ -47,7 +47,8 @@ public class MultiStagedServer implements KeyServer {
|
|||
|
||||
@Override
|
||||
public KeyRange getRange() {
|
||||
if (partition == null) return null; // We are finished searching the whole space
|
||||
if (partition == null)
|
||||
return null; // We are finished searching the whole space
|
||||
|
||||
KeyRange kr = null;
|
||||
|
||||
|
|
Loading…
Reference in a new issue