Prefinal local endpoint context override

This commit is contained in:
2025-05-05 14:37:17 +03:00
parent c384b18c5a
commit cc5f82c7e7
9 changed files with 27 additions and 28 deletions
+2 -3
View File
@@ -7,7 +7,6 @@ using mROA.Codegen;
using mROA.Implementation;
using mROA.Implementation.Backend;
using mROA.Implementation.Bootstrap;
using mROA.Implementation.Frontend;
class Program
{
@@ -24,11 +23,11 @@ class Program
builder.GetModule<IIdentityGenerator>()!);
builder.Modules.Add(new UdpGateway(listening));
builder.Modules.Add(new ConnectionHub());
builder.Modules.Add(new HubRequestExtractor(typeof(RequestExtractor)));
builder.Modules.Add(new HubRequestExtractor());
builder.UseBasicExecution();
builder.Modules.Add(new CreativeRepresentationModuleProducer(
new IInjectableModule[] { builder.GetModule<ISerializationToolkit>()! },
new IInjectableModule[] { builder.GetModule<IContextualSerializationToolKit>()! },
typeof(RepresentationModule)));
builder.Modules.Add(new RemoteContextRepository());
// builder.UseCollectableContextRepository(typeof(PrinterFactory).Assembly);
+1 -1
View File
@@ -8,7 +8,7 @@ namespace mROA.Abstract
int HostId { get; set; }
int ResisterObject<T>(object o, IEndPointContext context);
void ClearObject(ComplexObjectIdentifier id);
T GetObject<T>(ComplexObjectIdentifier id);
T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context);
object GetSingleObject(Type type, int ownerId);
int GetObjectIndex<T>(object o, IEndPointContext context);
}
@@ -49,7 +49,7 @@ namespace mROA.Implementation.Backend
if (invoker == null)
throw new Exception($"Command {command.CommandId} not found");
var context = GetContext(command, contextRepository, invoker);
var context = GetContext(command, contextRepository, invoker, endPointContext);
if (context == null)
throw new NullReferenceException("Instance can't be null");
@@ -96,10 +96,10 @@ namespace mROA.Implementation.Backend
}
private static object GetContext(ICallRequest command, IContextRepository contextRepository,
IMethodInvoker invoker)
IMethodInvoker invoker, IEndPointContext endPointContext)
{
var context = command.ObjectId.ContextId != -1
? contextRepository.GetObject<object>(command.ObjectId)
? contextRepository.GetObject<object>(command.ObjectId, endPointContext)
: contextRepository.GetSingleObject(invoker.SuitableType, command.ObjectId.OwnerId);
return context;
}
@@ -44,7 +44,7 @@ namespace mROA.Implementation.Backend
_storage.Free(id.ContextId);
}
public T GetObject<T>(ComplexObjectIdentifier id)
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
{
var value = _storage.GetValue(id.ContextId);
@@ -1,5 +1,5 @@
using System;
using mROA.Abstract;
using mROA.Implementation.Frontend;
namespace mROA.Implementation.Backend
{
@@ -12,12 +12,6 @@ namespace mROA.Implementation.Backend
private IMethodRepository? _methodRepository;
private IContextualSerializationToolKit? _serializationToolkit;
private IExecuteModule? _executeModule;
private readonly Type _extractorType;
public HubRequestExtractor(Type extractorType)
{
_extractorType = extractorType;
}
public void Inject<T>(T dependency)
{
@@ -49,7 +43,7 @@ namespace mROA.Implementation.Backend
private void HubOnOnConnected(IRepresentationModule interaction)
{
var extractor = CreateExtractor(interaction);
extractor.StartExtraction().ContinueWith(t => OnDisconnected(interaction));
extractor.StartExtraction().ContinueWith(_ => OnDisconnected(interaction));
}
private void OnDisconnected(IRepresentationModule representationModule)
@@ -60,16 +54,22 @@ namespace mROA.Implementation.Backend
private IRequestExtractor CreateExtractor(IRepresentationModule interaction)
{
var extractor = (IRequestExtractor)Activator.CreateInstance(_extractorType)!;
var extractor = new RequestExtractor();
var context = new EndPointContext
{
HostId = 0, OwnerId = interaction.Id
};
extractor.Inject(interaction);
if (_contextRepository is IContextRepositoryHub contextHub)
extractor.Inject(contextHub.GetRepository(interaction.Id));
context.RealRepository = contextHub.GetRepository(interaction.Id);
else
extractor.Inject(interaction);
context.RealRepository = _contextRepository!;
context.RemoteRepository = _remoteContextRepository!;
extractor.Inject(_methodRepository);
extractor.Inject(_serializationToolkit);
extractor.Inject(_executeModule);
extractor.Inject(_remoteContextRepository);
return extractor;
}
}
@@ -32,10 +32,10 @@ namespace mROA.Implementation.Backend
repository.ClearObject(id);
}
public T GetObject<T>(ComplexObjectIdentifier id)
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
{
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
return repository.GetObject<T>(id);
return repository.GetObject<T>(id, context);
}
public object GetSingleObject(Type type, int ownerId)
@@ -52,7 +52,7 @@ namespace mROA.Implementation
_storages.Find(i => i.Key == id.OwnerId).Value.Free(id.ContextId);
}
public T GetObject<T>(ComplexObjectIdentifier id)
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
{
throw new NotImplementedException();
}
@@ -23,7 +23,7 @@ namespace mROA.Implementation
throw new NotSupportedException();
}
public T GetObject<T>(ComplexObjectIdentifier id)
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
{
var index = _producedRemoteEndpoints.Find(i => i.Identifier.Equals(id));
if (index is not null)
@@ -35,7 +35,7 @@ namespace mROA.Implementation
var representationModule =
_representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId());
var remote = (T)Activator.CreateInstance(remoteType, id.ContextId,
representationModule)!;
representationModule, context)!;
_producedRemoteEndpoints.Add((remote as RemoteObjectBase)!);
+1 -1
View File
@@ -77,7 +77,7 @@ namespace mROA.Implementation
set
{
_identifier = value;
Value = GetDefaultContextRepository().GetObject<T>(Identifier);
Value = GetDefaultContextRepository().GetObject<T>(Identifier, EndPointContext);
}
}