public class HotSwappableTargetSource extends java.lang.Object implements TargetSource, java.io.Serializable
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.
Constructor and Description |
---|
HotSwappableTargetSource(java.lang.Object initialTarget)
Create a new HotSwappableTargetSource with the given initial target object.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other)
Two HotSwappableTargetSources are equal if the current target
objects are equal.
|
java.lang.Object |
getTarget()
Return a target instance.
|
java.lang.Class<?> |
getTargetClass()
Return the type of the current target object.
|
int |
hashCode() |
boolean |
isStatic()
Will all calls to
TargetSource.getTarget() return the same object? |
void |
releaseTarget(java.lang.Object target)
Release the given target object obtained from the
TargetSource.getTarget() method, if any. |
java.lang.Object |
swap(java.lang.Object newTarget)
Swap the target, returning the old target object.
|
java.lang.String |
toString() |
public HotSwappableTargetSource(java.lang.Object initialTarget)
initialTarget
- the initial target objectpublic java.lang.Class<?> getTargetClass()
The returned type should usually be constant across all target objects.
getTargetClass
in interface TargetClassAware
getTargetClass
in interface TargetSource
TargetSource
public final boolean isStatic()
TargetSource
TargetSource.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 of TargetSource.getTarget()
.
isStatic
in interface TargetSource
true
if the target is immutableTargetSource.getTarget()
public java.lang.Object getTarget()
TargetSource
getTarget
in interface TargetSource
null
if there is no actual target instancepublic void releaseTarget(java.lang.Object target)
TargetSource
TargetSource.getTarget()
method, if any.releaseTarget
in interface TargetSource
target
- object obtained from a call to TargetSource.getTarget()
public java.lang.Object swap(java.lang.Object newTarget) throws java.lang.IllegalArgumentException
newTarget
- the new target objectjava.lang.IllegalArgumentException
- if the new target is invalidpublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object