Package org.springframework.aop.target
Class HotSwappableTargetSource
java.lang.Object
org.springframework.aop.target.HotSwappableTargetSource
- All Implemented Interfaces:
Serializable
,TargetClassAware
,TargetSource
TargetSource
implementation 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:
-
Constructor Summary
ConstructorDescriptionHotSwappableTargetSource
(Object initialTarget) Create a new HotSwappableTargetSource with the given initial target object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Two HotSwappableTargetSources are equal if the current target objects are equal.Return a target instance.Class<?>
Return the type of the current target object.int
hashCode()
final boolean
isStatic()
Will all calls toTargetSource.getTarget()
return the same object?void
releaseTarget
(Object target) Release the given target object obtained from theTargetSource.getTarget()
method, if any.Swap the target, returning the old target object.toString()
-
Constructor Details
-
HotSwappableTargetSource
Create a new HotSwappableTargetSource with the given initial target object.- Parameters:
initialTarget
- the initial target object
-
-
Method Details
-
getTargetClass
Return the type of the current target object.The returned type should usually be constant across all target objects.
- Specified by:
getTargetClass
in interfaceTargetClassAware
- Specified by:
getTargetClass
in interfaceTargetSource
- Returns:
- the type of targets returned by this
TargetSource
-
isStatic
public final boolean isStatic()Description copied from interface:TargetSource
Will 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:
isStatic
in interfaceTargetSource
- Returns:
true
if the target is immutable- See Also:
-
getTarget
Description copied from interface:TargetSource
Return a target instance. Invoked immediately before the AOP framework calls the "target" of an AOP method invocation.- Specified by:
getTarget
in interfaceTargetSource
- Returns:
- the target object which contains the joinpoint,
or
null
if there is no actual target instance
-
releaseTarget
Description copied from interface:TargetSource
Release the given target object obtained from theTargetSource.getTarget()
method, if any.- Specified by:
releaseTarget
in interfaceTargetSource
- Parameters:
target
- object obtained from a call toTargetSource.getTarget()
-
swap
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
Two HotSwappableTargetSources are equal if the current target objects are equal. -
hashCode
public int hashCode() -
toString
-