本文整理汇总了Java中org.apache.bookkeeper.util.ReflectionUtils.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.newInstance方法的具体用法?Java ReflectionUtils.newInstance怎么用?Java ReflectionUtils.newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bookkeeper.util.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.newInstance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.bookkeeper.util.ReflectionUtils; //导入方法依赖的package包/类
public static void main(String args[]) {
int rc = -1;
if (args.length <= 0) {
System.err.println("No tool to run.");
System.err.println("");
System.err.println("Usage : Tool <tool_class_name> <options>");
System.exit(-1);
}
String toolClass = args[0];
try {
Tool tool = ReflectionUtils.newInstance(toolClass, Tool.class);
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
rc = tool.run(newArgs);
} catch (Throwable t) {
System.err.println("Fail to run tool " + toolClass + " : ");
t.printStackTrace();
}
System.exit(rc);
}
示例2: createService
import org.apache.bookkeeper.util.ReflectionUtils; //导入方法依赖的package包/类
private DistributedLogServiceImpl createService(
ServerConfiguration serverConf,
DistributedLogConfiguration dlConf,
CountDownLatch latch) throws Exception {
// Build the stream partition converter
StreamPartitionConverter converter;
try {
converter = ReflectionUtils.newInstance(serverConf.getStreamPartitionConverterClass());
} catch (ConfigurationException e) {
logger.warn("Failed to load configured stream-to-partition converter. Fallback to use {}",
IdentityStreamPartitionConverter.class.getName());
converter = new IdentityStreamPartitionConverter();
}
return new DistributedLogServiceImpl(
serverConf,
dlConf,
ConfUtils.getConstDynConf(dlConf),
new NullStreamConfigProvider(),
uri,
converter,
NullStatsLogger.INSTANCE,
NullStatsLogger.INSTANCE,
latch);
}
示例3: runTool
import org.apache.bookkeeper.util.ReflectionUtils; //导入方法依赖的package包/类
private static int runTool(String[] args) throws Exception {
Tool tool = ReflectionUtils.newInstance(args[0], Tool.class);
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
int rc = tool.run(newArgs);
assertTrue(0 == rc);
return rc;
}
示例4: runCmd
import org.apache.bookkeeper.util.ReflectionUtils; //导入方法依赖的package包/类
void runCmd(CommandLine cmdline) throws IOException {
StatsProvider statsProvider = new NullStatsProvider();
if (cmdline.hasOption("p")) {
String providerClass = cmdline.getOptionValue("p");
statsProvider = ReflectionUtils.newInstance(providerClass, StatsProvider.class);
}
StatsReceiver statsReceiver = NullStatsReceiver.get();
final MonitorService monitorService = new MonitorService(
getOptionalStringArg(cmdline, "u"),
getOptionalStringArg(cmdline, "c"),
getOptionalStringArg(cmdline, "s"),
getOptionalIntegerArg(cmdline, "i"),
getOptionalIntegerArg(cmdline, "d"),
getOptionalStringArg(cmdline, "f"),
getOptionalIntegerArg(cmdline, "n"),
getOptionalIntegerArg(cmdline, "t"),
getOptionalIntegerArg(cmdline, "hck"),
getOptionalBooleanArg(cmdline, "hsci"),
getOptionalBooleanArg(cmdline, "w"),
statsReceiver,
statsProvider);
monitorService.runServer();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
logger.info("Closing monitor service.");
monitorService.close();
logger.info("Closed monitor service.");
}
});
try {
monitorService.join();
} catch (InterruptedException ie) {
logger.warn("Interrupted when waiting monitor service to be finished : ", ie);
}
}
示例5: parseCommandLine
import org.apache.bookkeeper.util.ReflectionUtils; //导入方法依赖的package包/类
protected void parseCommandLine(String[] args)
throws Exception {
BasicParser parser = new BasicParser();
CommandLine cmdline = parser.parse(options, args);
if (cmdline.hasOption("h")) {
printUsage();
System.exit(0);
}
if (cmdline.hasOption("u")) {
this.uri = URI.create(cmdline.getOptionValue("u"));
} else {
printUsage();
System.exit(0);
}
this.conf = new DistributedLogConfiguration();
if (cmdline.hasOption("c")) {
String configFile = cmdline.getOptionValue("c");
this.conf.loadConf(new File(configFile).toURI().toURL());
}
if (cmdline.hasOption("p")) {
statsProvider = ReflectionUtils.newInstance(cmdline.getOptionValue("p"), StatsProvider.class);
} else {
statsProvider = new NullStatsProvider();
}
if (cmdline.hasOption("s")) {
this.streamName = cmdline.getOptionValue("s");
} else {
printUsage();
System.exit(0);
}
parseCommandLine(cmdline);
}
示例6: main
import org.apache.bookkeeper.util.ReflectionUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length <= 0) {
System.err.println(USAGE);
return;
}
String benchmarkClassName = args[0];
StreamBenchmark benchmark = ReflectionUtils.newInstance(
benchmarkClassName, StreamBenchmark.class);
benchmark.run(args);
}
示例7: BrokerStarter
import org.apache.bookkeeper.util.ReflectionUtils; //导入方法依赖的package包/类
BrokerStarter(String[] args) throws Exception{
StarterArguments starterArguments = new StarterArguments();
JCommander jcommander = new JCommander(starterArguments);
jcommander.setProgramName("PulsarBrokerStarter");
// parse args by JCommander
jcommander.parse(args);
if (starterArguments.help) {
jcommander.usage();
System.exit(-1);
}
// init broker config and pulsar service
if (isBlank(starterArguments.brokerConfigFile)) {
jcommander.usage();
throw new IllegalArgumentException("Need to specify a configuration file for broker");
} else {
brokerConfig = loadConfig(starterArguments.brokerConfigFile);
pulsarService = new PulsarService(brokerConfig);
}
// if no argument to run bookie in cmd line, read from pulsar config
if (!argsContains(args, "-rb") && !argsContains(args, "--run-bookie")) {
checkState(starterArguments.runBookie == false,
"runBookie should be false if has no argument specified");
starterArguments.runBookie = brokerConfig.isEnableRunBookieTogether();
}
if (!argsContains(args, "-ra") && !argsContains(args, "--run-bookie-autorecovery")) {
checkState(starterArguments.runBookieAutoRecovery == false,
"runBookieAutoRecovery should be false if has no argument specified");
starterArguments.runBookieAutoRecovery = brokerConfig.isEnableRunBookieAutoRecoveryTogether();
}
if ((starterArguments.runBookie || starterArguments.runBookieAutoRecovery)
&& isBlank(starterArguments.bookieConfigFile)) {
jcommander.usage();
throw new IllegalArgumentException("No configuration file for Bookie");
}
// init stats provider
if (starterArguments.runBookie || starterArguments.runBookieAutoRecovery) {
checkState(isNotBlank(starterArguments.bookieConfigFile),
"No configuration file for Bookie");
bookieConfig = readBookieConfFile(starterArguments.bookieConfigFile);
Class<? extends StatsProvider> statsProviderClass = bookieConfig.getStatsProviderClass();
bookieStatsProvider = ReflectionUtils.newInstance(statsProviderClass);
} else {
bookieConfig = null;
bookieStatsProvider = null;
}
// init bookie server
if (starterArguments.runBookie) {
checkNotNull(bookieConfig, "No ServerConfiguration for Bookie");
checkNotNull(bookieStatsProvider, "No Stats Provider for Bookie");
bookieServer = new BookieServer(bookieConfig, bookieStatsProvider.getStatsLogger(""));
} else {
bookieServer = null;
}
// init bookie AutorecoveryMain
if (starterArguments.runBookieAutoRecovery) {
checkNotNull(bookieConfig, "No ServerConfiguration for Bookie Autorecovery");
autoRecoveryMain = new AutoRecoveryMain(bookieConfig);
} else {
autoRecoveryMain = null;
}
}