|
@@ -1,15 +1,5 @@
|
|
|
package com.redhat.training.collector;
|
|
|
|
|
|
-import javax.jms.Connection;
|
|
|
-import javax.jms.ConnectionFactory;
|
|
|
-import javax.jms.JMSException;
|
|
|
-import javax.jms.MessageConsumer;
|
|
|
-import javax.jms.Queue;
|
|
|
-import javax.jms.Session;
|
|
|
-import javax.jms.TextMessage;
|
|
|
-import javax.naming.InitialContext;
|
|
|
-import javax.naming.NamingException;
|
|
|
-
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -17,52 +7,33 @@ public class CollectMetric {
|
|
|
public static void main(String... args) {
|
|
|
Logger LOG = LoggerFactory.getLogger(CollectMetric.class);
|
|
|
|
|
|
- // prepare connection objects
|
|
|
- InitialContext ctx;
|
|
|
- ConnectionFactory cf;
|
|
|
- Connection c;
|
|
|
- Session s;
|
|
|
- MessageConsumer mc;
|
|
|
- Queue q;
|
|
|
-
|
|
|
+ // TODO: prepare connection objects
|
|
|
+
|
|
|
+ // TODO: declare JMS objects
|
|
|
+
|
|
|
try {
|
|
|
- ctx = new InitialContext();
|
|
|
- cf = (ConnectionFactory)ctx.lookup("ConnectionFactory");
|
|
|
- q = (Queue)ctx.lookup("queue/metrics");
|
|
|
- } catch (NamingException ne) {
|
|
|
+ // TODO: initialise context, connection factory, and destination
|
|
|
+ } catch (Exception ne) { // TODO: be specific about exception
|
|
|
ne.printStackTrace();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- c = cf.createConnection();
|
|
|
- c.start();
|
|
|
-
|
|
|
- s = c.createSession();
|
|
|
- mc = s.createConsumer(q);
|
|
|
- } catch (JMSException je) {
|
|
|
+ // TODO: create and start the connection, obtain session and consumer
|
|
|
+ } catch (Exception je) { // TODO: be specific about exception
|
|
|
je.printStackTrace();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
while (true) {
|
|
|
try {
|
|
|
- TextMessage tm = (TextMessage)mc.receive(1000);
|
|
|
+ // TODO: wait up to 1 second to receive message
|
|
|
|
|
|
- if (tm != null) {
|
|
|
- LOG.info("Got: " + tm.getText());
|
|
|
- }
|
|
|
-
|
|
|
- continue;
|
|
|
- } catch (JMSException je) {
|
|
|
+ // TODO: print the message in the log
|
|
|
+ LOG.info("Got: " + null);
|
|
|
+ } catch (Exception je) { // TODO: Specific exception type
|
|
|
je.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
- try {
|
|
|
- Thread.sleep(1000);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|