Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from veena-udayabhanu/master
Browse files Browse the repository at this point in the history
Azure Storage Client Library - 3.0.3
  • Loading branch information
joeg committed Feb 11, 2014
2 parents 048b3d8 + 175f3a4 commit 3c5a6ff
Show file tree
Hide file tree
Showing 45 changed files with 645 additions and 405 deletions.
207 changes: 119 additions & 88 deletions Lib/ClassLibraryCommon/Core/Executor/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace Microsoft.WindowsAzure.Storage.Core.Executor
{
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Core;
using Microsoft.WindowsAzure.Storage.Core.Util;
using Microsoft.WindowsAzure.Storage.RetryPolicies;
Expand Down Expand Up @@ -81,23 +82,20 @@ public static void InitRequest<T>(ExecutionState<T> executionState)
return;
}

lock (executionState.CancellationLockerObject)
if (Executor.CheckCancellation(executionState))
{
if (Executor.CheckCancellation(executionState))
{
Executor.EndOperation(executionState);
return;
}
Executor.EndOperation(executionState);
return;
}

// 5. potentially upload data
if (executionState.RestCMD.SendStream != null)
{
Executor.BeginGetRequestStream(executionState);
}
else
{
Executor.BeginGetResponse(executionState);
}
// 5. potentially upload data
if (executionState.RestCMD.SendStream != null)
{
Executor.BeginGetRequestStream(executionState);
}
else
{
Executor.BeginGetResponse(executionState);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -198,39 +196,36 @@ private static void EndSendStreamCopy<T>(ExecutionState<T> executionState)
{
executionState.CurrentOperation = ExecutorOperation.EndUploadRequest;

lock (executionState.CancellationLockerObject)
{
Executor.CheckCancellation(executionState);
Executor.CheckCancellation(executionState);

if (executionState.ExceptionRef != null)
if (executionState.ExceptionRef != null)
{
try
{
try
{
executionState.Req.Abort();
}
catch (Exception)
{
// No op
}

Executor.EndOperation(executionState);
executionState.Req.Abort();
}
else
catch (Exception)
{
try
{
executionState.ReqStream.Flush();
executionState.ReqStream.Dispose();
executionState.ReqStream = null;
}
catch (Exception)
{
// If we could not flush/dispose the request stream properly,
// BeginGetResponse will fail with a more meaningful error anyway.
}
// No op
}

Executor.BeginGetResponse(executionState);
Executor.EndOperation(executionState);
}
else
{
try
{
executionState.ReqStream.Flush();
executionState.ReqStream.Dispose();
executionState.ReqStream = null;
}
catch (Exception)
{
// If we could not flush/dispose the request stream properly,
// BeginGetResponse will fail with a more meaningful error anyway.
}

Executor.BeginGetResponse(executionState);
}
}
#endregion
Expand Down Expand Up @@ -289,7 +284,8 @@ private static void EndGetResponse<T>(IAsyncResult getResponseResult)
}
else
{
executionState.ExceptionRef = ExecutorBase.TranslateExceptionBasedOnParseError(ex, executionState.Cmd.CurrentResult, executionState.Resp, executionState.Cmd.ParseError);
// Store this exception for now. It will be parsed/thrown after the stream is read in step 8
executionState.ExceptionRef = ex;
}
}

Expand All @@ -300,21 +296,37 @@ private static void EndGetResponse<T>(IAsyncResult getResponseResult)
if (executionState.RestCMD.PreProcessResponse != null)
{
executionState.CurrentOperation = ExecutorOperation.PreProcess;
executionState.Result = executionState.RestCMD.PreProcessResponse(executionState.RestCMD, executionState.Resp, executionState.ExceptionRef, executionState.OperationContext);

// clear exception
executionState.ExceptionRef = null;
Logger.LogInformational(executionState.OperationContext, SR.TracePreProcessDone);
try
{
executionState.Result = executionState.RestCMD.PreProcessResponse(executionState.RestCMD, executionState.Resp, executionState.ExceptionRef, executionState.OperationContext);

// clear exception
executionState.ExceptionRef = null;
Logger.LogInformational(executionState.OperationContext, SR.TracePreProcessDone);
}
catch (Exception ex)
{
executionState.ExceptionRef = ex;
}
}

Executor.CheckCancellation(executionState);

executionState.CurrentOperation = ExecutorOperation.GetResponseStream;
executionState.RestCMD.ResponseStream = executionState.Resp.GetResponseStream();

// 8. (Potentially reads stream from server)
if (executionState.ExceptionRef == null)
if (executionState.ExceptionRef != null)
{
executionState.CurrentOperation = ExecutorOperation.GetResponseStream;
executionState.RestCMD.ResponseStream = executionState.Resp.GetResponseStream();
executionState.CurrentOperation = ExecutorOperation.BeginDownloadResponse;
Logger.LogInformational(executionState.OperationContext, SR.TraceDownloadError);

executionState.RestCMD.ErrorStream = new MemoryStream();
executionState.RestCMD.ResponseStream.WriteToAsync(executionState.RestCMD.ErrorStream, null /* copyLength */, null /* maxLength */, false /* calculateMd5 */, executionState, new StreamDescriptor(), EndResponseStreamCopy);
}
else
{
if (!executionState.RestCMD.RetrieveResponseStream)
{
executionState.RestCMD.DestinationStream = Stream.Null;
Expand All @@ -337,11 +349,6 @@ private static void EndGetResponse<T>(IAsyncResult getResponseResult)
Executor.EndOperation(executionState);
}
}
else
{
// End
Executor.EndOperation(executionState);
}
}
catch (Exception ex)
{
Expand All @@ -353,6 +360,32 @@ private static void EndGetResponse<T>(IAsyncResult getResponseResult)

private static void EndResponseStreamCopy<T>(ExecutionState<T> executionState)
{
// At this time, the response/error stream has been read. So try to parse the error if there was en exception
if (executionState.RestCMD.ErrorStream != null)
{
executionState.RestCMD.ErrorStream.Seek(0, SeekOrigin.Begin);
if (executionState.Cmd.ParseError != null)
{
executionState.ExceptionRef = StorageException.TranslateExceptionWithPreBufferedStream(executionState.ExceptionRef, executionState.Cmd.CurrentResult, stream => executionState.Cmd.ParseError(stream, executionState.Resp, null), executionState.RestCMD.ErrorStream);
}
else
{
executionState.ExceptionRef = StorageException.TranslateExceptionWithPreBufferedStream(executionState.ExceptionRef, executionState.Cmd.CurrentResult, null, executionState.RestCMD.ErrorStream);
}

// Dispose the stream and end the operation
try
{
executionState.RestCMD.ErrorStream.Dispose();
executionState.RestCMD.ErrorStream = null;
}
catch (Exception)
{
// no-op
}
}

// Dispose the stream and end the operation
try
{
if (executionState.RestCMD.ResponseStream != null)
Expand All @@ -367,6 +400,7 @@ private static void EndResponseStreamCopy<T>(ExecutionState<T> executionState)
}

executionState.CurrentOperation = ExecutorOperation.EndDownloadResponse;

Executor.EndOperation(executionState);
}
#endregion
Expand All @@ -377,49 +411,46 @@ private static void EndOperation<T>(ExecutionState<T> executionState)
{
Executor.FinishRequestAttempt(executionState);

lock (executionState.CancellationLockerObject)
try
{
try
{
// If an operation has been canceled of timed out this should overwrite any exception
Executor.CheckCancellation(executionState);
Executor.CheckTimeout(executionState, true);
// If an operation has been canceled of timed out this should overwrite any exception
Executor.CheckCancellation(executionState);
Executor.CheckTimeout(executionState, true);

// Success
if (executionState.ExceptionRef == null)
{
// Step 9 - This will not be called if an exception is raised during stream copying
Executor.ProcessEndOfRequest(executionState);
executionState.OnComplete();
return;
}
}
catch (Exception ex)
// Success
if (executionState.ExceptionRef == null)
{
Logger.LogWarning(executionState.OperationContext, SR.TracePostProcessError, ex.Message);
executionState.ExceptionRef = ExecutorBase.TranslateExceptionBasedOnParseError(ex, executionState.Cmd.CurrentResult, executionState.Resp, executionState.Cmd.ParseError);
// Step 9 - This will not be called if an exception is raised during stream copying
Executor.ProcessEndOfRequest(executionState);
executionState.OnComplete();
return;
}
finally
}
catch (Exception ex)
{
Logger.LogWarning(executionState.OperationContext, SR.TracePostProcessError, ex.Message);
executionState.ExceptionRef = ExecutorBase.TranslateExceptionBasedOnParseError(ex, executionState.Cmd.CurrentResult, executionState.Resp, executionState.Cmd.ParseError);
}
finally
{
try
{
try
if (executionState.ReqStream != null)
{
if (executionState.ReqStream != null)
{
executionState.ReqStream.Dispose();
executionState.ReqStream = null;
}

if (executionState.Resp != null)
{
executionState.Resp.Close();
executionState.Resp = null;
}
executionState.ReqStream.Dispose();
executionState.ReqStream = null;
}
catch (Exception)

if (executionState.Resp != null)
{
// no op
executionState.Resp.Close();
executionState.Resp = null;
}
}
catch (Exception)
{
// no op
}
}

// Handle Retry
Expand Down
Loading

0 comments on commit 3c5a6ff

Please sign in to comment.