org.springframework.aop.target
Class HotSwappableTargetSource

java.lang.Object
  extended by org.springframework.aop.target.HotSwappableTargetSource
All Implemented Interfaces:
Serializable, TargetSource

public class HotSwappableTargetSource
extends Object
implements TargetSource, Serializable

Implementation of TargetSource interface 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
See Also:
Serialized Form

Constructor Summary
HotSwappableTargetSource(Object initialTarget)
          Create a new HotSwappableTargetSource with the given initial target object.
 
Method Summary
 boolean equals(Object other)
          Two HotSwappableTargetSources are equal if the targets are equal.
 Object getTarget()
          Synchronization around something that takes so little time is fine.
 Class getTargetClass()
          Return the type of targets returned by this TargetSource.
 int hashCode()
           
 boolean isStatic()
          Will all calls to getTarget() return the same object?
 void releaseTarget(Object o)
          Release the given target object obtained from the getTarget() method.
 Object swap(Object newTarget)
          Swap the target, returning the old target.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

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()
Description copied from interface: TargetSource
Return the type of targets returned by this TargetSource. Can return null, although certain usages of a TargetSource might just work with a predetermined target class.

Specified by:
getTargetClass in interface TargetSource

isStatic

public final boolean isStatic()
Description copied from interface: TargetSource
Will all calls to getTarget() return the same object? In that case, there will be no need to invoke releaseTarget, and the AOP framework can cache the return value of getTarget().

Specified by:
isStatic in interface TargetSource
Returns:
whether the target is immutable
See Also:
TargetSource.getTarget()

getTarget

public Object getTarget()
Synchronization around something that takes so little time is fine.

Specified by:
getTarget in interface TargetSource
Returns:
the target object, whicch contains the joinpoint

releaseTarget

public void releaseTarget(Object o)
Description copied from interface: TargetSource
Release the given target object obtained from the getTarget() method.

Specified by:
releaseTarget in interface TargetSource
Parameters:
o - object obtained from a call to getTarget()
See Also:
TargetSource.getTarget()

swap

public Object swap(Object newTarget)
            throws IllegalArgumentException
Swap the target, returning the old target.

Parameters:
newTarget - new target
Returns:
the old target
Throws:
IllegalArgumentException - if the new target is invalid

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object other)
Two HotSwappableTargetSources are equal if the targets are equal.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright (c) 2002-2006 The Spring Framework Project.