Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the JMS session in a try-with-resources statement in the Transmitter #91

Merged
merged 4 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/main/java/org/icatproject/ids/Transmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public class Transmitter {

private TopicConnection topicConnection;

private Session jmsSession;

private MessageProducer jmsProducer;

@PostConstruct
private void init() {

Expand All @@ -42,9 +38,7 @@ private void init() {
.lookup(propertyHandler.getJmsTopicConnectionFactory());
topicConnection = topicConnectionFactory.createTopicConnection();
topic = (Topic) ic.lookup("jms/IDS/log");
jmsSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
jmsProducer = jmsSession.createProducer(topic);
logger.info("Transmitter created");
logger.info("Notification Transmitter created");
} catch (JMSException | NamingException e) {
logger.error(fatal, "Problem with JMS " + e);
throw new IllegalStateException(e.getMessage());
Expand All @@ -55,25 +49,23 @@ private void init() {
@PreDestroy()
private void exit() {
try {
if (jmsSession != null) {
jmsSession.close();
}
if (topicConnection != null) {
topicConnection.close();
}
logger.info("Transmitter closing down");
logger.info("Notification Transmitter closing down");
} catch (JMSException e) {
throw new IllegalStateException(e.getMessage());
}
}

public void processMessage(String operation, String ip, String body, long startMillis) {
try {
try (Session jmsSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
TextMessage jmsg = jmsSession.createTextMessage(body);
jmsg.setStringProperty("operation", operation);
jmsg.setStringProperty("ip", ip);
jmsg.setLongProperty("millis", System.currentTimeMillis() - startMillis);
jmsg.setLongProperty("start", startMillis);
MessageProducer jmsProducer = jmsSession.createProducer(topic);
jmsProducer.send(jmsg);
logger.debug("Sent jms message " + operation + " " + ip);
} catch (JMSException e) {
Expand Down
2 changes: 2 additions & 0 deletions src/site/xhtml/release-notes.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<ul>
<li>Fix uncaught exception in DfRestorer can cause restoration to stall
until IDS is restarted. (Issue #87)</li>
<li>Fix once again JMS Session not closed if an exception is thrown (Issue #85).
The previous fix from 1.9.0 was not thread safe.</li>
</ul>

<h2>1.9.0</h2>
Expand Down