org.springframework.ejb.access
abstract public class: AbstractSlsbInvokerInterceptor [javadoc |
source]
java.lang.Object
org.springframework.jndi.JndiAccessor
org.springframework.jndi.JndiLocatorSupport
org.springframework.jndi.JndiObjectLocator
org.springframework.ejb.access.AbstractSlsbInvokerInterceptor
All Implemented Interfaces:
org.aopalliance.intercept.MethodInterceptor, InitializingBean
Direct Known Subclasses:
SimpleRemoteStatelessSessionProxyFactoryBean, LocalSlsbInvokerInterceptor, SimpleRemoteSlsbInvokerInterceptor, LocalStatelessSessionProxyFactoryBean, AbstractRemoteSlsbInvokerInterceptor
Base class for AOP interceptors invoking local or remote Stateless Session Beans.
Designed for EJB 2.x, but works for EJB 3 Session Beans as well.
Such an interceptor must be the last interceptor in the advice chain.
In this case, there is no direct target object: The call is handled in a
special way, getting executed on an EJB instance retrieved via an EJB home.
- author:
Rod - Johnson
- author:
Juergen - Hoeller
| Method from org.springframework.ejb.access.AbstractSlsbInvokerInterceptor Detail: |
public void afterPropertiesSet() throws NamingException {
super.afterPropertiesSet();
if (this.lookupHomeOnStartup) {
// look up EJB home and create method
refreshHome();
}
}
Fetches EJB home on startup, if necessary. |
protected Object create() throws NamingException, InvocationTargetException {
try {
Object home = getHome();
Method createMethodToUse = this.createMethod;
if (createMethodToUse == null) {
createMethodToUse = getCreateMethod(home);
}
if (createMethodToUse == null) {
return home;
}
// Invoke create() method on EJB home object.
return createMethodToUse.invoke(home, (Object[]) null);
}
catch (IllegalAccessException ex) {
throw new EjbAccessException("Could not access EJB home create() method", ex);
}
}
Invoke the create() method on the cached EJB home object. |
protected Method getCreateMethod(Object home) throws EjbAccessException {
try {
// Cache the EJB create() method that must be declared on the home interface.
return home.getClass().getMethod("create", (Class[]) null);
}
catch (NoSuchMethodException ex) {
throw new EjbAccessException("EJB home [" + home + "] has no no-arg create() method");
}
}
Determine the create method of the given EJB home object. |
protected Object getHome() throws NamingException {
if (!this.cacheHome || (this.lookupHomeOnStartup && !isHomeRefreshable())) {
return (this.cachedHome != null ? this.cachedHome : lookup());
}
else {
synchronized (this.homeMonitor) {
if (this.cachedHome == null) {
this.cachedHome = lookup();
this.createMethod = getCreateMethod(this.cachedHome);
}
return this.cachedHome;
}
}
}
Return the EJB home object to use. Called for each invocation.
Default implementation returns the home created on initialization,
if any; else, it invokes lookup to get a new proxy for each invocation.
Can be overridden in subclasses, for example to cache a home object
for a given amount of time before recreating it, or to test the home
object whether it is still alive. |
protected boolean isHomeRefreshable() {
return false;
}
Return whether the cached EJB home object is potentially
subject to on-demand refreshing. Default is "false". |
protected void refreshHome() throws NamingException {
synchronized (this.homeMonitor) {
Object home = lookup();
if (this.cacheHome) {
this.cachedHome = home;
this.createMethod = getCreateMethod(home);
}
}
}
Refresh the cached home object, if applicable.
Also caches the create method on the home object. |
public void setCacheHome(boolean cacheHome) {
this.cacheHome = cacheHome;
}
Set whether to cache the EJB home object once it has been located.
Default is "true".
Can be turned off to allow for hot restart of the EJB server.
In this case, the EJB home object will be fetched for each invocation. |
public void setLookupHomeOnStartup(boolean lookupHomeOnStartup) {
this.lookupHomeOnStartup = lookupHomeOnStartup;
}
Set whether to look up the EJB home object on startup.
Default is "true".
Can be turned off to allow for late start of the EJB server.
In this case, the EJB home object will be fetched on first access. |