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");
}
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);
}
}
}
Aggregations