/** * Get the current weak affinity of a proxy. * * @param proxy the proxy (must not be {@code null}) * @return the affinity (not {@code null}) * @throws IllegalArgumentException if the given proxy is not a valid client proxy instance */ public static Affinity getWeakAffinity(Object proxy) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); return EJBInvocationHandler.forProxy(proxy).getWeakAffinity(); }
/** * Get the locator for a proxy, if it has one. * * @param proxy the proxy (may not be {@code null}) * @param <T> the proxy type * @return the locator * @throws IllegalArgumentException if the given proxy is not a valid client proxy instance */ public static <T> EJBLocator<? extends T> getLocatorFor(T proxy) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); return EJBInvocationHandler.forProxy(proxy).getLocator(); }
/** * Clear the per-proxy invocation timeout, causing it to use the globally configured timeout. * * @param proxy the proxy to change (must not be {@code null}, must be a valid EJB proxy) * @throws IllegalArgumentException if the proxy is {@code null} or is not valid */ public static void clearInvocationTimeout(Object proxy) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); EJBInvocationHandler.forProxy(proxy).setInvocationTimeout(-1L); }
/** * Perform a one-way asynchronous invocation by method locator on a proxy. Any return value is ignored. * * @param proxy the EJB proxy * @param methodLocator the method locator * @param args the invocation arguments * @param <T> the view type * @throws Exception if the invocation failed for some reason */ public static <T> void invokeOneWay(T proxy, EJBMethodLocator methodLocator, Object... args) throws Exception { final EJBInvocationHandler<? extends T> invocationHandler = EJBInvocationHandler.forProxy(proxy); final EJBProxyInformation.ProxyMethodInfo proxyMethodInfo = invocationHandler.getProxyMethodInfo(methodLocator); invocationHandler.invoke(proxy, proxyMethodInfo, args); }
/** * Perform an asynchronous invocation by method locator on a proxy, returning the future result. * * @param proxy the EJB proxy * @param methodLocator the method locator * @param args the invocation arguments * @param <T> the view type * @throws Exception if the invocation failed for some reason */ public static <T> Future<?> invokeAsync(T proxy, EJBMethodLocator methodLocator, Object... args) throws Exception { final EJBInvocationHandler<? extends T> invocationHandler = EJBInvocationHandler.forProxy(proxy); final EJBProxyInformation.ProxyMethodInfo proxyMethodInfo = invocationHandler.getProxyMethodInfo(methodLocator); return (Future<?>) invocationHandler.invoke(proxy, proxyMethodInfo, args); }
/** * Perform an invocation by method locator on a proxy, returning the result. * * @param proxy the EJB proxy * @param methodLocator the method locator * @param args the invocation arguments * @param <T> the view type * @throws Exception if the invocation failed for some reason */ public static <T> Object invoke(T proxy, EJBMethodLocator methodLocator, Object... args) throws Exception { final EJBInvocationHandler<? extends T> invocationHandler = EJBInvocationHandler.forProxy(proxy); final EJBProxyInformation.ProxyMethodInfo proxyMethodInfo = invocationHandler.getProxyMethodInfo(methodLocator); return invocationHandler.invoke(proxy, proxyMethodInfo, args); }
/** * Change the strong affinity of a proxy. All subsequent invocations against the proxy will use the new affinity. * Subsequent calls to {@link #getLocatorFor(Object)} for the given proxy will return the updated locator. * * @param proxy the proxy (may not be {@code null}) * @param newAffinity the new affinity (may not be {@code null}) * @throws IllegalArgumentException if the given proxy is not a valid client proxy instance * @throws SecurityException if a security manager is present and the caller does not have the {@code changeStrongAffinity} {@link EJBClientPermission} */ public static void setStrongAffinity(Object proxy, Affinity newAffinity) throws IllegalArgumentException, SecurityException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("newAffinity", newAffinity); final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(EJBClientPermission.CHANGE_STRONG_AFFINITY); } EJBInvocationHandler.forProxy(proxy).setStrongAffinity(newAffinity); }
/** * Change the weak affinity of a proxy. All subsequent invocations against the proxy will use the new affinity. * * @param proxy the proxy (may not be {@code null}) * @param newAffinity the new affinity (may not be {@code null}) * @throws IllegalArgumentException if the given proxy is not a valid client proxy instance * @throws SecurityException if a security manager is present and the caller does not have the {@code changeWeakAffinity} {@link EJBClientPermission} */ public static void setWeakAffinity(Object proxy, Affinity newAffinity) throws IllegalArgumentException, SecurityException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("newAffinity", newAffinity); final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(EJBClientPermission.CHANGE_WEAK_AFFINITY); } EJBInvocationHandler.forProxy(proxy).setWeakAffinity(newAffinity); }
/** * Set a per-proxy invocation timeout. This overrides the globally configured timeout. * * @param proxy the proxy to change (must not be {@code null}, must be a valid EJB proxy) * @param timeout the amount of time (must be greater than zero) * @param timeUnit the time unit (must not be {@code null}) * @throws IllegalArgumentException if the timeout is less than or equal to zero or a required parameter is * {@code null} or invalid */ public static void setInvocationTimeout(Object proxy, long timeout, TimeUnit timeUnit) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); Assert.checkMinimumParameter("timeout", 1L, timeout); Assert.checkNotNullParam("timeUnit", timeUnit); EJBInvocationHandler.forProxy(proxy).setInvocationTimeout(Math.max(1L, timeUnit.toMillis(timeout))); }
/** * Get a proxy attachment. * * @param proxy the proxy (must not be {@code null}) * @param attachmentKey the attachment key to use (must not be {@code null}) * @param <T> the value type * @return the attachment value or {@code null} if the attachment is not present * @throws IllegalArgumentException if a required parameter is {@code null} or if the object is not a valid EJB client proxy */ public static <T> T getProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("attachmentKey", attachmentKey); return EJBInvocationHandler.forProxy(proxy).getAttachment(attachmentKey); }
/** * Remove a proxy attachment. * * @param proxy the proxy (must not be {@code null}) * @param attachmentKey the attachment key to use (must not be {@code null}) * @param <T> the value type * @return the previous attachment value or {@code null} if the attachment previously did not exist * @throws IllegalArgumentException if a required parameter is {@code null} or if the object is not a valid EJB client proxy */ public static <T> T removeProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("attachmentKey", attachmentKey); return EJBInvocationHandler.forProxy(proxy).removeAttachment(attachmentKey); }
/** * Convert a non-stateful proxy to be stateful. If the proxy was already stateful and the session ID matches, the * proxy is unchanged. If the proxy was otherwise already stateful, an exception is thrown. Subsequent calls to * {@link #getLocatorFor(Object)} for the given proxy will return the updated locator. * * @param proxy the proxy to convert (must not be {@code null}) * @param sessionID the session ID to use for the stateful locator (must not be {@code null}) * @throws IllegalArgumentException if the given proxy is not a valid client proxy instance, or the proxy is already * stateful with a different session ID */ public static void convertToStateful(Object proxy, SessionID sessionID) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("sessionID", sessionID); EJBInvocationHandler.forProxy(proxy).setSessionID(sessionID); }
/** * Replace a proxy attachment if it is already present. * * @param proxy the proxy (must not be {@code null}) * @param attachmentKey the attachment key to use (must not be {@code null}) * @param newValue the new value to set (must not be {@code null}) * @param <T> the value type * @return the previous attachment value or {@code null} if the attachment previously did not exist * @throws IllegalArgumentException if a required parameter is {@code null} or if the object is not a valid EJB client proxy */ public static <T> T replaceProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T newValue) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("attachmentKey", attachmentKey); Assert.checkNotNullParam("newValue", newValue); return EJBInvocationHandler.forProxy(proxy).replaceAttachment(attachmentKey, newValue); }
/** * Set a proxy attachment. * * @param proxy the proxy (must not be {@code null}) * @param attachmentKey the attachment key to use (must not be {@code null}) * @param newValue the new value to set (must not be {@code null}) * @param <T> the value type * @return the previous attachment value or {@code null} if the attachment previously did not exist * @throws IllegalArgumentException if a required parameter is {@code null} or if the object is not a valid EJB client proxy */ public static <T> T putProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T newValue) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("attachmentKey", attachmentKey); Assert.checkNotNullParam("newValue", newValue); return EJBInvocationHandler.forProxy(proxy).putAttachment(attachmentKey, newValue); }
/** * Set a proxy attachment if it is not already set. * * @param proxy the proxy (must not be {@code null}) * @param attachmentKey the attachment key to use (must not be {@code null}) * @param newValue the new value to set (must not be {@code null}) * @param <T> the value type * @return the previous attachment value or {@code null} if the attachment previously did not exist * @throws IllegalArgumentException if a required parameter is {@code null} or if the object is not a valid EJB client proxy */ public static <T> T putProxyAttachmentIfAbsent(Object proxy, AttachmentKey<T> attachmentKey, T newValue) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("attachmentKey", attachmentKey); Assert.checkNotNullParam("newValue", newValue); return EJBInvocationHandler.forProxy(proxy).putAttachmentIfAbsent(attachmentKey, newValue); }
/** * Remove a proxy attachment with a particular value. * * @param proxy the proxy (must not be {@code null}) * @param attachmentKey the attachment key to use (must not be {@code null}) * @param oldValue the new value to set (must not be {@code null}) * @param <T> the value type * @return {@code true} if the attachment was removed, or {@code false} if the value did not match or was not present * @throws IllegalArgumentException if a required parameter is {@code null} or if the object is not a valid EJB client proxy */ public static <T> boolean removeProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T oldValue) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("attachmentKey", attachmentKey); Assert.checkNotNullParam("oldValue", oldValue); return EJBInvocationHandler.forProxy(proxy).removeAttachment(attachmentKey, oldValue); }
/** * Compare and change the strong affinity of a proxy. All subsequent invocations against the proxy will use the new affinity. * Subsequent calls to {@link #getLocatorFor(Object)} for the given proxy will return the updated locator. If the * affinity is not equal to the expected value, {@code false} is returned and no change is made. * * @param proxy the proxy (may not be {@code null}) * @param newAffinity the new affinity (may not be {@code null}) * @throws IllegalArgumentException if the given proxy is not a valid client proxy instance * @throws SecurityException if a security manager is present and the caller does not have the {@code changeStrongAffinity} {@link EJBClientPermission} */ public static boolean compareAndSetStrongAffinity(Object proxy, Affinity expectedAffinity, Affinity newAffinity) throws IllegalArgumentException, SecurityException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("expectedAffinity", expectedAffinity); Assert.checkNotNullParam("newAffinity", newAffinity); final EJBInvocationHandler<?> invocationHandler = EJBInvocationHandler.forProxy(proxy); final Affinity existing = invocationHandler.getLocator().getAffinity(); if (! expectedAffinity.equals(existing)) { return false; } final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(EJBClientPermission.CHANGE_STRONG_AFFINITY); } return invocationHandler.compareAndSetStrongAffinity(expectedAffinity, newAffinity); }
/** * Replace a proxy attachment if it is already present. * * @param proxy the proxy (must not be {@code null}) * @param attachmentKey the attachment key to use (must not be {@code null}) * @param newValue the old value to replace (must not be {@code null}) * @param <T> the value type * @return {@code true} if the attachment value was replaced, {@code false} otherwise * @throws IllegalArgumentException if a required parameter is {@code null} or if the object is not a valid EJB client proxy */ public static <T> boolean replaceProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T oldValue, T newValue) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("attachmentKey", attachmentKey); Assert.checkNotNullParam("oldValue", oldValue); Assert.checkNotNullParam("newValue", newValue); return EJBInvocationHandler.forProxy(proxy).replaceAttachment(attachmentKey, oldValue, newValue); } }
Assert.checkNotNullParam("proxy", proxy); Assert.checkNotNullParam("transformOperator", transformOperator); final EJBInvocationHandler<?> invocationHandler = EJBInvocationHandler.forProxy(proxy); Affinity oldAffinity = invocationHandler.getLocator().getAffinity(); Affinity newAffinity = transformOperator.apply(oldAffinity);
/** * Clear the per-proxy invocation timeout, causing it to use the globally configured timeout. * * @param proxy the proxy to change (must not be {@code null}, must be a valid EJB proxy) * @throws IllegalArgumentException if the proxy is {@code null} or is not valid */ public static void clearInvocationTimeout(Object proxy) throws IllegalArgumentException { Assert.checkNotNullParam("proxy", proxy); EJBInvocationHandler.forProxy(proxy).setInvocationTimeout(-1L); }