Class AbstractRefreshableTargetSource
- java.lang.Object
- org.springframework.aop.target.dynamic.AbstractRefreshableTargetSource
- All Implemented Interfaces:
Refreshable,TargetClassAware,TargetSource
- Direct Known Subclasses:
BeanFactoryRefreshableTargetSource
public abstract class AbstractRefreshableTargetSource extends Object implements TargetSource, Refreshable
AbstractTargetSourceimplementation that wraps a refreshable target object. Subclasses can determine whether a refresh is required, and need to provide fresh target objects.Implements the
Refreshableinterface in order to allow for explicit control over the refresh status.- Since:
- 2.0
- Author:
- Rod Johnson, Rob Harrop, Juergen Hoeller
- See Also:
requiresRefresh(),freshTarget()
Field Summary
Fields Modifier and Type Field Description protected LogloggerLogger available to subclassesprotected ObjecttargetObject
Constructor Summary
Constructors Constructor Description AbstractRefreshableTargetSource()
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract ObjectfreshTarget()Obtain a fresh target object.longgetLastRefreshTime()Return the last time an actual refresh happened (as timestamp).longgetRefreshCount()Return the number of actual refreshes since startup.ObjectgetTarget()Return a target instance.Class<?>getTargetClass()Return the type of targets returned by thisTargetSource.booleanisStatic()Not static.voidrefresh()Refresh the underlying target object.voidreleaseTarget(Object object)No need to release target.protected booleanrequiresRefresh()Determine whether a refresh is required.voidsetRefreshCheckDelay(long refreshCheckDelay)Set the delay between refresh checks, in milliseconds.
Field Detail
targetObject
protected Object targetObject
Constructor Detail
AbstractRefreshableTargetSource
public AbstractRefreshableTargetSource()
Method Detail
setRefreshCheckDelay
public void setRefreshCheckDelay(long refreshCheckDelay)
Set the delay between refresh checks, in milliseconds. Default is -1, indicating no refresh checks at all.Note that an actual refresh will only happen when
requiresRefresh()returnstrue.
getTargetClass
public Class<?> getTargetClass()
Description copied from interface:TargetSourceReturn the type of targets returned by thisTargetSource.Can return
null, although certain usages of aTargetSourcemight just work with a predetermined target class.- Specified by:
getTargetClassin interfaceTargetClassAware- Specified by:
getTargetClassin interfaceTargetSource- Returns:
- the type of targets returned by this
TargetSource
isStatic
public boolean isStatic()
Not static.- Specified by:
isStaticin interfaceTargetSource- Returns:
trueif the target is immutable- See Also:
TargetSource.getTarget()
getTarget
public final Object getTarget()
Description copied from interface:TargetSourceReturn a target instance. Invoked immediately before the AOP framework calls the "target" of an AOP method invocation.- Specified by:
getTargetin interfaceTargetSource- Returns:
- the target object which contains the joinpoint, or
nullif there is no actual target instance
releaseTarget
public void releaseTarget(Object object)
No need to release target.- Specified by:
releaseTargetin interfaceTargetSource- Parameters:
object- object obtained from a call toTargetSource.getTarget()
refresh
public final void refresh()
Description copied from interface:RefreshableRefresh the underlying target object.- Specified by:
refreshin interfaceRefreshable
getRefreshCount
public long getRefreshCount()
Description copied from interface:RefreshableReturn the number of actual refreshes since startup.- Specified by:
getRefreshCountin interfaceRefreshable
getLastRefreshTime
public long getLastRefreshTime()
Description copied from interface:RefreshableReturn the last time an actual refresh happened (as timestamp).- Specified by:
getLastRefreshTimein interfaceRefreshable
requiresRefresh
protected boolean requiresRefresh()
Determine whether a refresh is required. Invoked for each refresh check, after the refresh check delay has elapsed.The default implementation always returns
true, triggering a refresh every time the delay has elapsed. To be overridden by subclasses with an appropriate check of the underlying target resource.- Returns:
- whether a refresh is required
freshTarget
protected abstract Object freshTarget()
Obtain a fresh target object.Only invoked if a refresh check has found that a refresh is required (that is,
requiresRefresh()has returnedtrue).- Returns:
- the fresh target object