Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit b46f12f01fde88212b12beede8ffd4fcc178deaf 0 parents
@tjake authored
Showing with 48 additions and 0 deletions.
  1. +11 −0 README
  2. +37 −0 TokenCalulator.java
11 README
@@ -0,0 +1,11 @@
+Calculates a initial token for the random paritioner assuming a fixed cluster size.
+
+To run token calculator run:
+
+java TokenCalculator N M
+
+Where N: is the clockwise position of the token you wish to calculate. N starts at 0.
+Where M: is the total number of nodes in the ring
+
+
+
37 TokenCalulator.java
@@ -0,0 +1,37 @@
+
+import java.math.BigInteger;
+
+public class TokenCalulator
+{
+ public static void main(String[] args)
+ {
+ try
+ {
+ if (args.length == 0)
+ {
+ System.err.println("Usage: calculate_token.sh [node] [total]");
+ return;
+ }
+
+ Integer node = Integer.valueOf(args[0]);
+ Integer total = Integer.valueOf(args[1]);
+
+ if(node < 0 || total <= 0 || node >= total)
+ throw new RuntimeException("Invalid input: "+node+" "+total);
+
+ BigInteger token = BigInteger.valueOf(node);
+ BigInteger pow = BigInteger.valueOf(2).pow(127).subtract(BigInteger.ONE);
+ token = token.multiply(pow).divide(BigInteger.valueOf(total));
+
+ System.out.println("Token "+node+" of "+total+": "+token.abs().toString());
+
+ return;
+ }
+ catch(Throwable t)
+ {
+ t.printStackTrace();
+ System.err.println("Usage: calculate_token.sh [node] [total]");
+ }
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.