use of net.dempsy.messages.KeyedMessageWithType in project Dempsy by Dempsy.
the class KeyExtractor method extract.
public List<KeyedMessageWithType> extract(final Object toSend) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
final List<Object> messages = new ArrayList<Object>();
unwindMessages(toSend, messages);
final ArrayList<KeyedMessageWithType> ret = new ArrayList<>(messages.size());
for (final Object msg : messages) {
final Class<?> messageClass = msg.getClass();
final MessageTypeDetails[] extractors = cache.computeIfAbsent(messageClass, mc -> MessageUtils.getAllMessageTypeDetailsUsingAnnotationValues(mc, true).toArray(MessageTypeDetails[]::new));
final int numExtractors = extractors.length;
for (int i = 0; i < numExtractors; i++) {
final MessageTypeDetails mtd = extractors[i];
final Function<Object, Object> extractor = mtd.keyExtractorForThisType;
if (extractor == null)
throw new IllegalArgumentException("The message object " + msg.getClass().getSimpleName() + " doesn't seem to have a method annotated with " + MessageKey.class.getSimpleName() + " so there's no way to route this message");
final Object msgKeyValue = extractor.apply(msg);
ret.add(new KeyedMessageWithType(msgKeyValue, msg, mtd.messageType));
}
}
return ret;
}
use of net.dempsy.messages.KeyedMessageWithType in project Dempsy by Dempsy.
the class TestContainer method testMpThrowsDempsyException.
@Test
public void testMpThrowsDempsyException() throws Exception {
assertEquals(0, ((ClusterMetricGetters) container.statCollector).getMessageFailedCount());
assertEquals(0, ((ClusterMetricGetters) container.statCollector).getDispatchedMessageCount());
justThrowMe = new DempsyException("JustThrowMe!");
final KeyedMessageWithType kmwt = ke.extract(new MyMessage("YO")).get(0);
container.dispatch(kmwt, Operation.handle, true);
assertEquals(1, ((ClusterMetricGetters) container.statCollector).getMessageFailedCount());
assertEquals(1, ((ClusterMetricGetters) container.statCollector).getDispatchedMessageCount());
}
use of net.dempsy.messages.KeyedMessageWithType in project Dempsy by Dempsy.
the class TestContainer method testWrongTypeMessage.
@Test
public void testWrongTypeMessage() throws Exception {
assertEquals(0, ((ClusterMetricGetters) container.statCollector).getMessageFailedCount());
final KeyedMessageWithType kmwt = ke.extract(new MyMessage("YO")).get(0);
container.dispatch(new KeyedMessage(kmwt.key, new Object()), Operation.handle, true);
assertEquals(1, ((ClusterMetricGetters) container.statCollector).getMessageFailedCount());
}
use of net.dempsy.messages.KeyedMessageWithType in project Dempsy by Dempsy.
the class TestContainer method testMpThrowsException.
@Test
public void testMpThrowsException() throws Exception {
assertEquals(0, ((ClusterMetricGetters) container.statCollector).getMessageFailedCount());
assertEquals(0, ((ClusterMetricGetters) container.statCollector).getDispatchedMessageCount());
justThrowMe = new RuntimeException("JustThrowMe!");
final KeyedMessageWithType kmwt = ke.extract(new MyMessage("YO")).get(0);
container.dispatch(kmwt, Operation.handle, true);
assertEquals(1, ((ClusterMetricGetters) container.statCollector).getMessageFailedCount());
assertEquals(1, ((ClusterMetricGetters) container.statCollector).getDispatchedMessageCount());
}
use of net.dempsy.messages.KeyedMessageWithType in project Dempsy by Dempsy.
the class TestContainer method testMpActivationFails.
@Test
public void testMpActivationFails() throws Exception {
assertEquals(0, ((ClusterMetricGetters) container.statCollector).getMessageFailedCount());
assertEquals(0, ((ClusterMetricGetters) container.statCollector).getDispatchedMessageCount());
throwMeInActivation = new RuntimeException("JustThrowMeDAMMIT!");
final KeyedMessageWithType kmwt = ke.extract(new MyMessage("YO")).get(0);
container.dispatch(kmwt, Operation.handle, true);
assertEquals(1, ((ClusterMetricGetters) container.statCollector).getMessageFailedCount());
assertEquals(0, ((ClusterMetricGetters) container.statCollector).getDispatchedMessageCount());
}
Aggregations