private final Map<Integer, AdderBusinessLogic> state = new HashMap<>();
+ public void addNumber(
+ Integer partition,
+ String user,
+ MessageAddNumber message)
+ {
+ state.get(partition).addToSum(user, message.getNext());
+ }
+
+ public void calculateSum(
+ Integer partition,
+ String user,
+ MessageCalculateSum message)
+ {
+ AdderResult result = state.get(partition).calculate(user);
+ log.info("{} - New result for {}: {}", id, user, result);
+ results.addResults(partition, user, result);
+ }
+
@Override
public void accept(ConsumerRecord<String, Message> record)
{
switch(message.getType())
{
case ADD:
- MessageAddNumber addNumber = (MessageAddNumber)message;
- state.get(partition).addToSum(user, addNumber.getNext());
+ addNumber(partition, user, (MessageAddNumber) message);
break;
case CALC:
- AdderResult result = state.get(partition).calculate(user);
- log.info("{} - New result for {}: {}", id, user, result);
- results.addResults(partition, user, result);
+ calculateSum(partition, user, (MessageCalculateSum) message);
break;
}