Class HotSwappableTargetSource

All Implemented Interfaces:
Serializable, TargetClassAware, TargetSource

public class HotSwappableTargetSource extends Object implements TargetSource, 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.

Rod Johnson, Juergen Hoeller
See Also:
  • Constructor Details

    • HotSwappableTargetSource

      public HotSwappableTargetSource(Object initialTarget)
      Create a new HotSwappableTargetSource with the given initial target object.
      initialTarget - the initial target object
  • Method Details

    • 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:
      getTargetClass in interface TargetClassAware
      Specified by:
      getTargetClass in interface TargetSource
      the type of targets returned by this TargetSource
    • getTarget

      public 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
      the target object which contains the joinpoint, or null if there is no actual target instance
    • swap

      public Object swap(Object newTarget) throws IllegalArgumentException
      Swap the target, returning the old target object.
      newTarget - the new target object
      the old target object
      IllegalArgumentException - if the new target is invalid
    • equals

      public boolean equals(@Nullable Object other)
      Two HotSwappableTargetSources are equal if the current target objects are equal.
      equals in class Object
    • hashCode

      public int hashCode()
      hashCode in class Object
    • toString

      public String toString()
      toString in class Object