Package org.springframework.aop.target
Class HotSwappableTargetSource
- java.lang.Object
- org.springframework.aop.target.HotSwappableTargetSource
- All Implemented Interfaces:
Serializable,TargetClassAware,TargetSource
public class HotSwappableTargetSource extends Object implements TargetSource, Serializable
TargetSourceimplementation that caches a local target object, but allows the target to be swapped while the application is running.If configuring an object of this class in a Spring IoC container, use constructor injection.
This TargetSource is serializable if the target is at the time of serialization.
- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
- Serialized Form
Constructor Summary
Constructors Constructor Description HotSwappableTargetSource(Object initialTarget)Create a new HotSwappableTargetSource with the given initial target object.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)Two HotSwappableTargetSources are equal if the current target objects are equal.ObjectgetTarget()Return a target instance.Class<?>getTargetClass()Return the type of the current target object.inthashCode()booleanisStatic()Will all calls toTargetSource.getTarget()return the same object?voidreleaseTarget(Object target)Release the given target object obtained from theTargetSource.getTarget()method, if any.Objectswap(Object newTarget)Swap the target, returning the old target object.StringtoString()
Constructor Detail
HotSwappableTargetSource
public HotSwappableTargetSource(Object initialTarget)
Create a new HotSwappableTargetSource with the given initial target object.- Parameters:
initialTarget- the initial target object
Method Detail
getTargetClass
public Class<?> getTargetClass()
Return the type of the current target object.The returned type should usually be constant across all target objects.
- Specified by:
getTargetClassin interfaceTargetClassAware- Specified by:
getTargetClassin interfaceTargetSource- Returns:
- the type of targets returned by this
TargetSource
isStatic
public final boolean isStatic()
Description copied from interface:TargetSourceWill all calls toTargetSource.getTarget()return the same object?In that case, there will be no need to invoke
TargetSource.releaseTarget(Object), and the AOP framework can cache the return value ofTargetSource.getTarget().- Specified by:
isStaticin interfaceTargetSource- Returns:
trueif the target is immutable- See Also:
TargetSource.getTarget()
getTarget
public 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 target)
Description copied from interface:TargetSourceRelease the given target object obtained from theTargetSource.getTarget()method, if any.- Specified by:
releaseTargetin interfaceTargetSource- Parameters:
target- object obtained from a call toTargetSource.getTarget()
swap
public Object swap(Object newTarget) throws IllegalArgumentException
Swap the target, returning the old target object.- Parameters:
newTarget- the new target object- Returns:
- the old target object
- Throws:
IllegalArgumentException- if the new target is invalid
equals
public boolean equals(Object other)
Two HotSwappableTargetSources are equal if the current target objects are equal.