本文整理汇总了Java中io.vertx.core.eventbus.MessageCodec类的典型用法代码示例。如果您正苦于以下问题:Java MessageCodec类的具体用法?Java MessageCodec怎么用?Java MessageCodec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageCodec类属于io.vertx.core.eventbus包,在下文中一共展示了MessageCodec类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerMessageCodecs
import io.vertx.core.eventbus.MessageCodec; //导入依赖的package包/类
static void registerMessageCodecs(
final Vertx vertx,
final JsonObject config,
final boolean abortOnFailure)
throws CodecRegistrationException {
final JsonArray messageCodecs = config.getJsonArray(MESSAGE_CODECS_FIELD);
if (messageCodecs != null) {
for (final Object messageCodecClassNameObject : messageCodecs.getList()) {
if (messageCodecClassNameObject instanceof String) {
final String messageCodecClassName = (String) messageCodecClassNameObject;
try {
final MessageCodec<?, ?> messageCodec = (MessageCodec<?, ?>) Class.forName(messageCodecClassName).newInstance();
vertx.eventBus().registerCodec(messageCodec);
} catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) {
log.warn("registerMessageCodecs", "start", new String[]{"message", "messageCodecClassName"}, "Failed to instantiate message codec", messageCodecClassName, e);
if (abortOnFailure) {
throw new CodecRegistrationException(
String.format(
"Failed to instantiate message codec %s",
messageCodecClassName),
e);
}
}
} else {
log.warn("registerMessageCodecs", "start", new String[]{"message", "messageCodecClassName"}, "Ignoring non-string message codec class name", messageCodecClassNameObject);
if (abortOnFailure) {
throw new CodecRegistrationException("Ignoring non-string message codec class name");
}
}
}
}
}
示例2: registerDefaultCodec
import io.vertx.core.eventbus.MessageCodec; //导入依赖的package包/类
private <T> void registerDefaultCodec(Class<T> clazz, MessageCodec<T, ?> codec) {
try {
vertx.eventBus().registerDefaultCodec(clazz, codec);
} catch (IllegalStateException iae) {
// Codec is already registered.
}
}
示例3: registerMessageCodec
import io.vertx.core.eventbus.MessageCodec; //导入依赖的package包/类
private void registerMessageCodec(final ProtobufMessageCodec<A> codec) {
try {
eventBus.registerDefaultCodec(codec.getDefaultInstance().getClass(), (MessageCodec) codec);
} catch (final IllegalStateException e) {
log.logp(FINE, "ProtobufMessageProducer", "registerMessageCodec", "failed to register codec for request message", e.getCause());
}
}
示例4: registerCodec
import io.vertx.core.eventbus.MessageCodec; //导入依赖的package包/类
public void registerCodec(Vertx vertx, MessageCodec<Person, Person> codec) {
vertx.eventBus().registerDefaultCodec(Person.class, codec);
}
示例5: example10
import io.vertx.core.eventbus.MessageCodec; //导入依赖的package包/类
public void example10(EventBus eventBus, MessageCodec myCodec) {
eventBus.registerCodec(myCodec);
DeliveryOptions options = new DeliveryOptions().setCodecName(myCodec.name());
eventBus.send("orders", new MyPOJO(), options);
}
示例6: example11
import io.vertx.core.eventbus.MessageCodec; //导入依赖的package包/类
public void example11(EventBus eventBus, MessageCodec myCodec) {
eventBus.registerDefaultCodec(MyPOJO.class, myCodec);
eventBus.send("orders", new MyPOJO());
}