Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first commit

  • Loading branch information...
commit b46f12f01fde88212b12beede8ffd4fcc178deaf 0 parents
Jake Luciani authored

Showing 2 changed files with 48 additions and 0 deletions. Show diff stats Hide diff stats

  1. +11 0 README
  2. +37 0 TokenCalulator.java
11 README
... ... @@ -0,0 +1,11 @@
  1 +Calculates a initial token for the random paritioner assuming a fixed cluster size.
  2 +
  3 +To run token calculator run:
  4 +
  5 +java TokenCalculator N M
  6 +
  7 +Where N: is the clockwise position of the token you wish to calculate. N starts at 0.
  8 +Where M: is the total number of nodes in the ring
  9 +
  10 +
  11 +
37 TokenCalulator.java
... ... @@ -0,0 +1,37 @@
  1 +
  2 +import java.math.BigInteger;
  3 +
  4 +public class TokenCalulator
  5 +{
  6 + public static void main(String[] args)
  7 + {
  8 + try
  9 + {
  10 + if (args.length == 0)
  11 + {
  12 + System.err.println("Usage: calculate_token.sh [node] [total]");
  13 + return;
  14 + }
  15 +
  16 + Integer node = Integer.valueOf(args[0]);
  17 + Integer total = Integer.valueOf(args[1]);
  18 +
  19 + if(node < 0 || total <= 0 || node >= total)
  20 + throw new RuntimeException("Invalid input: "+node+" "+total);
  21 +
  22 + BigInteger token = BigInteger.valueOf(node);
  23 + BigInteger pow = BigInteger.valueOf(2).pow(127).subtract(BigInteger.ONE);
  24 + token = token.multiply(pow).divide(BigInteger.valueOf(total));
  25 +
  26 + System.out.println("Token "+node+" of "+total+": "+token.abs().toString());
  27 +
  28 + return;
  29 + }
  30 + catch(Throwable t)
  31 + {
  32 + t.printStackTrace();
  33 + System.err.println("Usage: calculate_token.sh [node] [total]");
  34 + }
  35 +
  36 + }
  37 +}

0 comments on commit b46f12f

Please sign in to comment.
Something went wrong with that request. Please try again.