public <T> T executeRequest( ProviderRequest request )
{
int retryCount = 0;
boolean successful = false;
T output = null;
ProviderRequestStatus status = new ProviderRequestStatus( request );
do
{
try
{
output = (T)request.invoke( status );
successful = true;
}
catch ( Throwable ex )
{
successful = false;
if ( retryCount >= _retryCount )
{
if ( status.getStatus( ) != Status.ERROR )
{
status.setStatus( Status.ERROR, "Error occurred during operation. " + ex.getMessage( ) );
}
if ( _observer != null )
{
_observer.onFailure( ex );
}
if ( ex instanceof ProviderRequestException )
{
throw (ProviderRequestException) ex;
}
throw new ProviderRequestException(ex);
}
if ( _observer != null )
{
_observer.onRetry( ex, retryCount );
}
sleep( _timeBetweenRetriesMillis );
}
retryCount++;
}
while ( !successful );
if (status.getStatus( ) != Status.COMPLETED)
{
status.setStatus( Status.COMPLETED, "Operation completed successfully." );
}
if ( _observer != null )
{
_observer.onSuccess( status.getElapsedMillis( ) );
}
return output;
}