public SignalHandlerDefaultWInvoke(Object target, Method method) {
    this.target = target;

    FastClass fastClass =
        FastClass.create(Thread.currentThread().getContextClassLoader(), target.getClass());
    fastMethod = fastClass.getMethod(method);
  }
Example #2
0
  public SimpleFieldAccessor(Field field, FastClass fastClass) {
    this.field = field;

    if (field == null || fastClass == null) {
      throw new IllegalArgumentException("Arguments can't be null");
    }

    field.setAccessible(true);

    // todo log if can't access getter or setter
    try {
      getter = fastClass.getMethod(ReflectionUtil.getFieldGetterName(field), new Class[] {});
    } catch (Throwable e) {
      // no operation
    }

    try {
      setter =
          fastClass.getMethod(
              ReflectionUtil.getFieldSetterName(field), new Class[] {field.getType()});
    } catch (Throwable e) {
      // no operation
    }
  }
Example #3
0
  /**
   * Return getter for the given method and CGLIB FastClass.
   *
   * @param method to return getter for
   * @param fastClass is the CGLIB fast classs to make FastMethod for
   * @param eventAdapterService factory for event beans and event types
   * @return property getter
   */
  public static EventPropertyGetter getGetter(
      Method method, FastClass fastClass, EventAdapterService eventAdapterService) {
    // Get CGLib fast method handle
    FastMethod fastMethod = null;
    try {
      if (fastClass != null) {
        fastMethod = fastClass.getMethod(method);
      }
    } catch (Throwable ex) {
      log.warn(
          ".getAccessors Unable to obtain CGLib fast method implementation, msg="
              + ex.getMessage());
    }

    // Construct the appropriate property getter CGLib or reflect
    EventPropertyGetter getter;
    if (fastMethod != null) {
      getter = new CGLibPropertyGetter(method, fastMethod, eventAdapterService);
    } else {
      getter = new ReflectionPropMethodGetter(method, eventAdapterService);
    }

    return getter;
  }
  private Object createServiceInterfaceProxy(
      String serviceInterfaceClassName,
      Map seiPortNameToFactoryMap,
      Map seiClassNameToFactoryMap,
      ClassLoader classLoader)
      throws NamingException {
    boolean initialize = (this.serviceConstructor == null);

    if (initialize) {
      Class serviceInterface;
      try {
        serviceInterface = classLoader.loadClass(serviceInterfaceClassName);
      } catch (ClassNotFoundException e) {
        throw (NamingException)
            new NamingException(
                    "Could not load service interface class " + serviceInterfaceClassName)
                .initCause(e);
      }

      // create method interceptors
      Callback callback = new ServiceMethodInterceptor(seiPortNameToFactoryMap);
      this.methodInterceptors = new Callback[] {NoOp.INSTANCE, callback};

      // create service class
      Enhancer enhancer = new Enhancer();
      enhancer.setClassLoader(classLoader);
      enhancer.setSuperclass(ServiceImpl.class);
      enhancer.setInterfaces(new Class[] {serviceInterface});
      enhancer.setCallbackFilter(new NoOverrideCallbackFilter(Service.class));
      enhancer.setCallbackTypes(new Class[] {NoOp.class, MethodInterceptor.class});
      enhancer.setUseFactory(false);
      enhancer.setUseCache(false);
      this.enhancedServiceClass = enhancer.createClass();

      // get constructor
      this.serviceConstructor =
          FastClass.create(this.enhancedServiceClass).getConstructor(SERVICE_CONSTRUCTOR_TYPES);
    }

    // associate the method interceptors with the generated service class on the current thread
    Enhancer.registerCallbacks(this.enhancedServiceClass, this.methodInterceptors);

    Object[] arguments = new Object[] {seiPortNameToFactoryMap, seiClassNameToFactoryMap};

    Object serviceInstance = null;

    try {
      serviceInstance = this.serviceConstructor.newInstance(arguments);
    } catch (InvocationTargetException e) {
      throw (NamingException)
          new NamingException("Could not construct service instance")
              .initCause(e.getTargetException());
    }

    if (initialize) {
      for (Iterator iterator = seiPortNameToFactoryMap.values().iterator(); iterator.hasNext(); ) {
        SeiFactoryImpl seiFactory = (SeiFactoryImpl) iterator.next();
        try {
          seiFactory.initialize(serviceInstance, classLoader);
        } catch (ClassNotFoundException e) {
          throw (NamingException)
              new NamingException("Could not load service interface class; " + e.getMessage())
                  .initCause(e);
        }
      }
    }

    return serviceInstance;
  }
Example #5
0
 public SimpleFieldAccessor(Field field) {
   this(field, FastClass.create(field.getDeclaringClass()));
 }
Example #6
0
  RecordDescriptor(Class<? extends Record> clazz) {
    super();
    if (clazz == null) throw new RecordDescriptorCreationExcetption();

    this.recordClass = FastClass.create(clazz);
  }