Merge pull request #1731 from rcordovano/develop

Add multiple retries to remote event publishing
This commit is contained in:
Richard Cordovano 2015-11-22 15:42:28 -05:00
commit 2bc998155f

View File

@ -23,7 +23,6 @@ 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;
@ -41,6 +40,7 @@ public final class AutopsyEventPublisher {
* Composed of thread-safe objects. * Composed of thread-safe objects.
*/ */
private static final Logger logger = Logger.getLogger(AutopsyEventPublisher.class.getName()); private static final Logger logger = Logger.getLogger(AutopsyEventPublisher.class.getName());
private static final int MAX_REMOTE_EVENT_PUBLISH_TRIES = 3;
private final LocalEventPublisher localPublisher; private final LocalEventPublisher localPublisher;
private RemoteEventPublisher remotePublisher; private RemoteEventPublisher remotePublisher;
private String currentChannelName; private String currentChannelName;
@ -162,18 +162,27 @@ public final class AutopsyEventPublisher {
* @param event The event to publish. * @param event The event to publish.
*/ */
public void publishRemotely(AutopsyEvent event) { public void publishRemotely(AutopsyEvent event) {
if (null != remotePublisher) { if (null != currentChannelName) {
try { boolean published = false;
remotePublisher.publish(event); int tryCount = 1;
} catch (JMSException ex) { while (false == published && tryCount <= MAX_REMOTE_EVENT_PUBLISH_TRIES) {
logger.log(Level.SEVERE, String.format("Failed to publish %s event remotely, re-opening channel %s", event.getPropertyName(), currentChannelName), ex); //NON-NLS
closeRemoteEventChannel();
try { try {
openRemoteEventChannel(this.currentChannelName); if (null == remotePublisher) {
} catch (AutopsyEventException ex1) { openRemoteEventChannel(currentChannelName);
logger.log(Level.SEVERE, String.format("Failed re-opening channel %s", currentChannelName), ex); //NON-NLS }
remotePublisher.publish(event);
published = true;
} catch (JMSException ex) {
logger.log(Level.SEVERE, String.format("Failed to publish %s using channel %s (tryCount = %s)", event.getPropertyName(), currentChannelName, tryCount), ex); //NON-NLS
closeRemoteEventChannel();
++tryCount;
} catch (AutopsyEventException ex) {
logger.log(Level.SEVERE, String.format("Failed to reopen channel %s to publish %s event (tryCount = %s)", currentChannelName, event.getPropertyName(), tryCount), ex); //NON-NLS
++tryCount;
} }
} }
} else {
logger.log(Level.SEVERE, "Attempt to publish {0} event remotely with no open channel", event.getPropertyName()); //NON-NLS
} }
} }