/** * Get an asynchronous view of a proxy. Any {@code void} method on the proxy will be invoked fully asynchronously * without a server round-trip delay. Any method which returns a {@link java.util.concurrent.Future Future} will * continue to be asynchronous. Any other method invoked on the returned proxy will return {@code null} (the future * result can be acquired by wrapping the remote call with {@link #getFutureResult(Object)} or by using {@link #getFutureResult()}). * If an asynchronous view is passed in, the same view is returned. * * @param proxy the proxy interface instance * @param <T> the proxy type * @return the asynchronous view * @throws IllegalArgumentException if the given object is not a valid proxy */ @SuppressWarnings("unchecked") public static <T> T asynchronous(final T proxy) throws IllegalArgumentException { final InvocationHandler invocationHandler = Proxy.getInvocationHandler(proxy); if (invocationHandler instanceof EJBInvocationHandler) { final EJBInvocationHandler<?> remoteInvocationHandler = (EJBInvocationHandler<?>) invocationHandler; // determine proxy "type", return existing instance if it's already async if (remoteInvocationHandler.isAsyncHandler()) { return proxy; } else { return (T) Proxy.newProxyInstance(proxy.getClass().getClassLoader(), proxy.getClass().getInterfaces(), remoteInvocationHandler.getAsyncHandler()); } } else { throw log.unknownProxy(proxy); } }
/** * Get an asynchronous view of a proxy. Any {@code void} method on the proxy will be invoked fully asynchronously * without a server round-trip delay. Any method which returns a {@link java.util.concurrent.Future Future} will * continue to be asynchronous. Any other method invoked on the returned proxy will return {@code null} (the future * result can be acquired by wrapping the remote call with {@link #getFutureResult(Object)} or by using {@link #getFutureResult()}). * If an asynchronous view is passed in, the same view is returned. * * @param proxy the proxy interface instance * @param <T> the proxy type * @return the asynchronous view * @throws IllegalArgumentException if the given object is not a valid proxy */ @SuppressWarnings("unchecked") public static <T> T asynchronous(final T proxy) throws IllegalArgumentException { final InvocationHandler invocationHandler = Proxy.getInvocationHandler(proxy); if (invocationHandler instanceof EJBInvocationHandler) { final EJBInvocationHandler<?> remoteInvocationHandler = (EJBInvocationHandler<?>) invocationHandler; // determine proxy "type", return existing instance if it's already async if (remoteInvocationHandler.isAsyncHandler()) { return proxy; } else { return (T) Proxy.newProxyInstance(proxy.getClass().getClassLoader(), proxy.getClass().getInterfaces(), remoteInvocationHandler.getAsyncHandler()); } } else { throw log.unknownProxy(proxy); } }
/** * Get an asynchronous view of a proxy. Any {@code void} method on the proxy will be invoked fully asynchronously * without a server round-trip delay. Any method which returns a {@link java.util.concurrent.Future Future} will * continue to be asynchronous. Any other method invoked on the returned proxy will return {@code null} (the future * result can be acquired by wrapping the remote call with {@link #getFutureResult(Object)} or by using {@link #getFutureResult()}). * If an asynchronous view is passed in, the same view is returned. * * @param proxy the proxy interface instance * @param <T> the proxy type * @return the asynchronous view * @throws IllegalArgumentException if the given object is not a valid proxy */ @SuppressWarnings("unchecked") public static <T> T asynchronous(final T proxy) throws IllegalArgumentException { final InvocationHandler invocationHandler = Proxy.getInvocationHandler(proxy); if (invocationHandler instanceof EJBInvocationHandler) { final EJBInvocationHandler<?> remoteInvocationHandler = (EJBInvocationHandler<?>) invocationHandler; // determine proxy "type", return existing instance if it's already async if (remoteInvocationHandler.isAsyncHandler()) { return proxy; } else { return (T) Proxy.newProxyInstance(proxy.getClass().getClassLoader(), proxy.getClass().getInterfaces(), remoteInvocationHandler.getAsyncHandler()); } } else { throw log.unknownProxy(proxy); } }