Пример #1
0
        @Override
        public Locker apply(String lockerName) {

          String expectedManagerName =
              "com.thinkaurelius.titan.diskstorage.cassandra.astyanax.AstyanaxStoreManager";
          String actualManagerName = storeManager.getClass().getCanonicalName();
          // Require AstyanaxStoreManager
          Preconditions.checkArgument(
              expectedManagerName.equals(actualManagerName),
              "Astyanax Recipe locker is only supported with the Astyanax storage backend (configured:"
                  + actualManagerName
                  + " != required:"
                  + expectedManagerName
                  + ")");

          try {
            Class<?> c = storeManager.getClass();
            Method method = c.getMethod("openLocker", String.class);
            Object o = method.invoke(storeManager, lockerName);
            return (Locker) o;
          } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException(
                "Could not find method when configuring locking with Astyanax Recipes");
          } catch (IllegalAccessException e) {
            throw new IllegalArgumentException(
                "Could not access method when configuring locking with Astyanax Recipes", e);
          } catch (InvocationTargetException e) {
            throw new IllegalArgumentException(
                "Could not invoke method when configuring locking with Astyanax Recipes", e);
          }
        }
Пример #2
0
  public static final <T> T instantiate(String clazzname, Object... constructorArgs) {

    try {
      Class clazz = Class.forName(clazzname);
      Constructor constructor = clazz.getConstructor(Configuration.class);
      T instance = (T) constructor.newInstance(constructorArgs);
      return instance;
    } catch (ClassNotFoundException e) {
      throw new IllegalArgumentException("Could not find implementation class: " + clazzname);
    } catch (NoSuchMethodException e) {
      throw new IllegalArgumentException(
          "Configured backend implementation does not have required constructor: " + clazzname);
    } catch (InstantiationException e) {
      throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
    } catch (InvocationTargetException e) {
      throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
    } catch (ClassCastException e) {
      throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
    }
  }