AutopsyEventPublisher closed channel recovery

This commit is contained in:
Richard Cordovano 2015-11-20 10:17:15 -05:00
parent d6a9b9b7fc
commit a54848e3f4

View File

@ -23,6 +23,7 @@ import java.net.URISyntaxException;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import javax.jms.JMSException; import javax.jms.JMSException;
import org.openide.util.Exceptions;
import org.sleuthkit.autopsy.core.UserPreferencesException; import org.sleuthkit.autopsy.core.UserPreferencesException;
import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.core.UserPreferences;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
@ -42,6 +43,7 @@ public final class AutopsyEventPublisher {
private static final Logger logger = Logger.getLogger(AutopsyEventPublisher.class.getName()); private static final Logger logger = Logger.getLogger(AutopsyEventPublisher.class.getName());
private final LocalEventPublisher localPublisher; private final LocalEventPublisher localPublisher;
private RemoteEventPublisher remotePublisher; private RemoteEventPublisher remotePublisher;
private String currentChannelName;
/** /**
* Constructs an object for publishing events to registered subscribers on * Constructs an object for publishing events to registered subscribers on
@ -62,6 +64,7 @@ public final class AutopsyEventPublisher {
* @throws AutopsyEventException if the channel was not opened. * @throws AutopsyEventException if the channel was not opened.
*/ */
public void openRemoteEventChannel(String channelName) throws AutopsyEventException { public void openRemoteEventChannel(String channelName) throws AutopsyEventException {
currentChannelName = channelName;
if (null != remotePublisher) { if (null != remotePublisher) {
closeRemoteEventChannel(); closeRemoteEventChannel();
} }
@ -83,6 +86,7 @@ public final class AutopsyEventPublisher {
* events from other Autopsy nodes. * events from other Autopsy nodes.
*/ */
public void closeRemoteEventChannel() { public void closeRemoteEventChannel() {
currentChannelName = null;
if (null != remotePublisher) { if (null != remotePublisher) {
try { try {
remotePublisher.stop(); remotePublisher.stop();
@ -162,7 +166,13 @@ public final class AutopsyEventPublisher {
try { try {
remotePublisher.publish(event); remotePublisher.publish(event);
} catch (JMSException ex) { } catch (JMSException ex) {
logger.log(Level.SEVERE, String.format("Failed to publish %s event remotely", event.getPropertyName()), ex); //NON-NLS logger.log(Level.SEVERE, String.format("Failed to publish %s event remotely, re-opening channel %s", event.getPropertyName(), currentChannelName), ex); //NON-NLS
closeRemoteEventChannel();
try {
openRemoteEventChannel(this.currentChannelName);
} catch (AutopsyEventException ex1) {
logger.log(Level.SEVERE, String.format("Failed re-opening channel %s", currentChannelName), ex); //NON-NLS
}
} }
} }
} }