|
@@ -3,16 +3,6 @@ package com.redhat.training.sender;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.management.ManagementFactory;
|
|
import java.lang.management.ThreadMXBean;
|
|
import java.lang.management.ThreadMXBean;
|
|
|
|
|
|
-import javax.jms.Connection;
|
|
|
|
-import javax.jms.ConnectionFactory;
|
|
|
|
-import javax.jms.JMSException;
|
|
|
|
-import javax.jms.MessageProducer;
|
|
|
|
-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.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
@@ -26,30 +16,18 @@ public class SendMetric {
|
|
long threadId = Thread.currentThread().getId();
|
|
long threadId = Thread.currentThread().getId();
|
|
long oldTime = 0;
|
|
long oldTime = 0;
|
|
|
|
|
|
- // prepare connection objects
|
|
|
|
- InitialContext ctx;
|
|
|
|
- ConnectionFactory cf;
|
|
|
|
- Connection c;
|
|
|
|
- Session s;
|
|
|
|
- MessageProducer mp;
|
|
|
|
- Queue q;
|
|
|
|
-
|
|
|
|
|
|
+ // TODO: declare JMS objects
|
|
|
|
+
|
|
try {
|
|
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();
|
|
ne.printStackTrace();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
- c = cf.createConnection();
|
|
|
|
- c.start();
|
|
|
|
-
|
|
|
|
- s = c.createSession();
|
|
|
|
- mp = s.createProducer(q);
|
|
|
|
- } catch (JMSException je) {
|
|
|
|
|
|
+ // TODO: create and start the connection, obtain session and producer
|
|
|
|
+ } catch (Exception je) { // TODO: be specific about exception
|
|
je.printStackTrace();
|
|
je.printStackTrace();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -61,13 +39,13 @@ public class SendMetric {
|
|
LOG.info(report);
|
|
LOG.info(report);
|
|
|
|
|
|
try {
|
|
try {
|
|
- TextMessage tm = s.createTextMessage(report);
|
|
|
|
- mp.send(tm);
|
|
|
|
- } catch (JMSException je) {
|
|
|
|
|
|
+ // TODO: create a message and send it
|
|
|
|
+ } catch (Exception je) { // TODO: be specific about exception
|
|
je.printStackTrace();
|
|
je.printStackTrace();
|
|
}
|
|
}
|
|
|
|
|
|
oldTime = newTime;
|
|
oldTime = newTime;
|
|
|
|
+
|
|
try {
|
|
try {
|
|
Thread.sleep(1000);
|
|
Thread.sleep(1000);
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|