public final class EJBClient extends Object
Modifier and Type | Field and Description |
---|---|
static String |
CLUSTER_AFFINITY
A JNDI context key which, if defined, identifies that the proxy to be created should have affinity to the cluster.
|
static String |
DISABLE_AFFINITY_LEARNING
A JNDI context key which, if defined, disables learning in the case of an unspecified
CLUSTER_AFFINITY |
static String |
SOURCE_ADDRESS_KEY
An invocation context key which is set to the source socket address of the invocation request, if any.
|
Modifier and Type | Method and Description |
---|---|
static <T> T |
asynchronous(T proxy)
Get an asynchronous view of a proxy.
|
static void |
clearInvocationTimeout(Object proxy)
Clear the per-proxy invocation timeout, causing it to use the globally configured timeout.
|
static boolean |
compareAndSetStrongAffinity(Object proxy,
Affinity expectedAffinity,
Affinity newAffinity)
Compare and change the strong affinity of a proxy.
|
static void |
convertToStateful(Object proxy,
SessionID sessionID)
Convert a non-stateful proxy to be stateful.
|
static <T> T |
createProxy(EJBLocator<T> locator)
Create a new proxy for the remote object identified by the given locator.
|
static <T> StatefulEJBLocator<T> |
createSession(Affinity affinity,
Class<T> viewType,
String appName,
String moduleName,
String beanName)
Create a new EJB session.
|
static <T> StatefulEJBLocator<T> |
createSession(Affinity affinity,
Class<T> viewType,
String appName,
String moduleName,
String beanName,
String distinctName)
Create a new EJB session.
|
static <T> StatefulEJBLocator<T> |
createSession(Class<T> viewType,
String appName,
String moduleName,
String beanName)
Create a new EJB session.
|
static <T> StatefulEJBLocator<T> |
createSession(Class<T> viewType,
String appName,
String moduleName,
String beanName,
String distinctName)
Create a new EJB session.
|
static <T> StatefulEJBLocator<T> |
createSession(StatelessEJBLocator<T> statelessLocator)
Create a new EJB session.
|
static <T> StatefulEJBLocator<T> |
createSession(URI uri,
Class<T> viewType,
String appName,
String moduleName,
String beanName)
Create a new EJB session.
|
static <T> StatefulEJBLocator<T> |
createSession(URI uri,
Class<T> viewType,
String appName,
String moduleName,
String beanName,
String distinctName)
Create a new EJB session.
|
static <T> T |
createSessionProxy(StatelessEJBLocator<T> statelessLocator)
Create a new EJB session proxy.
|
static Future<?> |
getFutureResult()
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> T |
getProxyAttachment(Object proxy,
AttachmentKey<T> attachmentKey)
Get a proxy attachment.
|
static Affinity |
getStrongAffinity(Object proxy)
Get the strong affinity of a proxy.
|
static UserTransaction |
getUserTransaction(String targetNodeName)
Deprecated.
|
static Affinity |
getWeakAffinity(Object proxy)
Get the current weak affinity of a proxy.
|
static <T> Object |
invoke(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> void |
invokeOneWay(T proxy,
EJBMethodLocator methodLocator,
Object... args)
Perform a one-way asynchronous invocation by method locator on a proxy.
|
static boolean |
isEJBProxy(Object object)
Determine whether an object is indeed a valid EJB proxy object created by this API.
|
static <T> T |
putProxyAttachment(Object proxy,
AttachmentKey<T> attachmentKey,
T newValue)
Set a proxy attachment.
|
static <T> T |
putProxyAttachmentIfAbsent(Object proxy,
AttachmentKey<T> attachmentKey,
T newValue)
Set a proxy attachment if it is not already set.
|
static <T> T |
removeProxyAttachment(Object proxy,
AttachmentKey<T> attachmentKey)
Remove a proxy attachment.
|
static <T> boolean |
removeProxyAttachment(Object proxy,
AttachmentKey<T> attachmentKey,
T oldValue)
Remove a proxy attachment with a particular value.
|
static <T> T |
replaceProxyAttachment(Object proxy,
AttachmentKey<T> attachmentKey,
T newValue)
Replace a proxy attachment if it is already present.
|
static <T> boolean |
replaceProxyAttachment(Object proxy,
AttachmentKey<T> attachmentKey,
T oldValue,
T newValue)
Replace a proxy attachment if it is already present.
|
static void |
setInvocationTimeout(Object proxy,
long timeout,
TimeUnit timeUnit)
Set a per-proxy invocation timeout.
|
static void |
setStrongAffinity(Object proxy,
Affinity newAffinity)
Change the strong affinity of a proxy.
|
static void |
setWeakAffinity(Object proxy,
Affinity newAffinity)
Change the weak affinity of a proxy.
|
static void |
transformStrongAffinity(Object proxy,
UnaryOperator<Affinity> transformOperator)
Transform the strong affinity of a proxy.
|
public static final String SOURCE_ADDRESS_KEY
SocketAddress
.public static final String CLUSTER_AFFINITY
public static final String DISABLE_AFFINITY_LEARNING
CLUSTER_AFFINITY
public static <T> T asynchronous(T proxy) throws IllegalArgumentException
void
method on the proxy will be invoked fully asynchronously
without a server round-trip delay. Any method which returns a Future
will
continue to be asynchronous. Any other method invoked on the returned proxy will return null
(the future
result can be acquired by wrapping the remote call with getFutureResult(Object)
or by using getFutureResult()
).
If an asynchronous view is passed in, the same view is returned.T
- the proxy typeproxy
- the proxy interface instanceIllegalArgumentException
- if the given object is not a valid proxypublic static <T> Future<T> getFutureResult(T operation) throws IllegalStateException
asynchronous(Object)
.T
- the result typeoperation
- the operationIllegalStateException
- if the operation is not appropriately givenpublic static Future<?> getFutureResult() throws IllegalStateException
asynchronous(Object)
.IllegalStateException
- if the operation is not appropriately givenpublic static <T> T createProxy(EJBLocator<T> locator) throws IllegalArgumentException
T
- the proxy typelocator
- the locatorIllegalArgumentException
- if the locator parameter is null
or is invalidpublic static boolean isEJBProxy(Object object)
object
- the object to testtrue
if it is an EJB proxy, false
otherwisepublic static <T> T createSessionProxy(StatelessEJBLocator<T> statelessLocator) throws Exception
T
- the view typestatelessLocator
- the stateless locator identifying the stateful EJBCreateException
- if an error occursException
public static <T> StatefulEJBLocator<T> createSession(Class<T> viewType, String appName, String moduleName, String beanName, String distinctName) throws Exception
T
- the view typeviewType
- the view type classappName
- the application namemoduleName
- the module namebeanName
- the EJB namedistinctName
- the module distinct nameCreateException
- if an error occursException
public static <T> StatefulEJBLocator<T> createSession(Affinity affinity, Class<T> viewType, String appName, String moduleName, String beanName, String distinctName) throws Exception
T
- the view typeaffinity
- the affinity specification for the sessionviewType
- the view type classappName
- the application namemoduleName
- the module namebeanName
- the EJB namedistinctName
- the module distinct nameCreateException
- if an error occursException
public static <T> StatefulEJBLocator<T> createSession(URI uri, Class<T> viewType, String appName, String moduleName, String beanName, String distinctName) throws Exception
T
- the view typeuri
- a URI at which EJBs may be obtainedviewType
- the view type classappName
- the application namemoduleName
- the module namebeanName
- the EJB namedistinctName
- the module distinct nameCreateException
- if an error occursException
public static <T> StatefulEJBLocator<T> createSession(Class<T> viewType, String appName, String moduleName, String beanName) throws Exception
T
- the view typeviewType
- the view type classappName
- the application namemoduleName
- the module namebeanName
- the EJB nameCreateException
- if an error occursException
public static <T> StatefulEJBLocator<T> createSession(Affinity affinity, Class<T> viewType, String appName, String moduleName, String beanName) throws Exception
T
- the view typeaffinity
- the affinity specification for the sessionviewType
- the view type classappName
- the application namemoduleName
- the module namebeanName
- the EJB nameCreateException
- if an error occursException
public static <T> StatefulEJBLocator<T> createSession(URI uri, Class<T> viewType, String appName, String moduleName, String beanName) throws Exception
T
- the view typeuri
- a URI at which EJBs may be obtainedviewType
- the view type classappName
- the application namemoduleName
- the module namebeanName
- the EJB nameCreateException
- if an error occursException
public static <T> StatefulEJBLocator<T> createSession(StatelessEJBLocator<T> statelessLocator) throws Exception
T
- the view typestatelessLocator
- the stateless locator identifying the stateful EJBCreateException
- if an error occursException
public static <T> void invokeOneWay(T proxy, EJBMethodLocator methodLocator, Object... args) throws Exception
T
- the view typeproxy
- the EJB proxymethodLocator
- the method locatorargs
- the invocation argumentsException
- if the invocation failed for some reasonpublic static <T> Future<?> invokeAsync(T proxy, EJBMethodLocator methodLocator, Object... args) throws Exception
T
- the view typeproxy
- the EJB proxymethodLocator
- the method locatorargs
- the invocation argumentsException
- if the invocation failed for some reasonpublic static <T> Object invoke(T proxy, EJBMethodLocator methodLocator, Object... args) throws Exception
T
- the view typeproxy
- the EJB proxymethodLocator
- the method locatorargs
- the invocation argumentsException
- if the invocation failed for some reasonpublic static <T> EJBLocator<? extends T> getLocatorFor(T proxy) throws IllegalArgumentException
T
- the proxy typeproxy
- the proxy (may not be null
)IllegalArgumentException
- if the given proxy is not a valid client proxy instancepublic static void setInvocationTimeout(Object proxy, long timeout, TimeUnit timeUnit) throws IllegalArgumentException
proxy
- the proxy to change (must not be null
, must be a valid EJB proxy)timeout
- the amount of time (must be greater than zero)timeUnit
- the time unit (must not be null
)IllegalArgumentException
- if the timeout is less than or equal to zero or a required parameter is
null
or invalidpublic static void clearInvocationTimeout(Object proxy) throws IllegalArgumentException
proxy
- the proxy to change (must not be null
, must be a valid EJB proxy)IllegalArgumentException
- if the proxy is null
or is not validpublic static void setStrongAffinity(Object proxy, Affinity newAffinity) throws IllegalArgumentException, SecurityException
getLocatorFor(Object)
for the given proxy will return the updated locator.proxy
- the proxy (may not be null
)newAffinity
- the new affinity (may not be null
)IllegalArgumentException
- if the given proxy is not a valid client proxy instanceSecurityException
- if a security manager is present and the caller does not have the changeStrongAffinity
EJBClientPermission
public static Affinity getStrongAffinity(Object proxy) throws IllegalArgumentException
getLocatorFor(proxy).getAffinity()
.proxy
- the proxy (may not be null
)IllegalArgumentException
- if the given proxy is not a valid client proxy instancepublic static boolean compareAndSetStrongAffinity(Object proxy, Affinity expectedAffinity, Affinity newAffinity) throws IllegalArgumentException, SecurityException
getLocatorFor(Object)
for the given proxy will return the updated locator. If the
affinity is not equal to the expected value, false
is returned and no change is made.proxy
- the proxy (may not be null
)newAffinity
- the new affinity (may not be null
)IllegalArgumentException
- if the given proxy is not a valid client proxy instanceSecurityException
- if a security manager is present and the caller does not have the changeStrongAffinity
EJBClientPermission
public static void transformStrongAffinity(Object proxy, UnaryOperator<Affinity> transformOperator) throws IllegalArgumentException, SecurityException
getLocatorFor(Object)
for the given proxy will return the updated locator.proxy
- the proxy (may not be null
)transformOperator
- the operator to apply to acquire the new affinity from the old one (may not be null
)IllegalArgumentException
- if the given proxy is not a valid client proxy instanceSecurityException
- if a security manager is present and the caller does not have the changeStrongAffinity
EJBClientPermission
public static void setWeakAffinity(Object proxy, Affinity newAffinity) throws IllegalArgumentException, SecurityException
proxy
- the proxy (may not be null
)newAffinity
- the new affinity (may not be null
)IllegalArgumentException
- if the given proxy is not a valid client proxy instanceSecurityException
- if a security manager is present and the caller does not have the changeWeakAffinity
EJBClientPermission
public static Affinity getWeakAffinity(Object proxy) throws IllegalArgumentException
proxy
- the proxy (must not be null
)null
)IllegalArgumentException
- if the given proxy is not a valid client proxy instancepublic static void convertToStateful(Object proxy, SessionID sessionID) throws IllegalArgumentException
getLocatorFor(Object)
for the given proxy will return the updated locator.proxy
- the proxy to convert (must not be null
)sessionID
- the session ID to use for the stateful locator (must not be null
)IllegalArgumentException
- if the given proxy is not a valid client proxy instance, or the proxy is already
stateful with a different session ID@Deprecated public static UserTransaction getUserTransaction(String targetNodeName)
UserTransaction
object instance which can be used to control transactions on a specific node.targetNodeName
- the node name (ignored)UserTransaction
instanceIllegalStateException
- if the transaction context isn't set or cannot provide a UserTransaction
instancepublic static <T> T getProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey) throws IllegalArgumentException
T
- the value typeproxy
- the proxy (must not be null
)attachmentKey
- the attachment key to use (must not be null
)null
if the attachment is not presentIllegalArgumentException
- if a required parameter is null
or if the object is not a valid EJB client proxypublic static <T> T putProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T newValue) throws IllegalArgumentException
T
- the value typeproxy
- the proxy (must not be null
)attachmentKey
- the attachment key to use (must not be null
)newValue
- the new value to set (must not be null
)null
if the attachment previously did not existIllegalArgumentException
- if a required parameter is null
or if the object is not a valid EJB client proxypublic static <T> T putProxyAttachmentIfAbsent(Object proxy, AttachmentKey<T> attachmentKey, T newValue) throws IllegalArgumentException
T
- the value typeproxy
- the proxy (must not be null
)attachmentKey
- the attachment key to use (must not be null
)newValue
- the new value to set (must not be null
)null
if the attachment previously did not existIllegalArgumentException
- if a required parameter is null
or if the object is not a valid EJB client proxypublic static <T> T removeProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey) throws IllegalArgumentException
T
- the value typeproxy
- the proxy (must not be null
)attachmentKey
- the attachment key to use (must not be null
)null
if the attachment previously did not existIllegalArgumentException
- if a required parameter is null
or if the object is not a valid EJB client proxypublic static <T> boolean removeProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T oldValue) throws IllegalArgumentException
T
- the value typeproxy
- the proxy (must not be null
)attachmentKey
- the attachment key to use (must not be null
)oldValue
- the new value to set (must not be null
)true
if the attachment was removed, or false
if the value did not match or was not presentIllegalArgumentException
- if a required parameter is null
or if the object is not a valid EJB client proxypublic static <T> T replaceProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T newValue) throws IllegalArgumentException
T
- the value typeproxy
- the proxy (must not be null
)attachmentKey
- the attachment key to use (must not be null
)newValue
- the new value to set (must not be null
)null
if the attachment previously did not existIllegalArgumentException
- if a required parameter is null
or if the object is not a valid EJB client proxypublic static <T> boolean replaceProxyAttachment(Object proxy, AttachmentKey<T> attachmentKey, T oldValue, T newValue) throws IllegalArgumentException
T
- the value typeproxy
- the proxy (must not be null
)attachmentKey
- the attachment key to use (must not be null
)newValue
- the old value to replace (must not be null
)true
if the attachment value was replaced, false
otherwiseIllegalArgumentException
- if a required parameter is null
or if the object is not a valid EJB client proxyCopyright © 2019 JBoss by Red Hat. All rights reserved.