1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.service.component.agent.impl.worldbank;
20
21 import java.util.Collection;
22 import java.util.Map;
23
24 import javax.jms.JMSException;
25 import javax.jms.Message;
26 import javax.jms.ObjectMessage;
27
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.stereotype.Service;
32
33 import com.hack23.cia.model.internal.application.data.impl.WorldBankDataSources;
34 import com.hack23.cia.service.component.agent.impl.common.AbstractAgentWorkConsumerImpl;
35 import com.hack23.cia.service.component.agent.impl.worldbank.workgenerator.WorldBankDataSourcesWorkGenerator;
36
37
38
39
40 @Service("WorldBankApiAgentWorkConsumer")
41 final class WorldBankApiAgentWorkConsumerImpl extends AbstractAgentWorkConsumerImpl {
42
43
44 private static final Logger LOGGER = LoggerFactory.getLogger(WorldBankApiAgentWorkConsumerImpl.class);
45
46
47 private final Map<String, WorldBankDataSourcesWorkGenerator> beansOfType;
48
49
50
51
52
53
54
55 public WorldBankApiAgentWorkConsumerImpl(final ApplicationContext context) {
56 super();
57 beansOfType = context.getBeansOfType(WorldBankDataSourcesWorkGenerator.class);
58 }
59
60 @Override
61 public void onMessage(final Message message) {
62 final ObjectMessage msg = (ObjectMessage) message;
63
64 try {
65 LOGGER.info("Consumed message:{}", msg.getObject());
66 final WorldBankDataSources dataSource = (WorldBankDataSources) msg.getObject();
67
68 final Collection<WorldBankDataSourcesWorkGenerator> values = beansOfType.values();
69
70 for (final WorldBankDataSourcesWorkGenerator worldBankDataSourcesWorkGenerator : values) {
71 if (worldBankDataSourcesWorkGenerator.matches(dataSource)) {
72 worldBankDataSourcesWorkGenerator.generateWorkOrders();
73 return;
74 }
75 }
76 LOGGER.warn("Missing import for :{}", dataSource);
77
78 } catch (final JMSException exception) {
79 LOGGER.warn("jms", exception);
80 }
81 }
82
83 }