Java 类io.vertx.core.eventbus.MessageCodec 实例源码

项目:vertx-utils    文件:MainVerticle.java   
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");
                }
            }
        }
    }
}
项目:vertx-memcache    文件:MemcacheVerticle.java   
private <T> void registerDefaultCodec(Class<T> clazz, MessageCodec<T, ?> codec) {
    try {
        vertx.eventBus().registerDefaultCodec(clazz, codec);
    } catch (IllegalStateException iae) {
        // Codec is already registered.
    }
}
项目:runrightfast-vertx    文件:ProtobufMessageProducer.java   
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());
    }
}
项目:vertx-camel-bridge    文件:Examples.java   
public void registerCodec(Vertx vertx, MessageCodec<Person, Person> codec) {
  vertx.eventBus().registerDefaultCodec(Person.class, codec);
}
项目:vertx-lang-groovy    文件:Examples.java   
public void example10(EventBus eventBus, MessageCodec myCodec) {

    eventBus.registerCodec(myCodec);

    DeliveryOptions options = new DeliveryOptions().setCodecName(myCodec.name());

    eventBus.send("orders", new MyPOJO(), options);
  }
项目:vertx-lang-groovy    文件:Examples.java   
public void example11(EventBus eventBus, MessageCodec myCodec) {

    eventBus.registerDefaultCodec(MyPOJO.class, myCodec);

    eventBus.send("orders", new MyPOJO());
  }