Created
December 25, 2014 21:31
-
-
Save maxant/62bc726f1cc1e46cdaec to your computer and use it in GitHub Desktop.
Trading engine servlet based on actors
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
@WebServlet(urlPatterns = { "/sell2", "/buy2", "/result2" }) | |
public class TradingEngineServletWithActors extends HttpServlet { | |
private static final ActorSystem teSystem = ActorSystem.create("TradingEngines"); | |
private static final Map<String, ActorRef> kids = new HashMap<>(); | |
static { | |
int chunk = PRODUCT_IDS.length / NUM_KIDS; | |
for (int i = 0, j = PRODUCT_IDS.length; i < j; i += chunk) { | |
String[] temparray = Arrays.copyOfRange(PRODUCT_IDS, i, i + chunk); | |
LOGGER.info("created engine for products " + temparray); | |
ActorRef actor = teSystem.actorOf(Props.create(TradingEngineActor.class), "engine-" + i); | |
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(TradingEngineActor.RUN, ActorRef.noSender()); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment