示例#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
  private static final StoreManager getStorageManager(Configuration storageConfig) {
    String clazzname =
        storageConfig.getString(
            GraphDatabaseConfiguration.STORAGE_BACKEND_KEY,
            GraphDatabaseConfiguration.STORAGE_BACKEND_DEFAULT);
    if (preregisteredStorageManagers.containsKey(clazzname.toLowerCase())) {
      clazzname = preregisteredStorageManagers.get(clazzname.toLowerCase()).getCanonicalName();
    }

    try {
      Class clazz = Class.forName(clazzname);
      Constructor constructor = clazz.getConstructor(Configuration.class);
      StoreManager storage = (StoreManager) constructor.newInstance(storageConfig);
      return storage;
    } catch (ClassNotFoundException e) {
      throw new IllegalArgumentException("Could not find storage manager class" + clazzname);
    } catch (NoSuchMethodException e) {
      throw new IllegalArgumentException(
          "Configured storage manager does not have required constructor: " + clazzname);
    } catch (InstantiationException e) {
      throw new IllegalArgumentException(
          "Could not instantiate storage manager class " + clazzname, e);
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException(
          "Could not instantiate storage manager class " + clazzname, e);
    } catch (InvocationTargetException e) {
      throw new IllegalArgumentException(
          "Could not instantiate storage manager class " + clazzname, e);
    } catch (ClassCastException e) {
      throw new IllegalArgumentException(
          "Could not instantiate storage manager class " + clazzname, e);
    }
  }
示例#3
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);
    }
  }