本文整理了Java中org.apache.storm.utils.Utils.newInstance()
方法的一些代码示例,展示了Utils.newInstance()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.newInstance()
方法的具体详情如下:
包路径:org.apache.storm.utils.Utils
类名称:Utils
方法名:newInstance
暂无
代码示例来源:origin: org.apache.storm/storm-core
public static JarTransformer jarTransformer(String klass) {
JarTransformer ret = null;
if (klass != null) {
ret = (JarTransformer)newInstance(klass);
}
return ret;
}
代码示例来源:origin: org.apache.storm/storm-core
private static PreparableReporter getPreparableReporter(String clazz) {
PreparableReporter reporter = null;
LOG.info("Using statistics reporter plugin:" + clazz);
if (clazz != null) {
reporter = (PreparableReporter) Utils.newInstance(clazz);
}
return reporter;
}
代码示例来源:origin: org.apache.storm/storm-core
@SuppressWarnings("unchecked")
public static <T> T newInstance(String klass) {
try {
return newInstance((Class<T>)Class.forName(klass));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.apache.storm/storm-core
/**
* Return a new instance of a pluggable specified in the conf.
* @param conf The conf to read from.
* @param configKey The key pointing to the pluggable class
* @return an instance of the class or null if it is not specified.
*/
public static Object getConfiguredClass(Map conf, Object configKey) {
if (conf.containsKey(configKey)) {
return newInstance((String)conf.get(configKey));
}
return null;
}
代码示例来源:origin: org.apache.storm/storm-core
public static StormMetricsFilter getMetricsFilter(Map reporterConf){
StormMetricsFilter filter = null;
Map<String, Object> filterConf = (Map)reporterConf.get("filter");
if(filterConf != null) {
String clazz = (String) filterConf.get("class");
if (clazz != null) {
filter = Utils.newInstance(clazz);
filter.prepare(filterConf);
}
}
return filter;
}
}
代码示例来源:origin: org.apache.storm/storm-core
public static ClientBlobStore getClientBlobStore(Map conf) {
ClientBlobStore store = (ClientBlobStore) Utils.newInstance((String) conf.get(Config.CLIENT_BLOBSTORE));
store.prepare(conf);
return store;
}
代码示例来源:origin: org.apache.storm/storm-core
private void registerMetrics(TopologyContext context, Map<String, String> metrics, int bucketSize) {
if (metrics == null) return;
for (Map.Entry<String, String> metric: metrics.entrySet()) {
try {
context.registerMetric(metric.getKey(), (IMetric)Utils.newInstance(metric.getValue()), bucketSize);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: org.apache.storm/storm-core
public static ClientBlobStore getClientBlobStoreForSupervisor(Map conf) {
ClientBlobStore store = (ClientBlobStore) newInstance(
(String) conf.get(Config.SUPERVISOR_BLOBSTORE));
store.prepare(conf);
return store;
}
代码示例来源:origin: org.apache.storm/storm-core
public static BlobStore getNimbusBlobStore(Map conf, String baseDir, NimbusInfo nimbusInfo) {
String type = (String)conf.get(Config.NIMBUS_BLOBSTORE);
if (type == null) {
type = LocalFsBlobStore.class.getName();
}
BlobStore store = (BlobStore) newInstance(type);
HashMap nconf = new HashMap(conf);
// only enable cleanup of blobstore on nimbus
nconf.put(Config.BLOBSTORE_CLEANUP_ENABLE, Boolean.TRUE);
if(store != null) {
// store can be null during testing when mocking utils.
store.prepare(nconf, baseDir, nimbusInfo);
}
return store;
}
代码示例来源:origin: org.apache.storm/storm-core
private static void startReporter(Map<String, Object> stormConfig, Map<String, Object> reporterConfig){
String clazz = (String)reporterConfig.get("class");
StormReporter reporter = null;
LOG.info("Attempting to instantiate reporter class: {}", clazz);
reporter = Utils.newInstance(clazz);
if(reporter != null){
reporter.prepare(REGISTRY, stormConfig, reporterConfig);
reporter.start();
REPORTERS.add(reporter);
}
}
代码示例来源:origin: org.apache.storm/storm-core
public Map<String, List<String>> getNetworkTopography() {
if (networkTopography == null) {
networkTopography = new HashMap<String, List<String>>();
ArrayList<String> supervisorHostNames = new ArrayList<String>();
for (SupervisorDetails s : supervisors.values()) {
supervisorHostNames.add(s.getHost());
}
String clazz = (String) conf.get(Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN);
DNSToSwitchMapping topographyMapper = (DNSToSwitchMapping) Utils.newInstance(clazz);
Map<String, String> resolvedSuperVisors = topographyMapper.resolve(supervisorHostNames);
for (Map.Entry<String, String> entry : resolvedSuperVisors.entrySet()) {
String hostName = entry.getKey();
String rack = entry.getValue();
List<String> nodesForRack = networkTopography.get(rack);
if (nodesForRack == null) {
nodesForRack = new ArrayList<String>();
networkTopography.put(rack, nodesForRack);
}
nodesForRack.add(hostName);
}
}
return networkTopography;
}
代码示例来源:origin: org.apache.storm/storm-sql-runtime
public static Scheme getScheme(String inputFormatClass, Properties properties, List<String> fieldNames) {
Scheme scheme;
if (isNotEmpty(inputFormatClass)) {
if (JsonScheme.class.getName().equals(inputFormatClass)) {
scheme = new JsonScheme(fieldNames);
} else if (TsvScheme.class.getName().equals(inputFormatClass)) {
String delimiter = properties.getProperty("input.tsv.delimiter", "\t");
scheme = new TsvScheme(fieldNames, delimiter.charAt(0));
} else if (CsvScheme.class.getName().equals(inputFormatClass)) {
scheme = new CsvScheme(fieldNames);
} else if (AvroScheme.class.getName().equals(inputFormatClass)) {
String schemaString = properties.getProperty("input.avro.schema");
Preconditions.checkArgument(isNotEmpty(schemaString), "input.avro.schema can not be empty");
scheme = new AvroScheme(schemaString, fieldNames);
} else {
scheme = Utils.newInstance(inputFormatClass);
}
} else {
//use JsonScheme as the default scheme
scheme = new JsonScheme(fieldNames);
}
return scheme;
}
代码示例来源:origin: org.apache.storm/storm-sql-runtime
public static IOutputSerializer getSerializer(String outputFormatClass, Properties properties, List<String> fieldNames) {
IOutputSerializer serializer;
if (isNotEmpty(outputFormatClass)) {
if (JsonSerializer.class.getName().equals(outputFormatClass)) {
serializer = new JsonSerializer(fieldNames);
} else if (TsvSerializer.class.getName().equals(outputFormatClass)) {
String delimiter = properties.getProperty("output.tsv.delimiter", "\t");
serializer = new TsvSerializer(fieldNames, delimiter.charAt(0));
} else if (CsvSerializer.class.getName().equals(outputFormatClass)) {
serializer = new CsvSerializer(fieldNames);
} else if (AvroSerializer.class.getName().equals(outputFormatClass)) {
String schemaString = properties.getProperty("output.avro.schema");
Preconditions.checkArgument(isNotEmpty(schemaString), "output.avro.schema can not be empty");
serializer = new AvroSerializer(schemaString, fieldNames);
} else {
serializer = Utils.newInstance(outputFormatClass);
}
} else {
//use JsonSerializer as the default serializer
serializer = new JsonSerializer(fieldNames);
}
return serializer;
}
代码示例来源:origin: org.apache.storm/storm-core
schedulingPrioritystrategy = (ISchedulingPriorityStrategy) Utils.newInstance((String) this.conf.get(Config.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY));
} catch (RuntimeException ex) {
LOG.error(String.format("failed to create instance of priority strategy: %s with error: %s! No topologies will be scheduled.",
代码示例来源:origin: com.twitter.heron/heron-storm
public static Kryo getKryo(Map conf) {
IKryoFactory kryoFactory =
(IKryoFactory) Utils.newInstance((String) conf.get(Config.TOPOLOGY_KRYO_FACTORY));
Kryo k = kryoFactory.getKryo(conf);
k.register(byte[].class);
代码示例来源:origin: org.apache.storm/storm-core
public static Kryo getKryo(Map conf) {
IKryoFactory kryoFactory = (IKryoFactory) Utils.newInstance((String) conf.get(Config.TOPOLOGY_KRYO_FACTORY));
Kryo k = kryoFactory.getKryo(conf);
k.register(byte[].class);
代码示例来源:origin: org.apache.storm/storm-core
IStrategy rasStrategy = null;
try {
rasStrategy = (IStrategy) Utils.newInstance((String) td.getConf().get(Config.TOPOLOGY_SCHEDULER_STRATEGY));
} catch (RuntimeException e) {
LOG.error("failed to create instance of IStrategy: {} with error: {}! Topology {} will not be scheduled.",
if (evictionStrategy == null) {
try {
evictionStrategy = (IEvictionStrategy) Utils.newInstance((String) this.conf.get(Config.RESOURCE_AWARE_SCHEDULER_EVICTION_STRATEGY));
} catch (RuntimeException e) {
LOG.error("failed to create instance of eviction strategy: {} with error: {}! No topology eviction will be done.",
内容来源于网络,如有侵权,请联系作者删除!