• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Configurable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.kafka.common.Configurable的典型用法代码示例。如果您正苦于以下问题:Java Configurable类的具体用法?Java Configurable怎么用?Java Configurable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Configurable类属于org.apache.kafka.common包,在下文中一共展示了Configurable类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getConfiguredInstances

import org.apache.kafka.common.Configurable; //导入依赖的package包/类
/**
 * Get a list of configured instances of the given class specified by the given configuration key. The configuration
 * may specify either null or an empty string to indicate no configured instances. In both cases, this method
 * returns an empty list to indicate no configured instances.
 * @param key The configuration key for the class
 * @param t The interface the class should implement
 * @return The list of configured instances
 */
public <T> List<T> getConfiguredInstances(String key, Class<T> t) {
    List<String> klasses = getList(key);
    List<T> objects = new ArrayList<T>();
    if (klasses == null)
        return objects;
    for (String klass : klasses) {
        Object o;
        try {
            o = Utils.newInstance(klass, t);
        } catch (ClassNotFoundException e) {
            throw new KafkaException(klass + " ClassNotFoundException exception occured", e);
        }
        if (!t.isInstance(o))
            throw new KafkaException(klass + " is not an instance of " + t.getName());
        if (o instanceof Configurable)
            ((Configurable) o).configure(this.originals);
        objects.add(t.cast(o));
    }
    return objects;
}
 
开发者ID:txazo,项目名称:kafka,代码行数:29,代码来源:AbstractConfig.java


示例2: getConfiguredInstance

import org.apache.kafka.common.Configurable; //导入依赖的package包/类
public <T> T getConfiguredInstance(String key, Class<T> t, Producer<byte[], byte[]> producer) {
  Class<?> c = getClass(key);
  if (c == null) {
    return null;
  }
  Object o = Utils.newInstance(c);

  if (!t.isInstance(o)) {
    throw new KafkaException(c.getName() + " is not an instance of " + t.getName());
  }

  if (o instanceof Configurable) {
    ((Configurable) o).configure(configsWithCurrentProducer(producer));
  }

  return t.cast(o);
}
 
开发者ID:linkedin,项目名称:li-apache-kafka-clients,代码行数:18,代码来源:LiKafkaProducerConfig.java


示例3: newConfiguredPlugin

import org.apache.kafka.common.Configurable; //导入依赖的package包/类
protected static <T> T newConfiguredPlugin(AbstractConfig config, Class<T> klass) {
    T plugin = Utils.newInstance(klass);
    if (plugin instanceof Configurable) {
        ((Configurable) plugin).configure(config.originals());
    }
    return plugin;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:8,代码来源:Plugins.java


示例4: getConfiguredInstance

import org.apache.kafka.common.Configurable; //导入依赖的package包/类
/**
 * Get a configured instance of the give class specified by the given configuration key. If the object implements
 * Configurable configure it using the configuration.
 *
 * @param key The configuration key for the class
 * @param t The interface the class should implement
 * @return A configured instance of the class
 */
public <T> T getConfiguredInstance(String key, Class<T> t) {
    Class<?> c = getClass(key);
    if (c == null)
        return null;
    Object o = Utils.newInstance(c);
    if (!t.isInstance(o))
        throw new KafkaException(c.getName() + " is not an instance of " + t.getName());
    if (o instanceof Configurable)
        ((Configurable) o).configure(originals());
    return t.cast(o);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:20,代码来源:AbstractConfig.java


示例5: getConfiguredInstances

import org.apache.kafka.common.Configurable; //导入依赖的package包/类
/**
 * Get a list of configured instances of the given class specified by the given configuration key. The configuration
 * may specify either null or an empty string to indicate no configured instances. In both cases, this method
 * returns an empty list to indicate no configured instances.
 * @param key The configuration key for the class
 * @param t The interface the class should implement
 * @param configOverrides Configuration overrides to use.
 * @return The list of configured instances
 */
public <T> List<T> getConfiguredInstances(String key, Class<T> t, Map<String, Object> configOverrides) {
    List<String> klasses = getList(key);
    List<T> objects = new ArrayList<T>();
    if (klasses == null)
        return objects;
    Map<String, Object> configPairs = originals();
    configPairs.putAll(configOverrides);
    for (Object klass : klasses) {
        Object o;
        if (klass instanceof String) {
            try {
                o = Utils.newInstance((String) klass, t);
            } catch (ClassNotFoundException e) {
                throw new KafkaException(klass + " ClassNotFoundException exception occurred", e);
            }
        } else if (klass instanceof Class<?>) {
            o = Utils.newInstance((Class<?>) klass);
        } else
            throw new KafkaException("List contains element of type " + klass.getClass().getName() + ", expected String or Class");
        if (!t.isInstance(o))
            throw new KafkaException(klass + " is not an instance of " + t.getName());
        if (o instanceof Configurable)
            ((Configurable) o).configure(configPairs);
        objects.add(t.cast(o));
    }
    return objects;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:37,代码来源:AbstractConfig.java


示例6: getConfiguredInstance

import org.apache.kafka.common.Configurable; //导入依赖的package包/类
/**
 * Get a configured instance of the give class specified by the given configuration key. If the object implements
 * Configurable configure it using the configuration.
 *
 * @param key The configuration key for the class
 * @param t The interface the class should implement
 * @return A configured instance of the class
 */
public <T> T getConfiguredInstance(String key, Class<T> t) {
    Class<?> c = getClass(key);
    if (c == null)
        return null;
    Object o = Utils.newInstance(c);
    if (!t.isInstance(o))
        throw new KafkaException(c.getName() + " is not an instance of " + t.getName());
    if (o instanceof Configurable)
        ((Configurable) o).configure(this.originals);
    return t.cast(o);
}
 
开发者ID:txazo,项目名称:kafka,代码行数:20,代码来源:AbstractConfig.java


示例7: doBindProducer

import org.apache.kafka.common.Configurable; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Binding<KStream<Object, Object>> doBindProducer(String name, KStream<Object, Object> outboundBindTarget,
														ExtendedProducerProperties<KStreamProducerProperties> properties) {
	ExtendedProducerProperties<KafkaProducerProperties> extendedProducerProperties = new ExtendedProducerProperties<KafkaProducerProperties>(
			new KafkaProducerProperties());
	this.kafkaTopicProvisioner.provisionProducerDestination(name, extendedProducerProperties);
	outboundBindTarget = outboundBindTarget
			.map((k, v) -> KeyValue.pair(k, ((Message<Object>) v).getPayload()));

	Serde<?> keySerde = Serdes.ByteArray();
	Serde<?> valueSerde = Serdes.ByteArray();
	if (properties.isUseNativeEncoding()) {
		outboundBindTarget.to(name, Produced.with((Serde<Object>) keySerde, (Serde<Object>) valueSerde));
	}
	else {
		try {
			if (StringUtils.hasText(properties.getExtension().getKeySerde())) {
				keySerde = Utils.newInstance(properties.getExtension().getKeySerde(), Serde.class);
				if (keySerde instanceof Configurable) {
					((Configurable) keySerde).configure(streamsConfig.originals());
				}
			}
			else {
				keySerde = this.binderConfigurationProperties.getConfiguration().containsKey("key.serde") ?
						Utils.newInstance(this.binderConfigurationProperties.getConfiguration().get("key.serde"), Serde.class) : Serdes.ByteArray();
			}

			if (StringUtils.hasText(properties.getExtension().getValueSerde())) {
				valueSerde = Utils.newInstance(properties.getExtension().getValueSerde(), Serde.class);
				if (valueSerde instanceof Configurable) {
					((Configurable) valueSerde).configure(streamsConfig.originals());
				}
			}
			outboundBindTarget.to(name, Produced.with((Serde<Object>) keySerde, (Serde<Object>) valueSerde));
		} catch (ClassNotFoundException e) {
			throw new IllegalStateException("Serde class not found: ", e);
		}
	}
	return new DefaultBinding<>(name, null, outboundBindTarget, null);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:42,代码来源:KStreamBinder.java



注:本文中的org.apache.kafka.common.Configurable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EchoResponse类代码示例发布时间:2022-05-22
下一篇:
Java Constants类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap