private static FenceMethodWithArg createFenceMethod( Configuration conf, String clazzName, String arg) throws BadFencingConfigurationException { Class<?> clazz; try { // See if it's a short name for one of the built-in methods clazz = STANDARD_METHODS.get(clazzName); if (clazz == null) { // Try to instantiate the user's custom method clazz = Class.forName(clazzName); } } catch (Exception e) { throw new BadFencingConfigurationException( "Could not find configured fencing method " + clazzName, e); } // Check that it implements the right interface if (!FenceMethod.class.isAssignableFrom(clazz)) { throw new BadFencingConfigurationException( "Class " + clazzName + " does not implement FenceMethod"); } FenceMethod method = (FenceMethod) ReflectionUtils.newInstance(clazz, conf); method.checkArgs(arg); return new FenceMethodWithArg(method, arg); }
@Override public String toString() { return method.getClass().getCanonicalName() + "(" + arg + ")"; }