@Test public void test() { List<String> errors = new ArrayList<>(); Consumer<ExceptionInfo> eic = (ei) -> { String failstring = MessageFormat.format("In bus {0} from {1} at {2} error {3}", ei.getBus().getId(), ei.getConsumer(), ei.getMessage(), ei.getThrowable()); System.out.println(failstring); errors.add(failstring); }; MessageBus<String> one = MessageBuses.create("one", String.class, eic); one.accept("haha"); ValueHolder<String> holder = new ValueHolder<>(); try(Subscription subs = one.openSubscription(holder)) { Assert.assertNull(holder.getValue()); } one.subscribe(holder); one.subscribe(holder); try(Subscription subs = one.openSubscription(holder)) { String s = "test"; one.accept("trash"); one.accept(s); Assert.assertEquals(s, holder.getValue()); Assert.assertEquals(2, holder.getInvocations()); one.accept(null); Assert.assertNull(holder.getValue()); } one.accept("fail"); Assert.assertNull(holder.getValue()); one.unsubscribe(holder); Assert.assertEquals(3, holder.getInvocations()); if(!errors.isEmpty()) { fail(errors.toString()); } }
@SuppressWarnings("unchecked") public static <M> MessageBus<M> create(String id, Class<M> type) { return MessageBusImpl.<M, Subscriptions<M>>builder(type, MessageSubscriptionsWrapper::new).id(id).build(); }
MessageBuses { @SuppressWarnings("unchecked") public static <M> MessageBus<M> create(String id, Class<M> type) { return MessageBusImpl.<M, Subscriptions<M>>builder(type, MessageSubscriptionsWrapper::new).id(id).build(); } }
MessageBuses { @SuppressWarnings("unchecked") public static <M> MessageBus<M> create(String id, Class<M> type) { return MessageBusImpl.<M, Subscriptions<M>>builder(type, MessageSubscriptionsWrapper::new).id(id).build(); } private  MessageBuses(); }
MessageBuses { @SuppressWarnings("unchecked") public static <M> MessageBus<M> create(String id, Class<M> type) { return MessageBusImpl.<M, Subscriptions<M>>builder(type, MessageSubscriptionsWrapper::new).id(id).build(); } private  MessageBuses(); @SuppressWarnings("unchecked") static MessageBus<M> create(String id, Class<M> type); @SuppressWarnings("unchecked") static MessageBus<M> create(String id, Class<M> type, Consumer<ExceptionInfo> eh); @SuppressWarnings("unchecked") static MessageBus<M> createConditional(String id, Class<M> type, Function<M, K> keyExtractor, BiPredicate<K, K> predicate); }
MessageBuses { @SuppressWarnings("unchecked") public static <M> MessageBus<M> create(String id, Class<M> type) { return MessageBusImpl.<M, Subscriptions<M>>builder(type, MessageSubscriptionsWrapper::new).id(id).build(); } private  MessageBuses(); @SuppressWarnings("unchecked") static MessageBus<M> create(String id, Class<M> type); @SuppressWarnings("unchecked") static MessageBus<M> create(String id, Class<M> type, Consumer<ExceptionInfo> eh); @SuppressWarnings("unchecked") static MessageBus<M> createConditional(String id, Class<M> type, Function<M, K> keyExtractor, BiPredicate<K, K> predicate);  }