Remove ICallRequest
This commit is contained in:
@@ -10,7 +10,7 @@ using mROA.Implementation;
|
|||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
var test = new CborTest();
|
var test = new CborTest();
|
||||||
test.ArrayWrite();
|
test.ArrayWrite();
|
||||||
BenchmarkRunner.Run<CborTest>();
|
BenchmarkRunner.Run<VirtualOverhead>();
|
||||||
|
|
||||||
public static class CborExtensions
|
public static class CborExtensions
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using mROA.Implementation;
|
||||||
|
|
||||||
|
namespace mROA.Benchmark;
|
||||||
|
|
||||||
|
public class VirtualOverhead
|
||||||
|
{
|
||||||
|
private ICallRequest _request;
|
||||||
|
private CallRequest _directRequest;
|
||||||
|
private RawCallRequest _rawRequest;
|
||||||
|
|
||||||
|
public VirtualOverhead()
|
||||||
|
{
|
||||||
|
_request = new CallRequest
|
||||||
|
{
|
||||||
|
CommandId = 5, Id = new RequestId(), ObjectId = ComplexObjectIdentifier.Null, Parameters = null
|
||||||
|
};
|
||||||
|
_directRequest = (CallRequest)_request;
|
||||||
|
_rawRequest = new RawCallRequest
|
||||||
|
{
|
||||||
|
CommandId = _directRequest.CommandId, Id = _directRequest.Id, ObjectId = _directRequest.ObjectId,
|
||||||
|
Parameters = null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark(Baseline = true)]
|
||||||
|
public long VirtualUsage()
|
||||||
|
{
|
||||||
|
var req = _request;
|
||||||
|
long acc = 0;
|
||||||
|
acc += req.CommandId;
|
||||||
|
acc += (long)(req.Id.P1 + req.Id.P0);
|
||||||
|
acc += req.ObjectId.ContextId + req.ObjectId.OwnerId;
|
||||||
|
acc += (req.Parameters ?? []).Length;
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public long DirectUsage()
|
||||||
|
{
|
||||||
|
var req = _directRequest;
|
||||||
|
long acc = 0;
|
||||||
|
acc += req.CommandId;
|
||||||
|
acc += (long)(req.Id.P1 + req.Id.P0);
|
||||||
|
acc += req.ObjectId.ContextId + req.ObjectId.OwnerId;
|
||||||
|
acc += (req.Parameters ?? []).Length;
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public long RawUsage()
|
||||||
|
{
|
||||||
|
var req = _rawRequest;
|
||||||
|
long acc = 0;
|
||||||
|
acc += req.CommandId;
|
||||||
|
acc += (long)(req.Id.P1 + req.Id.P0);
|
||||||
|
acc += req.ObjectId.ContextId + req.ObjectId.OwnerId;
|
||||||
|
acc += (req.Parameters ?? []).Length;
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct RawCallRequest
|
||||||
|
{
|
||||||
|
public RequestId Id;
|
||||||
|
public int CommandId;
|
||||||
|
public ComplexObjectIdentifier ObjectId;
|
||||||
|
|
||||||
|
public object?[]? Parameters;
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Call request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
private readonly IOrdinaryStructureParser[] _parsers =
|
private readonly IOrdinaryStructureParser[] _parsers =
|
||||||
{
|
{
|
||||||
new DefaultCallRequestParser(), new FinalCommandExecutionParser(),
|
new CallRequestParser(), new FinalCommandExecutionParser(),
|
||||||
new FinalCommandExecutionResultlessParser()
|
new FinalCommandExecutionResultlessParser()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
private bool FindParser(Type t, out IOrdinaryStructureParser parser)
|
private bool FindParser(Type t, out IOrdinaryStructureParser parser)
|
||||||
{
|
{
|
||||||
if (t == typeof(DefaultCallRequest))
|
if (t == typeof(CallRequest))
|
||||||
{
|
{
|
||||||
parser = _parsers[0];
|
parser = _parsers[0];
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ namespace mROA.Cbor
|
|||||||
object Read(CborReader reader, IEndPointContext context, CborSerializationToolkit serialization);
|
object Read(CborReader reader, IEndPointContext context, CborSerializationToolkit serialization);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DefaultCallRequestParser : IOrdinaryStructureParser
|
public class CallRequestParser : IOrdinaryStructureParser
|
||||||
{
|
{
|
||||||
public void Write(CborWriter writer, object value, IEndPointContext context, CborSerializationToolkit serialization)
|
public void Write(CborWriter writer, object value, IEndPointContext context, CborSerializationToolkit serialization)
|
||||||
{
|
{
|
||||||
var v = (DefaultCallRequest)value;
|
var v = (CallRequest)value;
|
||||||
writer.WriteStartArray(4);
|
writer.WriteStartArray(4);
|
||||||
v.Id.WriteToCborInline(writer);
|
v.Id.WriteToCborInline(writer);
|
||||||
// writer.WriteByteString(v.Id.ToByteArray());
|
// writer.WriteByteString(v.Id.ToByteArray());
|
||||||
@@ -31,7 +31,7 @@ namespace mROA.Cbor
|
|||||||
public object Read(CborReader reader, IEndPointContext context, CborSerializationToolkit serialization)
|
public object Read(CborReader reader, IEndPointContext context, CborSerializationToolkit serialization)
|
||||||
{
|
{
|
||||||
reader.ReadStartArray();
|
reader.ReadStartArray();
|
||||||
var value = new DefaultCallRequest
|
var value = new CallRequest
|
||||||
{
|
{
|
||||||
Id = new RequestId(reader.ReadByteString()),
|
Id = new RequestId(reader.ReadByteString()),
|
||||||
CommandId = reader.ReadInt32(),
|
CommandId = reader.ReadInt32(),
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace mROA.Codegen
|
|||||||
Console.WriteLine($"Try to send to {ownerId} with hash code {context.GetHashCode()}");
|
Console.WriteLine($"Try to send to {ownerId} with hash code {context.GetHashCode()}");
|
||||||
<!I callFilter>
|
<!I callFilter>
|
||||||
Console.WriteLine("Sending event...");
|
Console.WriteLine("Sending event...");
|
||||||
var request = new DefaultCallRequest
|
var request = new CallRequest
|
||||||
{
|
{
|
||||||
Id = RequestId.Generate(),
|
Id = RequestId.Generate(),
|
||||||
CommandId = <!L commandId>,
|
CommandId = <!L commandId>,
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
|
using mROA.Implementation.CommandExecution;
|
||||||
|
|
||||||
namespace mROA.Abstract
|
namespace mROA.Abstract
|
||||||
{
|
{
|
||||||
public interface IExecuteModule
|
public interface IExecuteModule
|
||||||
{
|
{
|
||||||
ICommandExecution? Execute(ICallRequest command, IInstanceRepository instanceRepository,
|
ICommandExecution? Execute(CallRequest command, IInstanceRepository instanceRepository,
|
||||||
IRepresentationModule representationModule, IEndPointContext context);
|
IRepresentationModule representationModule, IEndPointContext context);
|
||||||
|
ICommandExecution Cancel(CancelRequest command);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,17 +19,12 @@ namespace mROA.Implementation.Backend
|
|||||||
_serialization = serialization;
|
_serialization = serialization;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommandExecution? Execute(ICallRequest command, IInstanceRepository instanceRepository,
|
public ICommandExecution? Execute(CallRequest command, IInstanceRepository instanceRepository,
|
||||||
IRepresentationModule representationModule, IEndPointContext endPointContext)
|
IRepresentationModule representationModule, IEndPointContext endPointContext)
|
||||||
{
|
{
|
||||||
// _logger.LogInformation("Executing {0}", command.Id);
|
// _logger.LogInformation("Executing {0}", command.Id);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (command is CancelRequest)
|
|
||||||
{
|
|
||||||
return CancelExecution(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
var invoker = _methodRepo.GetMethod(command.CommandId);
|
var invoker = _methodRepo.GetMethod(command.CommandId);
|
||||||
if (invoker == null)
|
if (invoker == null)
|
||||||
throw new Exception($"Command {command.CommandId} not found");
|
throw new Exception($"Command {command.CommandId} not found");
|
||||||
@@ -63,7 +58,7 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICommandExecution? ExecuteRequest(ICallRequest command, IInstanceRepository instanceRepository,
|
private ICommandExecution? ExecuteRequest(CallRequest command, IInstanceRepository instanceRepository,
|
||||||
IRepresentationModule representationModule, IEndPointContext endPointContext, IMethodInvoker invoker,
|
IRepresentationModule representationModule, IEndPointContext endPointContext, IMethodInvoker invoker,
|
||||||
object context, object?[]? castedParams, RequestContext execContext)
|
object context, object?[]? castedParams, RequestContext execContext)
|
||||||
{
|
{
|
||||||
@@ -87,7 +82,7 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static object GetInstance(ICallRequest command, IInstanceRepository instanceRepository,
|
private static object GetInstance(CallRequest command, IInstanceRepository instanceRepository,
|
||||||
IMethodInvoker invoker, IEndPointContext endPointContext)
|
IMethodInvoker invoker, IEndPointContext endPointContext)
|
||||||
{
|
{
|
||||||
var context = command.ObjectId.ContextId != -1
|
var context = command.ObjectId.ContextId != -1
|
||||||
@@ -97,7 +92,7 @@ namespace mROA.Implementation.Backend
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
private object?[] CastedParams(ICallRequest command, IMethodInvoker invoker, IEndPointContext context)
|
private object?[] CastedParams(CallRequest command, IMethodInvoker invoker, IEndPointContext context)
|
||||||
{
|
{
|
||||||
object?[] castedParams = new object[invoker.ParameterTypes.Length];
|
object?[] castedParams = new object[invoker.ParameterTypes.Length];
|
||||||
for (var i = 0; i < castedParams.Length; i++)
|
for (var i = 0; i < castedParams.Length; i++)
|
||||||
@@ -108,7 +103,7 @@ namespace mROA.Implementation.Backend
|
|||||||
return castedParams;
|
return castedParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FinalCommandExecution CancelExecution(ICallRequest command)
|
public ICommandExecution Cancel(CancelRequest command)
|
||||||
{
|
{
|
||||||
var cts = _cancellationRepo.GetCancellation(command.Id);
|
var cts = _cancellationRepo.GetCancellation(command.Id);
|
||||||
if (cts == null)
|
if (cts == null)
|
||||||
@@ -123,7 +118,7 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ICommandExecution? Execute(MethodInvoker invoker, object instance, object?[] parameter,
|
private static ICommandExecution? Execute(MethodInvoker invoker, object instance, object?[] parameter,
|
||||||
ICallRequest command, RequestContext executionContext)
|
CallRequest command, RequestContext executionContext)
|
||||||
{
|
{
|
||||||
var finalResult = invoker.Invoke(instance, parameter, new object[] { executionContext });
|
var finalResult = invoker.Invoke(instance, parameter, new object[] { executionContext });
|
||||||
|
|
||||||
@@ -148,7 +143,7 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ICommandExecution? ExecuteAsync(AsyncMethodInvoker invoker, object instance, object?[]? parameters,
|
private ICommandExecution? ExecuteAsync(AsyncMethodInvoker invoker, object instance, object?[]? parameters,
|
||||||
ICallRequest command, ICancellationRepository cancellationRepository,
|
CallRequest command, ICancellationRepository cancellationRepository,
|
||||||
IRepresentationModule representationModule, RequestContext executionContext, IEndPointContext context)
|
IRepresentationModule representationModule, RequestContext executionContext, IEndPointContext context)
|
||||||
{
|
{
|
||||||
var tokenSource = new CancellationTokenSource();
|
var tokenSource = new CancellationTokenSource();
|
||||||
@@ -177,7 +172,7 @@ namespace mROA.Implementation.Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ICommandExecution? TypedExecuteAsync(AsyncMethodInvoker invoker, object instance, object?[]? parameters,
|
private ICommandExecution? TypedExecuteAsync(AsyncMethodInvoker invoker, object instance, object?[]? parameters,
|
||||||
ICallRequest command, ICancellationRepository cancellationRepository,
|
CallRequest command, ICancellationRepository cancellationRepository,
|
||||||
IRepresentationModule representationModule, RequestContext executionContext, IEndPointContext context)
|
IRepresentationModule representationModule, RequestContext executionContext, IEndPointContext context)
|
||||||
{
|
{
|
||||||
var tokenSource = new CancellationTokenSource();
|
var tokenSource = new CancellationTokenSource();
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace mROA.Implementation.Backend
|
|||||||
{
|
{
|
||||||
await foreach (var post in interaction.UntrustedPostChanel.ReadAllAsync())
|
await foreach (var post in interaction.UntrustedPostChanel.ReadAllAsync())
|
||||||
{
|
{
|
||||||
if (post.MessageType is not (CallRequest or EMessageType.CancelRequest
|
if (post.MessageType is not (EMessageType.CallRequest or EMessageType.CancelRequest
|
||||||
or EventRequest))
|
or EventRequest))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,9 @@
|
|||||||
|
|
||||||
namespace mROA.Implementation
|
namespace mROA.Implementation
|
||||||
{
|
{
|
||||||
public interface ICallRequest
|
|
||||||
{
|
|
||||||
RequestId Id { get; }
|
|
||||||
int CommandId { get; }
|
|
||||||
ComplexObjectIdentifier ObjectId { get; }
|
|
||||||
object?[]? Parameters { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct DefaultCallRequest : ICallRequest
|
|
||||||
|
public struct CallRequest
|
||||||
{
|
{
|
||||||
public RequestId Id { get; set; }
|
public RequestId Id { get; set; }
|
||||||
public int CommandId { get; set; }
|
public int CommandId { get; set; }
|
||||||
@@ -24,16 +18,8 @@ namespace mROA.Implementation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CancelRequest : ICallRequest
|
public struct CancelRequest
|
||||||
{
|
{
|
||||||
public RequestId Id { get; set; }
|
public RequestId Id { get; set; }
|
||||||
public int CommandId { get; set; } = -2;
|
|
||||||
public ComplexObjectIdentifier ObjectId { get; set; } = ComplexObjectIdentifier.Null;
|
|
||||||
public object?[]? Parameters { get; set; } = null;
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"Cancel request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,15 +41,15 @@ namespace mROA.Implementation.Frontend
|
|||||||
switch (originalType)
|
switch (originalType)
|
||||||
{
|
{
|
||||||
case EMessageType.CallRequest:
|
case EMessageType.CallRequest:
|
||||||
HandleCallRequest((DefaultCallRequest)parced);
|
HandleCallRequest((CallRequest)parced);
|
||||||
break;
|
break;
|
||||||
case EMessageType.ClientDisconnect:
|
case EMessageType.ClientDisconnect:
|
||||||
return;
|
return;
|
||||||
case EMessageType.EventRequest:
|
case EMessageType.EventRequest:
|
||||||
HandleEventRequest((DefaultCallRequest)parced);
|
HandleEventRequest((CallRequest)parced);
|
||||||
break;
|
break;
|
||||||
case EMessageType.CancelRequest:
|
case EMessageType.CancelRequest:
|
||||||
HandleCancelRequest((parced as CancelRequest)!);
|
HandleCancelRequest((CancelRequest)parced);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
@@ -62,18 +62,18 @@ namespace mROA.Implementation.Frontend
|
|||||||
|
|
||||||
public Func<NetworkMessage, Type?>[] Converters { get; } =
|
public Func<NetworkMessage, Type?>[] Converters { get; } =
|
||||||
{
|
{
|
||||||
m => m.MessageType == EMessageType.CallRequest ? typeof(DefaultCallRequest) : null,
|
m => m.MessageType == EMessageType.CallRequest ? typeof(CallRequest) : null,
|
||||||
m => m.MessageType == EMessageType.CancelRequest ? typeof(CancelRequest) : null,
|
m => m.MessageType == EMessageType.CancelRequest ? typeof(CancelRequest) : null,
|
||||||
m => m.MessageType == EMessageType.EventRequest ? typeof(DefaultCallRequest) : null,
|
m => m.MessageType == EMessageType.EventRequest ? typeof(CallRequest) : null,
|
||||||
m => m.MessageType == EMessageType.ClientDisconnect ? typeof(ClientDisconnect) : null
|
m => m.MessageType == EMessageType.ClientDisconnect ? typeof(ClientDisconnect) : null
|
||||||
};
|
};
|
||||||
|
|
||||||
private void HandleCancelRequest(CancelRequest req)
|
private void HandleCancelRequest(CancelRequest req)
|
||||||
{
|
{
|
||||||
_executeModule.Execute(req, _context.RealRepository, _representationModule, _context);
|
_executeModule.Cancel(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleCallRequest(DefaultCallRequest request)
|
private void HandleCallRequest(CallRequest request)
|
||||||
{
|
{
|
||||||
var result = _executeModule.Execute(request, _context.RealRepository, _representationModule, _context);
|
var result = _executeModule.Execute(request, _context.RealRepository, _representationModule, _context);
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ namespace mROA.Implementation.Frontend
|
|||||||
_representationModule.PostCallMessageAsync(request.Id, resultType, result, _context).ConfigureAwait(false);
|
_representationModule.PostCallMessageAsync(request.Id, resultType, result, _context).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleEventRequest(DefaultCallRequest request)
|
private void HandleEventRequest(CallRequest request)
|
||||||
{
|
{
|
||||||
_executeModule.Execute(request, _context.RemoteRepository, _representationModule, _context);
|
_executeModule.Execute(request, _context.RemoteRepository, _representationModule, _context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace mROA.Implementation
|
|||||||
protected async Task<T> GetResultAsync<T>(int methodId, object?[]? parameters = null,
|
protected async Task<T> GetResultAsync<T>(int methodId, object?[]? parameters = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var request = new DefaultCallRequest
|
var request = new CallRequest
|
||||||
{
|
{
|
||||||
Id = RequestId.Generate(), CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
Id = RequestId.Generate(), CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
||||||
};
|
};
|
||||||
@@ -100,7 +100,7 @@ namespace mROA.Implementation
|
|||||||
protected async Task CallAsync(int methodId, object?[]? parameters = null,
|
protected async Task CallAsync(int methodId, object?[]? parameters = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var request = new DefaultCallRequest
|
var request = new CallRequest
|
||||||
{
|
{
|
||||||
Id = RequestId.Generate(), CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
Id = RequestId.Generate(), CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
||||||
};
|
};
|
||||||
@@ -147,7 +147,7 @@ namespace mROA.Implementation
|
|||||||
|
|
||||||
protected async Task CallUntrustedAsync(int methodId, object?[]? parameters = null)
|
protected async Task CallUntrustedAsync(int methodId, object?[]? parameters = null)
|
||||||
{
|
{
|
||||||
var request = new DefaultCallRequest
|
var request = new CallRequest
|
||||||
{
|
{
|
||||||
Id = RequestId.Generate(), CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
Id = RequestId.Generate(), CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user