@Test public void shouldReplyAsynchronouslyToDeleteCustomer() throws Exception { service.deleteCustomer(DELETE_CUSTOMER_ID); replyTo(this).customerDeleted(); IN.release(); assertTrue(OUT.tryAcquire(1, SECONDS)); assertEquals(CALLBACK_MARKER, createdCustomerId); }
public static <T> T replyTo(final T target) { @SuppressWarnings("unchecked") Class<T> type = (Class<T>) target.getClass(); return new InvocationProxy<T>(type) { @Override public Object invoke(Method method, Object... args) { final Callback callback = CALL_INFO.get(); CALL_INFO.set(null); callback.invokeAndReplyTo(target, method); return null; } }.newInstance(); }
Callback { public static <T> T replyTo(final T target) { @SuppressWarnings("unchecked") Class<T> type = (Class<T>) target.getClass(); return new InvocationProxy<T>(type) { @Override public Object invoke(Method method, Object... args) { final Callback callback = CALL_INFO.get(); CALL_INFO.set(null); callback.invokeAndReplyTo(target, method); return null; } }.newInstance(); } }
Callback { public static <T> T replyTo(final T target) { @SuppressWarnings("unchecked") Class<T> type = (Class<T>) target.getClass(); return new InvocationProxy<T>(type) { @Override public Object invoke(Method method, Object... args) { final Callback callback = CALL_INFO.get(); CALL_INFO.set(null); callback.invokeAndReplyTo(target, method); return null; } }.newInstance(); } private  Callback(Object target, Method method, Object[] args); }
Callback { public static <T> T replyTo(final T target) { @SuppressWarnings("unchecked") Class<T> type = (Class<T>) target.getClass(); return new InvocationProxy<T>(type) { @Override public Object invoke(Method method, Object... args) { final Callback callback = CALL_INFO.get(); CALL_INFO.set(null); callback.invokeAndReplyTo(target, method); return null; } }.newInstance(); } private  Callback(Object target, Method method, Object[] args); static T forService(final T target); static T replyTo(final T target); static boolean hasCallbackInfo(); }
Callback { public static <T> T replyTo(final T target) { @SuppressWarnings("unchecked") Class<T> type = (Class<T>) target.getClass(); return new InvocationProxy<T>(type) { @Override public Object invoke(Method method, Object... args) { final Callback callback = CALL_INFO.get(); CALL_INFO.set(null); callback.invokeAndReplyTo(target, method); return null; } }.newInstance(); } private  Callback(Object target, Method method, Object[] args); static T forService(final T target); static T replyTo(final T target); static boolean hasCallbackInfo();  }