Beispiel #1
0
  public MethodInvoker getMethod(Class<?> clazz, String name, Class<?>[] parameters) {
    MethodDescriptor mDescriptor = new MethodDescriptor(name, clazz, parameters);
    MethodInvoker mInvoker = null;
    List<Method> acceptableMethods = null;
    LRUCache<MethodDescriptor, MethodInvoker> cache = cacheHolder.get();

    mInvoker = cache.get(mDescriptor);

    if (mInvoker == null) {
      acceptableMethods = getMethodsByNameAndLength(clazz, name, parameters.length);

      if (acceptableMethods.size() == 1) {
        mInvoker = MethodInvoker.buildInvoker(acceptableMethods.get(0), parameters);
      } else {
        mInvoker = getBestMethod(acceptableMethods, parameters);
      }

      if (mInvoker != null && mInvoker.getCost() != -1) {
        cache.put(mDescriptor, mInvoker);
      } else {
        String errorMessage =
            "Method " + name + "(" + Arrays.toString(parameters) + ") does not exist";
        logger.log(Level.WARNING, errorMessage);
        throw new Py4JException(errorMessage);
      }
    }

    return mInvoker;
  }
Beispiel #2
0
  private MethodInvoker getBestMethod(List<Method> acceptableMethods, Class<?>[] parameters) {
    MethodInvoker lowestCost = null;

    for (Method method : acceptableMethods) {
      MethodInvoker temp = MethodInvoker.buildInvoker(method, parameters);
      int cost = temp.getCost();
      if (cost == -1) {
        continue;
      } else if (cost == 0) {
        lowestCost = temp;
        break;
      } else if (lowestCost == null || cost < lowestCost.getCost()) {
        lowestCost = temp;
      }
    }

    return lowestCost;
  }
Beispiel #3
0
  private MethodInvoker getBestConstructor(
      List<Constructor<?>> acceptableConstructors, Class<?>[] parameters) {
    MethodInvoker lowestCost = null;

    for (Constructor<?> constructor : acceptableConstructors) {
      MethodInvoker temp = MethodInvoker.buildInvoker(constructor, parameters);
      int cost = temp.getCost();
      if (cost == -1) {
        continue;
      } else if (cost == 0) {
        lowestCost = temp;
        break;
      } else if (lowestCost == null || cost < lowestCost.getCost()) {
        lowestCost = temp;
      }
    }

    return lowestCost;
  }