Class DataAccessor

  • All Implemented Interfaces:
    Installable

    public class DataAccessor
    extends java.lang.Object
    implements Installable
    A generic template for creating efficient reflection-free accessors onto Objects for interceptors, where no compile-time dependency on the Object's class can safely be taken (which is most or all of the time). This mechanism may make mocking the target objects harder in tests, because the inserted Accessor interface will also have its methods mocked. Test authors may prefer to construct real objects instead of mocks.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  DataAccessor.ExceptionSafety
      An Advice class to wrap generated methods in catch-all exception safety.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected DataAccessor​(net.bytebuddy.matcher.ElementMatcher<net.bytebuddy.description.type.TypeDescription> typeImplementingAccessor, net.bytebuddy.matcher.ElementMatcher<net.bytebuddy.description.type.TypeDescription> typesImplementingAccessMethods, java.lang.Class<?> accessor)
      Protected constructor for factory access
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static DataAccessor forClassNamed​(java.lang.String className, java.lang.Class<?> accessor)
      Factory method to create a DataAccessor which allows access to corresponding methods of the given exact class
      static DataAccessor forConcreteSubclassesOfInterface​(java.lang.String interfaceName, java.lang.Class<?> accessor)
      Factory method to create a DataAccessor which allows access to the corresponding methods of any concrete subclasses of the given interface
      net.bytebuddy.agent.builder.AgentBuilder install​(net.bytebuddy.agent.builder.AgentBuilder agentBuilder)
      Install the necessary hooks for this piece of DiSCo functionality.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DataAccessor

        protected DataAccessor​(net.bytebuddy.matcher.ElementMatcher<net.bytebuddy.description.type.TypeDescription> typeImplementingAccessor,
                               net.bytebuddy.matcher.ElementMatcher<net.bytebuddy.description.type.TypeDescription> typesImplementingAccessMethods,
                               java.lang.Class<?> accessor)
        Protected constructor for factory access
        Parameters:
        typeImplementingAccessor - ElementMatcher describing the class to implement the accessor, usually some lowest-common denominator base or interface
        accessor - Accessor interface declaring the methods to use for access
    • Method Detail

      • forClassNamed

        public static DataAccessor forClassNamed​(java.lang.String className,
                                                 java.lang.Class<?> accessor)
        Factory method to create a DataAccessor which allows access to corresponding methods of the given exact class
        Parameters:
        className - the exact className to project data access onto
        accessor - the accessor defining the access methods
        Returns:
        a constructed DataAccessor
      • forConcreteSubclassesOfInterface

        public static DataAccessor forConcreteSubclassesOfInterface​(java.lang.String interfaceName,
                                                                    java.lang.Class<?> accessor)
        Factory method to create a DataAccessor which allows access to the corresponding methods of any concrete subclasses of the given interface
        Parameters:
        interfaceName - the name of the interface, for which implementing classes will have access methods defined
        accessor - the accessor defining the access methods
        Returns:
        a constructed DataAccessor
      • install

        public net.bytebuddy.agent.builder.AgentBuilder install​(net.bytebuddy.agent.builder.AgentBuilder agentBuilder)
        Install the necessary hooks for this piece of DiSCo functionality.
        Specified by:
        install in interface Installable
        Parameters:
        agentBuilder - - an AgentBuilder to append instructions to
        Returns:
        - the same AgentBuilder instance, for continuation/chaining, or null to prevent installation of the agentBuilder, in case the Installable instance does not require this instrumentation to take place.