Package org.jboss.ejb.client
Class EJBClient
java.lang.Object
org.jboss.ejb.client.EJBClient
The main Enterprise Beans client API class. This class contains helper methods which may be used to create proxies, open sessions,
and associate the current invocation context.
- Author:
- jpai, David M. Lloyd
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA JNDI context key which, if defined, identifies that the proxy to be created should have affinity to the cluster.static final StringA JNDI context key which, if defined, disables learning in the case of an unspecifiedCLUSTER_AFFINITYstatic final StringAn invocation context key which is set to the source socket address of the invocation request, if any. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tasynchronous(T proxy) Get an asynchronous view of a proxy.static voidclearInvocationTimeout(Object proxy) Clear the per-proxy invocation timeout, causing it to use the globally configured timeout.static booleancompareAndSetStrongAffinity(Object proxy, Affinity expectedAffinity, Affinity newAffinity) Compare and change the strong affinity of a proxy.static voidconvertToStateful(Object proxy, SessionID sessionID) Convert a non-stateful proxy to be stateful.static <T> TcreateProxy(EJBLocator<T> locator) Create a new proxy for the remote object identified by the given locator.static <T> StatefulEJBLocator<T>createSession(Class<T> viewType, String appName, String moduleName, String beanName) Create a new Enterprise Bean session.static <T> StatefulEJBLocator<T>createSession(Class<T> viewType, String appName, String moduleName, String beanName, String distinctName) Create a new Enterprise Bean session.static <T> StatefulEJBLocator<T>Create a new Enterprise Bean session.static <T> StatefulEJBLocator<T>createSession(URI uri, Class<T> viewType, String appName, String moduleName, String beanName, String distinctName) Create a new Enterprise Bean session.static <T> StatefulEJBLocator<T>createSession(Affinity affinity, Class<T> viewType, String appName, String moduleName, String beanName) Create a new Enterprise Bean session.static <T> StatefulEJBLocator<T>createSession(Affinity affinity, Class<T> viewType, String appName, String moduleName, String beanName, String distinctName) Create a new Enterprise Bean session.static <T> StatefulEJBLocator<T>createSession(StatelessEJBLocator<T> statelessLocator) Create a new Enterprise Bean session.static <T> TcreateSessionProxy(StatelessEJBLocator<T> statelessLocator) Create a new Enterprise Bean session proxy.static Future<?>Get the future result of an operation.static <T> Future<T>getFutureResult(T operation) Get the future result of an operation.static <T> EJBLocator<? extends T>getLocatorFor(T proxy) Get the locator for a proxy, if it has one.static <T> TgetProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey) Get a proxy attachment.static AffinitygetStrongAffinity(Object proxy) Get the strong affinity of a proxy.static jakarta.transaction.UserTransactiongetUserTransaction(String targetNodeName) Deprecated.static AffinitygetWeakAffinity(Object proxy) Get the current weak affinity of a proxy.static <T> Objectinvoke(T proxy, EJBMethodLocator methodLocator, Object... args) Perform an invocation by method locator on a proxy, returning the result.static <T> Future<?>invokeAsync(T proxy, EJBMethodLocator methodLocator, Object... args) Perform an asynchronous invocation by method locator on a proxy, returning the future result.static <T> voidinvokeOneWay(T proxy, EJBMethodLocator methodLocator, Object... args) Perform a one-way asynchronous invocation by method locator on a proxy.static booleanisEJBProxy(Object object) Determine whether an object is indeed a valid Enterprise Bean proxy object created by this API.static <T> TputProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T newValue) Set a proxy attachment.static <T> TputProxyAttachmentIfAbsent(Object proxy, AttachmentKey<T> attachmentKey, T newValue) Set a proxy attachment if it is not already set.static <T> TremoveProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey) Remove a proxy attachment.static <T> booleanremoveProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T oldValue) Remove a proxy attachment with a particular value.static <T> TreplaceProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T newValue) Replace a proxy attachment if it is already present.static <T> booleanreplaceProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T oldValue, T newValue) Replace a proxy attachment if it is already present.static voidsetInvocationTimeout(Object proxy, long timeout, TimeUnit timeUnit) Set a per-proxy invocation timeout.static voidsetStrongAffinity(Object proxy, Affinity newAffinity) Change the strong affinity of a proxy.static voidsetWeakAffinity(Object proxy, Affinity newAffinity) Change the weak affinity of a proxy.static voidtransformStrongAffinity(Object proxy, UnaryOperator<Affinity> transformOperator) Transform the strong affinity of a proxy.
-
Field Details
-
SOURCE_ADDRESS_KEY
An invocation context key which is set to the source socket address of the invocation request, if any. The value will be of typeSocketAddress.- See Also:
-
CLUSTER_AFFINITY
A JNDI context key which, if defined, identifies that the proxy to be created should have affinity to the cluster.- See Also:
-
DISABLE_AFFINITY_LEARNING
A JNDI context key which, if defined, disables learning in the case of an unspecifiedCLUSTER_AFFINITY- See Also:
-
-
Method Details
-
asynchronous
Get an asynchronous view of a proxy. Anyvoidmethod on the proxy will be invoked fully asynchronously without a server round-trip delay. Any method which returns aFuturewill continue to be asynchronous. Any other method invoked on the returned proxy will returnnull(the future result can be acquired by wrapping the remote call withgetFutureResult(Object)or by usinggetFutureResult()). If an asynchronous view is passed in, the same view is returned.- Type Parameters:
T- the proxy type- Parameters:
proxy- the proxy interface instance- Returns:
- the asynchronous view
- Throws:
IllegalArgumentException- if the given object is not a valid proxy
-
getFutureResult
Get the future result of an operation. Should be called in conjunction withasynchronous(Object).- Type Parameters:
T- the result type- Parameters:
operation- the operation- Returns:
- the future result
- Throws:
IllegalStateException- if the operation is not appropriately given
-
getFutureResult
Get the future result of an operation. Should be called in conjunction withasynchronous(Object).- Returns:
- the future result
- Throws:
IllegalStateException- if the operation is not appropriately given
-
createProxy
Create a new proxy for the remote object identified by the given locator.- Type Parameters:
T- the proxy type- Parameters:
locator- the locator- Returns:
- the new proxy
- Throws:
IllegalArgumentException- if the locator parameter isnullor is invalid
-
isEJBProxy
Determine whether an object is indeed a valid Enterprise Bean proxy object created by this API.- Parameters:
object- the object to test- Returns:
trueif it is an Enterprise Bean proxy,falseotherwise
-
createSessionProxy
Create a new Enterprise Bean session proxy. The returned proxy will be cluster-aware if a cluster affinity is used in the locator.- Type Parameters:
T- the view type- Parameters:
statelessLocator- the stateless locator identifying the stateful Enterprise Beans- Returns:
- the new Enterprise Beans locator
- Throws:
jakarta.ejb.CreateException- if an error occursException
-
createSession
public static <T> StatefulEJBLocator<T> createSession(Class<T> viewType, String appName, String moduleName, String beanName, String distinctName) throws Exception Create a new Enterprise Bean session.- Type Parameters:
T- the view type- Parameters:
viewType- the view type classappName- the application namemoduleName- the module namebeanName- the Enterprise Beans namedistinctName- the module distinct name- Returns:
- the new Enterprise Beans locator
- Throws:
jakarta.ejb.CreateException- if an error occursException
-
createSession
public static <T> StatefulEJBLocator<T> createSession(Affinity affinity, Class<T> viewType, String appName, String moduleName, String beanName, String distinctName) throws Exception Create a new Enterprise Bean session.- Type Parameters:
T- the view type- Parameters:
affinity- the affinity specification for the sessionviewType- the view type classappName- the application namemoduleName- the module namebeanName- the Enterprise Beans namedistinctName- the module distinct name- Returns:
- the new Enterprise Beans locator
- Throws:
jakarta.ejb.CreateException- if an error occursException
-
createSession
public static <T> StatefulEJBLocator<T> createSession(URI uri, Class<T> viewType, String appName, String moduleName, String beanName, String distinctName) throws Exception Create a new Enterprise Bean session.- Type Parameters:
T- the view type- Parameters:
uri- a URI at which Enterprise Beans may be obtainedviewType- the view type classappName- the application namemoduleName- the module namebeanName- the Enterprise Beans namedistinctName- the module distinct name- Returns:
- the new Enterprise Beans locator
- Throws:
jakarta.ejb.CreateException- if an error occursException
-
createSession
public static <T> StatefulEJBLocator<T> createSession(Class<T> viewType, String appName, String moduleName, String beanName) throws Exception Create a new Enterprise Bean session.- Type Parameters:
T- the view type- Parameters:
viewType- the view type classappName- the application namemoduleName- the module namebeanName- the Enterprise Beans name- Returns:
- the new Enterprise Beans locator
- Throws:
jakarta.ejb.CreateException- if an error occursException
-
createSession
public static <T> StatefulEJBLocator<T> createSession(Affinity affinity, Class<T> viewType, String appName, String moduleName, String beanName) throws Exception Create a new Enterprise Bean session.- Type Parameters:
T- the view type- Parameters:
affinity- the affinity specification for the sessionviewType- the view type classappName- the application namemoduleName- the module namebeanName- the Enterprise Beans name- Returns:
- the new Enterprise Beans locator
- Throws:
jakarta.ejb.CreateException- if an error occursException
-
createSession
public static <T> StatefulEJBLocator<T> createSession(URI uri, Class<T> viewType, String appName, String moduleName, String beanName) throws Exception Create a new Enterprise Bean session.- Type Parameters:
T- the view type- Parameters:
uri- a URI at which Enterprise Beans may be obtainedviewType- the view type classappName- the application namemoduleName- the module namebeanName- the Enterprise Beans name- Returns:
- the new Enterprise Beans locator
- Throws:
jakarta.ejb.CreateException- if an error occursException
-
createSession
public static <T> StatefulEJBLocator<T> createSession(StatelessEJBLocator<T> statelessLocator) throws Exception Create a new Enterprise Bean session.- Type Parameters:
T- the view type- Parameters:
statelessLocator- the stateless locator identifying the stateful Enterprise Beans- Returns:
- the new Enterprise Beans locator
- Throws:
jakarta.ejb.CreateException- if an error occursException
-
invokeOneWay
public static <T> void invokeOneWay(T proxy, EJBMethodLocator methodLocator, Object... args) throws Exception Perform a one-way asynchronous invocation by method locator on a proxy. Any return value is ignored.- Type Parameters:
T- the view type- Parameters:
proxy- the Enterprise Beans proxymethodLocator- the method locatorargs- the invocation arguments- Throws:
Exception- if the invocation failed for some reason
-
invokeAsync
public static <T> Future<?> invokeAsync(T proxy, EJBMethodLocator methodLocator, Object... args) throws Exception Perform an asynchronous invocation by method locator on a proxy, returning the future result.- Type Parameters:
T- the view type- Parameters:
proxy- the Enterprise Beans proxymethodLocator- the method locatorargs- the invocation arguments- Throws:
Exception- if the invocation failed for some reason
-
invoke
public static <T> Object invoke(T proxy, EJBMethodLocator methodLocator, Object... args) throws Exception Perform an invocation by method locator on a proxy, returning the result.- Type Parameters:
T- the view type- Parameters:
proxy- the Enterprise Beans proxymethodLocator- the method locatorargs- the invocation arguments- Throws:
Exception- if the invocation failed for some reason
-
getLocatorFor
Get the locator for a proxy, if it has one.- Type Parameters:
T- the proxy type- Parameters:
proxy- the proxy (may not benull)- Returns:
- the locator
- Throws:
IllegalArgumentException- if the given proxy is not a valid client proxy instance
-
setInvocationTimeout
public static void setInvocationTimeout(Object proxy, long timeout, TimeUnit timeUnit) throws IllegalArgumentException Set a per-proxy invocation timeout. This overrides the globally configured timeout.- Parameters:
proxy- the proxy to change (must not benull, must be a valid Enterprise Bean proxy)timeout- the amount of time (must be greater than zero)timeUnit- the time unit (must not benull)- Throws:
IllegalArgumentException- if the timeout is less than or equal to zero or a required parameter isnullor invalid
-
clearInvocationTimeout
Clear the per-proxy invocation timeout, causing it to use the globally configured timeout.- Parameters:
proxy- the proxy to change (must not benull, must be a valid Enterprise Bean proxy)- Throws:
IllegalArgumentException- if the proxy isnullor is not valid
-
setStrongAffinity
public static void setStrongAffinity(Object proxy, Affinity newAffinity) throws IllegalArgumentException, SecurityException Change the strong affinity of a proxy. All subsequent invocations against the proxy will use the new affinity. Subsequent calls togetLocatorFor(Object)for the given proxy will return the updated locator.- Parameters:
proxy- the proxy (may not benull)newAffinity- the new affinity (may not benull)- Throws:
IllegalArgumentException- if the given proxy is not a valid client proxy instanceSecurityException- if a security manager is present and the caller does not have thechangeStrongAffinityEJBClientPermission
-
getStrongAffinity
Get the strong affinity of a proxy. This is a shortcut forgetLocatorFor(proxy).getAffinity().- Parameters:
proxy- the proxy (may not benull)- Returns:
- the proxy strong affinity
- Throws:
IllegalArgumentException- if the given proxy is not a valid client proxy instance
-
compareAndSetStrongAffinity
public static boolean compareAndSetStrongAffinity(Object proxy, Affinity expectedAffinity, Affinity newAffinity) throws IllegalArgumentException, SecurityException Compare and change the strong affinity of a proxy. All subsequent invocations against the proxy will use the new affinity. Subsequent calls togetLocatorFor(Object)for the given proxy will return the updated locator. If the affinity is not equal to the expected value,falseis returned and no change is made.- Parameters:
proxy- the proxy (may not benull)newAffinity- the new affinity (may not benull)- Throws:
IllegalArgumentException- if the given proxy is not a valid client proxy instanceSecurityException- if a security manager is present and the caller does not have thechangeStrongAffinityEJBClientPermission
-
transformStrongAffinity
public static void transformStrongAffinity(Object proxy, UnaryOperator<Affinity> transformOperator) throws IllegalArgumentException, SecurityException Transform the strong affinity of a proxy. All subsequent invocations against the proxy will use the new affinity. Subsequent calls togetLocatorFor(Object)for the given proxy will return the updated locator.- Parameters:
proxy- the proxy (may not benull)transformOperator- the operator to apply to acquire the new affinity from the old one (may not benull)- Throws:
IllegalArgumentException- if the given proxy is not a valid client proxy instanceSecurityException- if a security manager is present and the caller does not have thechangeStrongAffinityEJBClientPermission
-
setWeakAffinity
public static void setWeakAffinity(Object proxy, Affinity newAffinity) throws IllegalArgumentException, SecurityException Change the weak affinity of a proxy. All subsequent invocations against the proxy will use the new affinity.- Parameters:
proxy- the proxy (may not benull)newAffinity- the new affinity (may not benull)- Throws:
IllegalArgumentException- if the given proxy is not a valid client proxy instanceSecurityException- if a security manager is present and the caller does not have thechangeWeakAffinityEJBClientPermission
-
getWeakAffinity
Get the current weak affinity of a proxy.- Parameters:
proxy- the proxy (must not benull)- Returns:
- the affinity (not
null) - Throws:
IllegalArgumentException- if the given proxy is not a valid client proxy instance
-
convertToStateful
public static void convertToStateful(Object proxy, SessionID sessionID) throws IllegalArgumentException 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 togetLocatorFor(Object)for the given proxy will return the updated locator.- Parameters:
proxy- the proxy to convert (must not benull)sessionID- the session ID to use for the stateful locator (must not benull)- Throws:
IllegalArgumentException- if the given proxy is not a valid client proxy instance, or the proxy is already stateful with a different session ID
-
getUserTransaction
@Deprecated public static jakarta.transaction.UserTransaction getUserTransaction(String targetNodeName) Deprecated.Get aUserTransactionobject instance which can be used to control transactions on a specific node.- Parameters:
targetNodeName- the node name (ignored)- Returns:
- the
UserTransactioninstance - Throws:
IllegalStateException- if the transaction context isn't set or cannot provide aUserTransactioninstance
-
getProxyAttachment
public static <T> T getProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey) throws IllegalArgumentException Get a proxy attachment.- Type Parameters:
T- the value type- Parameters:
proxy- the proxy (must not benull)attachmentKey- the attachment key to use (must not benull)- Returns:
- the attachment value or
nullif the attachment is not present - Throws:
IllegalArgumentException- if a required parameter isnullor if the object is not a valid EJB client proxy
-
putProxyAttachment
public static <T> T putProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T newValue) throws IllegalArgumentException Set a proxy attachment.- Type Parameters:
T- the value type- Parameters:
proxy- the proxy (must not benull)attachmentKey- the attachment key to use (must not benull)newValue- the new value to set (must not benull)- Returns:
- the previous attachment value or
nullif the attachment previously did not exist - Throws:
IllegalArgumentException- if a required parameter isnullor if the object is not a valid EJB client proxy
-
putProxyAttachmentIfAbsent
public static <T> T putProxyAttachmentIfAbsent(Object proxy, AttachmentKey<T> attachmentKey, T newValue) throws IllegalArgumentException Set a proxy attachment if it is not already set.- Type Parameters:
T- the value type- Parameters:
proxy- the proxy (must not benull)attachmentKey- the attachment key to use (must not benull)newValue- the new value to set (must not benull)- Returns:
- the previous attachment value or
nullif the attachment previously did not exist - Throws:
IllegalArgumentException- if a required parameter isnullor if the object is not a valid EJB client proxy
-
removeProxyAttachment
public static <T> T removeProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey) throws IllegalArgumentException Remove a proxy attachment.- Type Parameters:
T- the value type- Parameters:
proxy- the proxy (must not benull)attachmentKey- the attachment key to use (must not benull)- Returns:
- the previous attachment value or
nullif the attachment previously did not exist - Throws:
IllegalArgumentException- if a required parameter isnullor if the object is not a valid EJB client proxy
-
removeProxyAttachment
public static <T> boolean removeProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T oldValue) throws IllegalArgumentException Remove a proxy attachment with a particular value.- Type Parameters:
T- the value type- Parameters:
proxy- the proxy (must not benull)attachmentKey- the attachment key to use (must not benull)oldValue- the new value to set (must not benull)- Returns:
trueif the attachment was removed, orfalseif the value did not match or was not present- Throws:
IllegalArgumentException- if a required parameter isnullor if the object is not a valid EJB client proxy
-
replaceProxyAttachment
public static <T> T replaceProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T newValue) throws IllegalArgumentException Replace a proxy attachment if it is already present.- Type Parameters:
T- the value type- Parameters:
proxy- the proxy (must not benull)attachmentKey- the attachment key to use (must not benull)newValue- the new value to set (must not benull)- Returns:
- the previous attachment value or
nullif the attachment previously did not exist - Throws:
IllegalArgumentException- if a required parameter isnullor if the object is not a valid EJB client proxy
-
replaceProxyAttachment
public static <T> boolean replaceProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T oldValue, T newValue) throws IllegalArgumentException Replace a proxy attachment if it is already present.- Type Parameters:
T- the value type- Parameters:
proxy- the proxy (must not benull)attachmentKey- the attachment key to use (must not benull)newValue- the old value to replace (must not benull)- Returns:
trueif the attachment value was replaced,falseotherwise- Throws:
IllegalArgumentException- if a required parameter isnullor if the object is not a valid EJB client proxy
-