1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 04:55:22 +02:00

[222448] [dstore] update DownloadListener to handle timeouts and nudge

This commit is contained in:
David McKnight 2008-03-12 17:31:09 +00:00
parent f5ec51e020
commit db6618a76f
2 changed files with 62 additions and 11 deletions

View file

@ -288,6 +288,9 @@ public class StatusMonitor implements IDomainListener, ICommunicationsListener
else if ( wait == -1 ) // force a diagnostic else if ( wait == -1 ) // force a diagnostic
WaitThreshold = -1; 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) if (display != null)
{ {
// Current thread is UI thread // Current thread is UI thread
@ -319,8 +322,13 @@ public class StatusMonitor implements IDomainListener, ICommunicationsListener
if (WaitThreshold == 0) if (WaitThreshold == 0)
{ {
wakeupServer(status);
// no diagnostic factory but there is a timeout // no diagnostic factory but there is a timeout
if (nudges >= 12)
return status; // returning the undone status object return status; // returning the undone status object
nudges++;
} }
else if (_networkDown) else if (_networkDown)
{ {
@ -359,8 +367,13 @@ public class StatusMonitor implements IDomainListener, ICommunicationsListener
if (WaitThreshold == 0) if (WaitThreshold == 0)
{ {
wakeupServer(status);
// no diagnostic factory but there is a timeout // no diagnostic factory but there is a timeout
if (nudges >= 12)
return status; // returning the undone status object return status; // returning the undone status object
nudges++;
} }
else if (_networkDown) else if (_networkDown)
{ {
@ -375,6 +388,19 @@ public class StatusMonitor implements IDomainListener, ICommunicationsListener
return 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);
}
}
}
/** /**
* Start diagnostic * Start diagnostic

View file

@ -16,6 +16,7 @@
* David McKnight (IBM) - [197480] eliminating UI dependencies * David McKnight (IBM) - [197480] eliminating UI dependencies
* David McKnight (IBM) - [216252] MessageFormat.format -> NLS.bind * David McKnight (IBM) - [216252] MessageFormat.format -> NLS.bind
* Martin Oberhuber (Wind River) - [219952] Use MessageFormat for download progress message * 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; package org.eclipse.rse.services.dstore.util;
@ -230,14 +231,13 @@ public class DownloadListener implements IDomainListener
*/ */
public DataElement waitForUpdate(int wait) throws InterruptedException 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) if (wait > 0)
{ WaitThreshold = wait * 10; // 1 second means 10 sleep(100ms)
} else if (wait == -1) // force a diagnostic
else if (wait == -1) WaitThreshold = -1;
{
}
{ {
// Current thread is not UI thread // Current thread is not UI thread
@ -263,12 +263,37 @@ public class DownloadListener implements IDomainListener
{ {
Thread.sleep(100); Thread.sleep(100);
updateDownloadState(); 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; 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() public void cancelDownload()
{ {
DataElement status = _status; DataElement status = _status;