Skip to content

Commit

Permalink
Merge pull request #65 from lucasponce/HWKALERTS-63
Browse files Browse the repository at this point in the history
HWKALERTS-63 Fix for bus connection not properly closed
  • Loading branch information
jshaughn committed Jun 30, 2015
2 parents db667a9 + 5145e0e commit 0b1db1a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.hawkular.actions.email.registration;

import java.io.IOException;
import org.hawkular.bus.common.ConnectionContextFactory;
import org.hawkular.bus.common.Endpoint;
import org.hawkular.bus.common.MessageId;
Expand Down Expand Up @@ -73,6 +74,18 @@ public void init() {
} catch (JMSException e) {
log.debug(e.getMessage(), e);
msgLog.errorCannotSendMessage("email", e.getMessage());
} finally {
if (pcc != null) {
try {
pcc.close();
pcc = null;
} catch (IOException ignored) { }
}
if (ccf != null) {
try {
ccf.close();
} catch (JMSException ignored) { }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.hawkular.actions.pagerduty.registration;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -72,6 +73,18 @@ public void init() {
} catch (JMSException e) {
log.debug(e.getMessage(), e);
msgLog.errorCannotSendMessage("pagerduty", e.getMessage());
} finally {
if (pcc != null) {
try {
pcc.close();
pcc = null;
} catch (IOException ignored) { }
}
if (ccf != null) {
try {
ccf.close();
} catch (JMSException ignored) { }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.hawkular.actions.sms.registration;

import java.io.IOException;
import org.hawkular.bus.common.ConnectionContextFactory;
import org.hawkular.bus.common.Endpoint;
import org.hawkular.bus.common.MessageId;
Expand Down Expand Up @@ -72,6 +73,18 @@ public void init() {
} catch (JMSException e) {
log.debug(e.getMessage(), e);
msgLog.errorCannotSendMessage("sms", e.getMessage());
} finally {
if (pcc != null) {
try {
pcc.close();
pcc = null;
} catch (IOException ignored) { }
}
if (ccf != null) {
try {
ccf.close();
} catch (JMSException ignored) { }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.hawkular.actions.snmp.registration;

import java.io.IOException;
import org.hawkular.bus.common.ConnectionContextFactory;
import org.hawkular.bus.common.Endpoint;
import org.hawkular.bus.common.MessageId;
Expand Down Expand Up @@ -74,6 +75,18 @@ public void init() {
} catch (JMSException e) {
log.debug(e.getMessage(), e);
msgLog.errorCannotSendMessage("snmp", e.getMessage());
} finally {
if (pcc != null) {
try {
pcc.close();
pcc = null;
} catch (IOException ignored) { }
}
if (ccf != null) {
try {
ccf.close();
} catch (JMSException ignored) { }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.hawkular.alerts.bus.sender;

import java.io.IOException;
import javax.jms.JMSException;
import org.hawkular.alerts.api.model.action.Action;
import org.hawkular.alerts.api.services.DefinitionsService;
import org.hawkular.alerts.api.services.ActionListener;
Expand Down Expand Up @@ -81,6 +83,19 @@ public void process(Action action) {
} catch (Exception e) {
log.debug(e.getMessage(), e);
msgLogger.errorProcessingAction(e.getMessage());
} finally {
if (pcc != null) {
try {
pcc.close();
pcc = null;
} catch (IOException ignored) { }
}
if (ccf != null) {
try {
ccf.close();
ccf = null;
} catch (JMSException ignored) { }
}
}
}

Expand All @@ -90,7 +105,11 @@ private void init() throws Exception {
}
if (conFactory == null) {
conFactory = (TopicConnectionFactory) ctx.lookup(CONNECTION_FACTORY);
}
if (ccf == null) {
ccf = new ConnectionContextFactory(conFactory);
}
if (pcc == null) {
pcc = ccf.createProducerConnectionContext(new Endpoint(Endpoint.Type.TOPIC, ACTIONS_TOPIC));
}
if (definitions == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public void fire() {

batchData.clear();

if (log.isTraceEnabled()) {
log.trace("Drools session dumping before firing: ");
for (FactHandle fact : kSession.getFactHandles()) {
Object o = kSession.getObject(fact);
log.trace("Fact: " + o.toString());
}
}

kSession.fireAllRules();
}
}
Expand Down

0 comments on commit 0b1db1a

Please sign in to comment.