/** * Constructs a new custom authentication provider. * * @param providerName the name of the provider */ public CustomAuthenticationProvider(String providerName) { Class<?> customProviderClass; try { customProviderClass = Class.forName(providerName); } catch (ClassNotFoundException e) { throw new RuntimeException(providerName + " not found"); } mCustomProvider = (AuthenticationProvider) CommonUtils .createNewClassInstance(customProviderClass, null, null); }
/** * Factory method for {@link JournalFormatter}. * * @return the created formatter */ public static JournalFormatter create() { return CommonUtils.createNewClassInstance(ServerConfiguration .<JournalFormatter>getClass(PropertyKey.MASTER_JOURNAL_FORMATTER_CLASS), null, null); } }
/** * Factory for {@link DataServer}. * * @param dataAddress the address of the data server * @param worker the Alluxio worker handle * @return the generated {@link DataServer} */ public static DataServer create(final SocketAddress dataAddress, final WorkerProcess worker) { return CommonUtils.createNewClassInstance( ServerConfiguration.<DataServer>getClass(PropertyKey.WORKER_DATA_SERVER_CLASS), new Class[] {SocketAddress.class, WorkerProcess.class}, new Object[] {dataAddress, worker}); } }
/** * Creates a new instance of {@link AsyncPersistHandler}. * * @param view {@link FileSystemMasterView} to pass to {@link AsyncPersistHandler} * @return the generated {@link AsyncPersistHandler} */ public static AsyncPersistHandler create(FileSystemMasterView view) { return CommonUtils.createNewClassInstance( ServerConfiguration .<AsyncPersistHandler>getClass(PropertyKey.MASTER_FILE_ASYNC_PERSIST_HANDLER), new Class[] {FileSystemMasterView.class}, new Object[] {view}); } }
/** * Factory for {@link Allocator}. * * @param view {@link BlockMetadataManagerView} to pass to {@link Allocator} * @return the generated {@link Allocator}, it will be a {@link MaxFreeAllocator} by default */ public static Allocator create(BlockMetadataManagerView view) { BlockMetadataManagerView managerView = Preconditions.checkNotNull(view, "view"); return CommonUtils.createNewClassInstance( ServerConfiguration.<Allocator>getClass(PropertyKey.WORKER_ALLOCATOR_CLASS), new Class[] {BlockMetadataManagerView.class}, new Object[] {managerView}); } }
/** * Factory for {@link Evictor}. * * @param view {@link BlockMetadataManagerView} to pass to {@link Evictor} * @param allocator an allocation policy * @return the generated {@link Evictor} */ public static Evictor create(BlockMetadataManagerView view, Allocator allocator) { return CommonUtils.createNewClassInstance( ServerConfiguration.<Evictor>getClass(PropertyKey.WORKER_EVICTOR_CLASS), new Class[] {BlockMetadataManagerView.class, Allocator.class}, new Object[] {view, allocator}); } }
/** * Creates a {@link Runnable} to execute heartbeats for the given {@link HeartbeatExecutor}. * * This class is responsible for closing the given {@link HeartbeatExecutor} when it finishes. * * @param threadName identifies the heartbeat thread name * @param executor identifies the heartbeat thread executor; an instance of a class that * implements the HeartbeatExecutor interface * @param intervalMs Sleep time between different heartbeat * @param conf Alluxio configuration */ public HeartbeatThread(String threadName, HeartbeatExecutor executor, long intervalMs, AlluxioConfiguration conf) { mThreadName = threadName; mExecutor = Preconditions.checkNotNull(executor, "executor"); Class<? extends HeartbeatTimer> timerClass = HeartbeatContext.getTimerClass(threadName); mTimer = CommonUtils.createNewClassInstance(timerClass, new Class[] {String.class, long.class}, new Object[] {threadName, intervalMs}); mConfiguration = conf; }
/** * Factory for creating {@link BlockLocationPolicy}. * * @param options the block location policy creation options * @return a new instance of {@link BlockLocationPolicy} */ public static BlockLocationPolicy create(CreateOptions options, AlluxioConfiguration alluxioConf) { int numShards = options.getDeterministicHashPolicyNumShards(); try { Class<BlockLocationPolicy> clazz = (Class<BlockLocationPolicy>) Class.forName(options.getLocationPolicyClassName()); if (numShards > 1) { return CommonUtils.createNewClassInstance(clazz, new Class[] {Integer.class}, new Object[] {numShards}); } else { return CommonUtils.createNewClassInstance(clazz, new Class[] {AlluxioConfiguration.class}, new Object[] {alluxioConf}); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } }
/** * Get instances of all subclasses of {@link Command} in a sub-package called "command" the given * package. * * @param pkgName package prefix to look in * @param classArgs type of args to instantiate the class * @param objectArgs args to instantiate the class * @return a mapping from command name to command instance */ public static Map<String, Command> loadCommands(String pkgName, Class[] classArgs, Object[] objectArgs) { Map<String, Command> commandsMap = new HashMap<>(); Reflections reflections = new Reflections(Command.class.getPackage().getName()); for (Class<? extends Command> cls : reflections.getSubTypesOf(Command.class)) { // Add commands from <pkgName>.command.* if (cls.getPackage().getName().equals(pkgName + ".command") && !Modifier.isAbstract(cls.getModifiers())) { // Only instantiate a concrete class Command cmd = CommonUtils.createNewClassInstance(cls, classArgs, objectArgs); commandsMap.put(cmd.getCommandName(), cmd); } } return commandsMap; }
/** * Gets the cached groups mapping service being used to map user-to-groups. * * @return the groups mapping service being used to map user-to-groups */ public static GroupMappingService get(AlluxioConfiguration conf) { if (sCachedGroupMapping == null) { synchronized (Factory.class) { if (sCachedGroupMapping == null) { LOG.debug("Creating new Groups object"); GroupMappingService groupMappingService = CommonUtils.createNewClassInstance(conf.<GroupMappingService>getClass( PropertyKey.SECURITY_GROUP_MAPPING_CLASS), null, null); sCachedGroupMapping = new CachedGroupMapping(groupMappingService, conf.getMs(PropertyKey.SECURITY_GROUP_MAPPING_CACHE_TIMEOUT_MS)); } } } return sCachedGroupMapping; } }
/** * Tests the {@link CommonUtils#createNewClassInstance(Class, Class[], Object[])} method. */ @Test public void createNewClassInstance() { class TestCase { Class<?> mCls; Class<?>[] mCtorClassArgs; Object[] mCtorArgs; String mExpected; public TestCase(String expected, Class<?> cls, Class<?>[] ctorClassArgs, Object... ctorArgs) { mCls = cls; mCtorClassArgs = ctorClassArgs; mCtorArgs = ctorArgs; mExpected = expected; } } List<TestCase> testCases = new ArrayList<>(); testCases.add(new TestCase("hello", TestClassA.class, null)); testCases.add(new TestCase("1", TestClassB.class, new Class[] {int.class}, 1)); for (TestCase testCase : testCases) { Object o = CommonUtils.createNewClassInstance(testCase.mCls, testCase.mCtorClassArgs, testCase.mCtorArgs); assertEquals(o.toString(), testCase.mExpected); } }
private OutStreamOptions(AlluxioConfiguration alluxioConf) { mBlockSizeBytes = alluxioConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT); mTtl = Constants.NO_TTL; mTtlAction = TtlAction.DELETE; mLocationPolicy = CommonUtils.createNewClassInstance(alluxioConf.<FileWriteLocationPolicy>getClass( PropertyKey.USER_FILE_WRITE_LOCATION_POLICY), new Class[] {AlluxioConfiguration.class}, new Object[] {alluxioConf}); mWriteTier = alluxioConf.getInt(PropertyKey.USER_FILE_WRITE_TIER_DEFAULT); mWriteType = alluxioConf.getEnum(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class); mOwner = SecurityUtils.getOwnerFromLoginModule(alluxioConf); mGroup = SecurityUtils.getGroupFromLoginModule(alluxioConf); mMode = ModeUtils.applyFileUMask(Mode.defaults(), alluxioConf .get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); mMountId = IdUtils.INVALID_MOUNT_ID; mReplicationDurable = alluxioConf.getInt(PropertyKey.USER_FILE_REPLICATION_DURABLE); mReplicationMax = alluxioConf.getInt(PropertyKey.USER_FILE_REPLICATION_MAX); mReplicationMin = alluxioConf.getInt(PropertyKey.USER_FILE_REPLICATION_MIN); }
mLocationPolicy = (FileWriteLocationPolicy) CommonUtils.createNewClassInstance( Class.forName(options.getFileWriteLocationPolicy()), new Class[] {AlluxioConfiguration.class},
/** * Constructs a new custom authentication provider. * * @param providerName the name of the provider */ public CustomAuthenticationProvider(String providerName) { Class<?> customProviderClass; try { customProviderClass = Class.forName(providerName); } catch (ClassNotFoundException e) { throw new RuntimeException(providerName + " not found"); } mCustomProvider = (AuthenticationProvider) CommonUtils .createNewClassInstance(customProviderClass, null, null); }
/** * Factory method for {@link JournalFormatter}. * * @return the created formatter */ public static JournalFormatter create() { return CommonUtils.createNewClassInstance( Configuration.<JournalFormatter>getClass(PropertyKey.MASTER_JOURNAL_FORMATTER_CLASS), null, null); } }
/** * Creates a new instance of {@link AsyncPersistHandler}. * * @param view {@link FileSystemMasterView} to pass to {@link AsyncPersistHandler} * @return the generated {@link AsyncPersistHandler} */ public static AsyncPersistHandler create(FileSystemMasterView view) { return CommonUtils.createNewClassInstance( Configuration .<AsyncPersistHandler>getClass(PropertyKey.MASTER_FILE_ASYNC_PERSIST_HANDLER), new Class[] {FileSystemMasterView.class}, new Object[] {view}); } }
/** * @param lineageStoreView a view of the lineage store * @param fileSystemMasterView a view of the file system master * @return the generated planner */ public static CheckpointPlanner create(LineageStoreView lineageStoreView, FileSystemMasterView fileSystemMasterView) { return CommonUtils.createNewClassInstance( Configuration.<CheckpointPlanner>getClass(PropertyKey.MASTER_LINEAGE_CHECKPOINT_CLASS), new Class[] {LineageStoreView.class, FileSystemMasterView.class}, new Object[] {lineageStoreView, fileSystemMasterView}); } }
/** * Creates a {@link Runnable} to execute heartbeats for the given {@link HeartbeatExecutor}. * * This class is responsible for closing the given {@link HeartbeatExecutor} when it finishes. * * @param threadName identifies the heartbeat thread name * @param executor identifies the heartbeat thread executor; an instance of a class that * implements the HeartbeatExecutor interface * @param intervalMs Sleep time between different heartbeat */ public HeartbeatThread(String threadName, HeartbeatExecutor executor, long intervalMs) { mThreadName = threadName; mExecutor = Preconditions.checkNotNull(executor, "executor"); Class<? extends HeartbeatTimer> timerClass = HeartbeatContext.getTimerClass(threadName); mTimer = CommonUtils.createNewClassInstance(timerClass, new Class[] {String.class, long.class}, new Object[] {threadName, intervalMs}); }
private InStreamOptions() { mReadType = ClientContext.getConf().getEnum(Constants.USER_FILE_READ_TYPE_DEFAULT, ReadType.class); try { mLocationPolicy = CommonUtils.createNewClassInstance(ClientContext.getConf() .<FileWriteLocationPolicy>getClass(Constants.USER_FILE_WRITE_LOCATION_POLICY), new Class[]{}, new Object[]{}); } catch (Exception e) { throw Throwables.propagate(e); } }
private OutStreamOptions() { Configuration conf = ClientContext.getConf(); mBlockSizeBytes = conf.getBytes(Constants.USER_BLOCK_SIZE_BYTES_DEFAULT); mTtl = Constants.NO_TTL; try { mLocationPolicy = CommonUtils.createNewClassInstance(ClientContext.getConf() .<FileWriteLocationPolicy>getClass(Constants.USER_FILE_WRITE_LOCATION_POLICY), new Class[] {}, new Object[] {}); } catch (Exception e) { throw Throwables.propagate(e); } mWriteType = conf.getEnum(Constants.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class); }