org.springframework.aop.target

Class HotSwappableTargetSource

  • java.lang.Object
    • org.springframework.aop.target.HotSwappableTargetSource
  • All Implemented Interfaces:
    java.io.Serializable, TargetClassAware, TargetSource


    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.

    Author:
    Rod Johnson, Juergen Hoeller
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      HotSwappableTargetSource(java.lang.Object initialTarget)
      Create a new HotSwappableTargetSource with the given initial target object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      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() 
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • HotSwappableTargetSource

        public HotSwappableTargetSource(java.lang.Object initialTarget)
        Create a new HotSwappableTargetSource with the given initial target object.
        Parameters:
        initialTarget - the initial target object
    • Method Detail

      • getTargetClass

        public java.lang.Class<?> getTargetClass()
        Return the type of the current target object.

        The returned type should usually be constant across all target objects.

        Specified by:
        getTargetClass in interface TargetClassAware
        Specified by:
        getTargetClass in interface TargetSource
        Returns:
        the type of targets returned by this TargetSource
      • getTarget

        public java.lang.Object 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 interface TargetSource
        Returns:
        the target object which contains the joinpoint, or null if there is no actual target instance
      • swap

        public java.lang.Object swap(java.lang.Object newTarget)
                              throws java.lang.IllegalArgumentException
        Swap the target, returning the old target object.
        Parameters:
        newTarget - the new target object
        Returns:
        the old target object
        Throws:
        java.lang.IllegalArgumentException - if the new target is invalid
      • equals

        public boolean equals(java.lang.Object other)
        Two HotSwappableTargetSources are equal if the current target objects are equal.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object