Skip to content

Commit

Permalink
Merge pull request #45796 from tmat/RemotableDataServiceRef
Browse files Browse the repository at this point in the history
RemotableDataService refactoring
  • Loading branch information
tmat authored Jul 10, 2020
2 parents ecd7f38 + a9cc2aa commit e5a8db4
Show file tree
Hide file tree
Showing 7 changed files with 588 additions and 570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public async Task TestCancellationOnSessionWithSolution()
Assert.Equal(exception.CancellationToken, source.Token);

// make sure things that should have been cleaned up are cleaned up
Assert.Null(await ((RemotableDataServiceFactory.Service)service).TestOnly_GetRemotableDataAsync(solutionChecksum, CancellationToken.None).ConfigureAwait(false));
Assert.Null(await ((RemotableDataService)service).TestOnly_GetRemotableDataAsync(solutionChecksum, CancellationToken.None).ConfigureAwait(false));
}
}

Expand Down
72 changes: 72 additions & 0 deletions src/Workspaces/Core/Portable/Execution/RemotableDataService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable

using System;
using System.Collections.Generic;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;

namespace Microsoft.CodeAnalysis.Execution
{
internal sealed class RemotableDataService : IRemotableDataService
{
[ExportWorkspaceServiceFactory(typeof(IRemotableDataService)), Shared]
internal sealed class Factory : IWorkspaceServiceFactory
{
private readonly AssetStorages _assetStorages = new AssetStorages();

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public Factory()
{
}

public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
=> new RemotableDataService(_assetStorages);
}

private readonly AssetStorages _assetStorages;

private RemotableDataService(AssetStorages storages)
{
_assetStorages = storages;
}

public async ValueTask<PinnedRemotableDataScope> CreatePinnedRemotableDataScopeAsync(Solution solution, CancellationToken cancellationToken)
{
using (Logger.LogBlock(FunctionId.SolutionSynchronizationServiceFactory_CreatePinnedRemotableDataScopeAsync, cancellationToken))
{
var storage = AssetStorages.CreateStorage(solution.State);
var checksum = await solution.State.GetChecksumAsync(cancellationToken).ConfigureAwait(false);

return PinnedRemotableDataScope.Create(_assetStorages, storage, checksum);
}
}

public async ValueTask<RemotableData?> GetRemotableDataAsync(int scopeId, Checksum checksum, CancellationToken cancellationToken)
{
using (Logger.LogBlock(FunctionId.SolutionSynchronizationService_GetRemotableData, Checksum.GetChecksumLogInfo, checksum, cancellationToken))
{
return await _assetStorages.GetRemotableDataAsync(scopeId, checksum, cancellationToken).ConfigureAwait(false);
}
}

public async ValueTask<IReadOnlyDictionary<Checksum, RemotableData>> GetRemotableDataAsync(int scopeId, IEnumerable<Checksum> checksums, CancellationToken cancellationToken)
{
using (Logger.LogBlock(FunctionId.SolutionSynchronizationService_GetRemotableData, Checksum.GetChecksumsLogInfo, checksums, cancellationToken))
{
return await _assetStorages.GetRemotableDataAsync(scopeId, checksums, cancellationToken).ConfigureAwait(false);
}
}

public async ValueTask<RemotableData?> TestOnly_GetRemotableDataAsync(Checksum checksum, CancellationToken cancellationToken)
=> await _assetStorages.TestOnly_GetRemotableDataAsync(checksum, cancellationToken).ConfigureAwait(false);
}
}

This file was deleted.

Loading

0 comments on commit e5a8db4

Please sign in to comment.