Search in sources :

Example 1 with MessageHandler

use of com.creditease.uav.messaging.api.MessageHandler in project uavstack by uavorg.

the class GatherDataManager method start.

@Override
public void start() {
    StandardMessagingBuilder builder = new StandardMessagingBuilder("GatherDataManagerMessageBuilder", feature);
    try {
        builder.init();
    } catch (IOException e) {
        log.err(this, "Read msgtype2topic.properties FAILs, GatherDataManager can not START", e);
        return;
    }
    String[] topics = getConfigManager().getFeatureConfiguration(feature, "topics").split(",");
    List<MessageHandler> handlers = new ArrayList<>();
    for (String topic : topics) {
        handlers.add(new DefaultGatherDataHandler(topic));
    }
    MessagingContext.putConsumerHandlers(handlers);
    // init consumers
    consumers = new ArrayList<>();
    for (String topic : topics) {
        MessageConsumer consumer = builder.buildConsumer(topic);
        if (consumer == null) {
            continue;
        }
        consumers.add(consumer);
    }
    // start all consumers
    for (MessageConsumer consumer : consumers) {
        consumer.start();
        log.info(this, "GatherData Consumer [" + consumer.getName() + "] start");
    }
    log.info(this, "GatherDataManager start");
}
Also used : StandardMessagingBuilder(org.uavstack.resources.common.messaging.StandardMessagingBuilder) MessageConsumer(com.creditease.uav.messaging.api.MessageConsumer) MessageHandler(com.creditease.uav.messaging.api.MessageHandler) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DefaultGatherDataHandler(com.creditease.uav.collect.server.messaging.DefaultGatherDataHandler)

Example 2 with MessageHandler

use of com.creditease.uav.messaging.api.MessageHandler in project uavstack by uavorg.

the class RMQMessageConsumer method initHandler.

private void initHandler() {
    String[] handlerClassesStr = (String[]) this.context.get(MessagingContext.ConsumerHandlerClasses);
    ClassLoader[] clsLoaders = (ClassLoader[]) this.context.get(MessagingContext.ConsumerHandlerClassLoaders);
    ClassLoader cl = this.getClass().getClassLoader();
    for (String handlerClassStr : handlerClassesStr) {
        Class<?> c = null;
        try {
            c = cl.loadClass(handlerClassStr);
        } catch (ClassNotFoundException e) {
        // ignore
        }
        if (c == null && clsLoaders != null) {
            for (ClassLoader tcl : clsLoaders) {
                try {
                    c = tcl.loadClass(handlerClassStr);
                } catch (ClassNotFoundException e) {
                // ignore
                }
                if (c != null) {
                    break;
                }
            }
        }
        try {
            MessageHandler instance = (MessageHandler) c.newInstance();
            handlerMap.put(instance.getMsgTypeName(), instance);
        } catch (Exception e) {
            logger.err(this, "ConsumerHandler Class[" + handlerClassStr + "] load FAILs", e);
        }
    }
    // ext MessageHandler instances
    @SuppressWarnings("unchecked") List<MessageHandler> handlers = (List<MessageHandler>) context.get(MessagingContext.CONSUMER_HANDLER_INSTANCES);
    if (handlers != null) {
        for (MessageHandler handler : handlers) {
            handlerMap.put(handler.getMsgTypeName(), handler);
        }
    }
}
Also used : MessageHandler(com.creditease.uav.messaging.api.MessageHandler) List(java.util.List)

Aggregations

MessageHandler (com.creditease.uav.messaging.api.MessageHandler)2 DefaultGatherDataHandler (com.creditease.uav.collect.server.messaging.DefaultGatherDataHandler)1 MessageConsumer (com.creditease.uav.messaging.api.MessageConsumer)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StandardMessagingBuilder (org.uavstack.resources.common.messaging.StandardMessagingBuilder)1