Created
December 30, 2014 20:36
-
-
Save maxant/701b1186f0dcce2990a0 to your computer and use it in GitHub Desktop.
Partitioning the market and creating the router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Router partitionAndCreateRouter() { | |
Map<String, ActorRef> kids = new HashMap<>(); | |
java.util.List<Routee> routees = new ArrayList<Routee>(); | |
int chunk = Constants.PRODUCT_IDS.length / NUM_KIDS; | |
for (int i = 0, j = Constants.PRODUCT_IDS.length; i < j; i += chunk) { | |
String[] temparray = Arrays.copyOfRange(Constants.PRODUCT_IDS, i, i + chunk); | |
LOGGER.info("created engine for products " + temparray); | |
ActorRef actor = getContext().actorOf(Props.create(EngineActor.class)); | |
getContext().watch(actor); | |
routees.add(new ActorRefRoutee(actor)); | |
for (int k = 0; k < temparray.length; k++) { | |
LOGGER.debug("mapping productId '" + temparray[k] + "' to engine " + i); | |
kids.put(temparray[k], actor); | |
} | |
LOGGER.info("---started trading"); | |
actor.tell(EngineActor.RUN, ActorRef.noSender()); | |
} | |
Router router = new Router(new PartitioningRoutingLogic(kids), routees); | |
return router; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment