Create new top-level DefaultNodeInstance concept that will soon hold the "connection draining" logic

This commit is contained in:
SteveSandersonMS
2016-07-06 18:23:25 +01:00
parent 4ee09cbe82
commit 4fb3b18868
19 changed files with 210 additions and 89 deletions

View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Microsoft.AspNetCore.NodeServices
namespace Microsoft.AspNetCore.NodeServices.HostingModels
{
internal class HttpNodeInstance : OutOfProcessNodeInstance
{
@@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.NodeServices
return result;
}
public override async Task<T> Invoke<T>(NodeInvocationInfo invocationInfo)
protected override async Task<T> InvokeExportAsync<T>(NodeInvocationInfo invocationInfo)
{
await EnsureReady();

View File

@@ -0,0 +1,10 @@
using System;
using System.Threading.Tasks;
namespace Microsoft.AspNetCore.NodeServices.HostingModels
{
public interface INodeInstance : IDisposable
{
Task<T> InvokeExportAsync<T>(string moduleName, string exportNameOrNull, params object[] args);
}
}

View File

@@ -1,6 +1,6 @@
using System;
namespace Microsoft.AspNetCore.NodeServices
namespace Microsoft.AspNetCore.NodeServices.HostingModels
{
public class NodeInvocationException : Exception
{

View File

@@ -1,4 +1,4 @@
namespace Microsoft.AspNetCore.NodeServices
namespace Microsoft.AspNetCore.NodeServices.HostingModels
{
public class NodeInvocationInfo
{

View File

@@ -3,14 +3,14 @@ using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
namespace Microsoft.AspNetCore.NodeServices
namespace Microsoft.AspNetCore.NodeServices.HostingModels
{
/// <summary>
/// Class responsible for launching the Node child process, determining when it is ready to accept invocations,
/// and finally killing it when the parent process exits. Also it restarts the child process if it dies.
/// </summary>
/// <seealso cref="Microsoft.AspNetCore.NodeServices.INodeServices" />
public abstract class OutOfProcessNodeInstance : INodeServices
/// <seealso cref="Microsoft.AspNetCore.NodeServices.INodeInstance" />
public abstract class OutOfProcessNodeInstance : INodeInstance
{
private readonly object _childProcessLauncherLock;
private string _commandLineArguments;
@@ -34,15 +34,12 @@ namespace Microsoft.AspNetCore.NodeServices
set { _commandLineArguments = value; }
}
public Task<T> Invoke<T>(string moduleName, params object[] args)
=> InvokeExport<T>(moduleName, null, args);
public Task<T> InvokeExport<T>(string moduleName, string exportedFunctionName, params object[] args)
public Task<T> InvokeExportAsync<T>(string moduleName, string exportNameOrNull, params object[] args)
{
return Invoke<T>(new NodeInvocationInfo
return InvokeExportAsync<T>(new NodeInvocationInfo
{
ModuleName = moduleName,
ExportedFunctionName = exportedFunctionName,
ExportedFunctionName = exportNameOrNull,
Args = args
});
}
@@ -53,7 +50,7 @@ namespace Microsoft.AspNetCore.NodeServices
GC.SuppressFinalize(this);
}
public abstract Task<T> Invoke<T>(NodeInvocationInfo invocationInfo);
protected abstract Task<T> InvokeExportAsync<T>(NodeInvocationInfo invocationInfo);
protected void ExitNodeProcess()
{

View File

@@ -8,7 +8,7 @@ using Microsoft.AspNetCore.NodeServices.HostingModels.VirtualConnections;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Microsoft.AspNetCore.NodeServices
namespace Microsoft.AspNetCore.NodeServices.HostingModels
{
internal class SocketNodeInstance : OutOfProcessNodeInstance
{
@@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.NodeServices
_watchFileExtensions = watchFileExtensions;
}
public override async Task<T> Invoke<T>(NodeInvocationInfo invocationInfo)
protected override async Task<T> InvokeExportAsync<T>(NodeInvocationInfo invocationInfo)
{
await EnsureReady();
var virtualConnectionClient = await GetOrCreateVirtualConnectionClientAsync();