From db6618a76f939b017840824ae5f87c66722be23d Mon Sep 17 00:00:00 2001 From: David McKnight Date: Wed, 12 Mar 2008 17:31:09 +0000 Subject: [PATCH] [222448] [dstore] update DownloadListener to handle timeouts and nudge --- .../dstore/util/StatusMonitor.java | 34 ++++++++++++++-- .../dstore/util/DownloadListener.java | 39 +++++++++++++++---- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/util/StatusMonitor.java b/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/util/StatusMonitor.java index 181ed2583fe..d86b8c650d7 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/util/StatusMonitor.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/util/StatusMonitor.java @@ -287,7 +287,10 @@ public class StatusMonitor implements IDomainListener, ICommunicationsListener WaitThreshold = wait*10; // 1 second means 10 sleep(100ms) else if ( wait == -1 ) // force a diagnostic WaitThreshold = -1; - + + int nudges = 0; // nudges used for waking up server with slow connections + // nudge up to 12 times before giving up + if (display != null) { // Current thread is UI thread @@ -319,8 +322,13 @@ public class StatusMonitor implements IDomainListener, ICommunicationsListener if (WaitThreshold == 0) { - // no diagnostic factory but there is a timeout - return status; // returning the undone status object + wakeupServer(status); + + // no diagnostic factory but there is a timeout + if (nudges >= 12) + return status; // returning the undone status object + + nudges++; } else if (_networkDown) { @@ -359,8 +367,13 @@ public class StatusMonitor implements IDomainListener, ICommunicationsListener if (WaitThreshold == 0) { + wakeupServer(status); + // no diagnostic factory but there is a timeout - return status; // returning the undone status object + if (nudges >= 12) + return status; // returning the undone status object + + nudges++; } else if (_networkDown) { @@ -375,6 +388,19 @@ public class StatusMonitor implements IDomainListener, ICommunicationsListener return status; } + private void wakeupServer(DataElement status) + { + if (status != null) + { + // token command to wake up update handler + DataElement cmdDescriptor = _dataStore.findCommandDescriptor("C_REFRESH"); //$NON-NLS-1$ + DataElement subject = status.getParent().get(0); + if (cmdDescriptor != null) + { + _dataStore.command(cmdDescriptor, subject); + } + } + } /** * Start diagnostic diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DownloadListener.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DownloadListener.java index 8fd3a2c825f..7a676c3c5bf 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DownloadListener.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DownloadListener.java @@ -16,6 +16,7 @@ * David McKnight (IBM) - [197480] eliminating UI dependencies * David McKnight (IBM) - [216252] MessageFormat.format -> NLS.bind * Martin Oberhuber (Wind River) - [219952] Use MessageFormat for download progress message + * David McKnight (IBM) - [222448] [dstore] update DownloadListener to handle timeouts and nudge ********************************************************************************/ package org.eclipse.rse.services.dstore.util; @@ -230,14 +231,13 @@ public class DownloadListener implements IDomainListener */ public DataElement waitForUpdate(int wait) throws InterruptedException { - + // Prevent infinite looping by introducing a threshold for wait + int WaitThreshold = 50; //default. sleep(100ms) for 150 times + if (wait > 0) - { - } - else if (wait == -1) - { - } - + WaitThreshold = wait * 10; // 1 second means 10 sleep(100ms) + else if (wait == -1) // force a diagnostic + WaitThreshold = -1; { // Current thread is not UI thread @@ -263,11 +263,36 @@ public class DownloadListener implements IDomainListener { Thread.sleep(100); updateDownloadState(); + + if (WaitThreshold > 0) // update timer count if + { + // threshold not reached + --WaitThreshold; // decrement the timer count + } + else if (WaitThreshold == 0) + { + // try to wake up the server + wakeupServer(_status); + } } } } return _status; } + + private void wakeupServer(DataElement status) + { + if (status != null) + { + // token command to wake up update handler + DataElement cmdDescriptor = _dataStore.findCommandDescriptor("C_REFRESH"); //$NON-NLS-1$ + DataElement subject = status.getParent().get(0); + if (cmdDescriptor != null) + { + _dataStore.command(cmdDescriptor, subject); + } + } + } public void cancelDownload() {