Реализовано универсальное хранилище
This commit is contained in:
@@ -481,7 +481,7 @@ namespace {classSymbol.ContainingNamespace.ToDisplayString()}
|
|||||||
{callFilter}
|
{callFilter}
|
||||||
var request = new DefaultCallRequest
|
var request = new DefaultCallRequest
|
||||||
{{
|
{{
|
||||||
CommandId = {index}, ObjectId = new UniversalObjectIdentifier(index, context.OwnerId), Parameters = new object[] {{ {transferParameters} }}
|
CommandId = {index}, ObjectId = new ComplexObjectIdentifier(index, context.OwnerId), Parameters = new object[] {{ {transferParameters} }}
|
||||||
}};
|
}};
|
||||||
module.PostCallMessageAsync(request.Id, MessageType.EventRequest, request);
|
module.PostCallMessageAsync(request.Id, MessageType.EventRequest, request);
|
||||||
}};
|
}};
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ namespace mROA.Abstract
|
|||||||
{
|
{
|
||||||
public interface IContextRepository : IInjectableModule
|
public interface IContextRepository : IInjectableModule
|
||||||
{
|
{
|
||||||
|
int HostId { get; set; }
|
||||||
int ResisterObject<T>(object o, IEndPointContext context);
|
int ResisterObject<T>(object o, IEndPointContext context);
|
||||||
void ClearObject(int id);
|
void ClearObject(ComplexObjectIdentifier id);
|
||||||
T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell);
|
T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell);
|
||||||
T? GetObject<T>(int id);
|
T? GetObject<T>(ComplexObjectIdentifier id);
|
||||||
object GetSingleObject(Type type);
|
object GetSingleObject(Type type);
|
||||||
int GetObjectIndex<T>(object o, IEndPointContext context);
|
int GetObjectIndex<T>(object o, IEndPointContext context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
|
public interface IStorage<T>
|
||||||
|
{
|
||||||
|
T GetValue(int index);
|
||||||
|
int GetIndex(T value);
|
||||||
|
int Place(T value);
|
||||||
|
void Free(int index);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,7 +69,7 @@ namespace mROA.Implementation.Backend
|
|||||||
IContextRepository repository;
|
IContextRepository repository;
|
||||||
|
|
||||||
var context = command.ObjectId.ContextId != -1
|
var context = command.ObjectId.ContextId != -1
|
||||||
? contextRepository.GetObject<object>(command.ObjectId.ContextId)
|
? contextRepository.GetObject<object>(command.ObjectId)
|
||||||
: contextRepository.GetSingleObject(invoker.SuitableType);
|
: contextRepository.GetSingleObject(invoker.SuitableType);
|
||||||
|
|
||||||
if (context == null)
|
if (context == null)
|
||||||
@@ -104,7 +104,7 @@ namespace mROA.Implementation.Backend
|
|||||||
#if TRACE
|
#if TRACE
|
||||||
Console.WriteLine("Disposing object");
|
Console.WriteLine("Disposing object");
|
||||||
#endif
|
#endif
|
||||||
contextRepository.ClearObject(command.ObjectId.ContextId);
|
contextRepository.ClearObject(command.ObjectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ namespace mROA.Implementation.Backend
|
|||||||
_storage = new object[StartupSize];
|
_storage = new object[StartupSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int HostId { get; set; }
|
||||||
|
|
||||||
public int ResisterObject<T>(object o, IEndPointContext context)
|
public int ResisterObject<T>(object o, IEndPointContext context)
|
||||||
{
|
{
|
||||||
if (!_lastIndexFinder.IsCompleted)
|
if (!_lastIndexFinder.IsCompleted)
|
||||||
@@ -47,10 +49,10 @@ namespace mROA.Implementation.Backend
|
|||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearObject(int id)
|
public void ClearObject(ComplexObjectIdentifier id)
|
||||||
{
|
{
|
||||||
_storage[id] = null;
|
_storage[id.ContextId] = null;
|
||||||
_lastIndexFinder = Task.FromResult(id);
|
_lastIndexFinder = Task.FromResult(id.ContextId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
||||||
@@ -58,11 +60,11 @@ namespace mROA.Implementation.Backend
|
|||||||
return (T)GetObject(sharedObjectShellShell.Identifier.ContextId);
|
return (T)GetObject(sharedObjectShellShell.Identifier.ContextId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetObject<T>(int id)
|
public T? GetObject<T>(ComplexObjectIdentifier id)
|
||||||
{
|
{
|
||||||
return id == -1 || _storage.Length <= id
|
return id.ContextId == -1 || _storage.Length <= id.ContextId
|
||||||
? throw new NullReferenceException("Cannot find that object. It is null")
|
? throw new NullReferenceException("Cannot find that object. It is null")
|
||||||
: (T)_storage[id]!;
|
: (T)_storage[id.ContextId]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetSingleObject(Type type)
|
public object GetSingleObject(Type type)
|
||||||
|
|||||||
@@ -18,13 +18,15 @@ namespace mROA.Implementation.Backend
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int HostId { get; set; }
|
||||||
|
|
||||||
public int ResisterObject<T>(object o, IEndPointContext context)
|
public int ResisterObject<T>(object o, IEndPointContext context)
|
||||||
{
|
{
|
||||||
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
||||||
return repository.ResisterObject<T>(o, context);
|
return repository.ResisterObject<T>(o, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearObject(int id)
|
public void ClearObject(ComplexObjectIdentifier id)
|
||||||
{
|
{
|
||||||
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
||||||
repository.ClearObject(id);
|
repository.ClearObject(id);
|
||||||
@@ -33,10 +35,10 @@ namespace mROA.Implementation.Backend
|
|||||||
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
||||||
{
|
{
|
||||||
var repository = GetRepository(sharedObjectShellShell.Identifier.OwnerId);
|
var repository = GetRepository(sharedObjectShellShell.Identifier.OwnerId);
|
||||||
return repository.GetObject<T>(sharedObjectShellShell.Identifier.ContextId);
|
return repository.GetObject<T>(sharedObjectShellShell.Identifier)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? GetObject<T>(int id)
|
public T? GetObject<T>(ComplexObjectIdentifier id)
|
||||||
{
|
{
|
||||||
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
||||||
return repository.GetObject<T>(id);
|
return repository.GetObject<T>(id);
|
||||||
@@ -69,11 +71,5 @@ namespace mROA.Implementation.Backend
|
|||||||
_repositories.Add(clientId, created);
|
_repositories.Add(clientId, created);
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetObject(int id)
|
|
||||||
{
|
|
||||||
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
|
||||||
return repository.GetObject<object>(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using mROA.Abstract;
|
||||||
|
|
||||||
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
|
public class ComplexRepository : IContextRepository
|
||||||
|
{
|
||||||
|
public void Inject<T>(T dependency)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int HostId { get; set; }
|
||||||
|
public int ResisterObject<T>(object o, IEndPointContext context)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClearObject(ComplexObjectIdentifier id)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? GetObject<T>(ComplexObjectIdentifier id)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetSingleObject(Type type)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetObjectIndex<T>(object o, IEndPointContext context)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using mROA.Abstract;
|
||||||
|
|
||||||
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
|
public class ExtensibleStorage<T> : IStorage<T>
|
||||||
|
{
|
||||||
|
private const int StartupSize = 1024;
|
||||||
|
private const int GrowSize = 128;
|
||||||
|
private T?[] _array = new T?[StartupSize];
|
||||||
|
private readonly LinkedList<int> _freePlaces = new(Enumerable.Range(0, StartupSize));
|
||||||
|
|
||||||
|
public T GetValue(int index)
|
||||||
|
{
|
||||||
|
return _array[index]!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetIndex(T value)
|
||||||
|
{
|
||||||
|
return Array.IndexOf(_array, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Place(T value)
|
||||||
|
{
|
||||||
|
if (_freePlaces.Count == 0)
|
||||||
|
{
|
||||||
|
Grow();
|
||||||
|
}
|
||||||
|
|
||||||
|
var index = _freePlaces.First.Value;
|
||||||
|
|
||||||
|
_array[index] = value;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Grow()
|
||||||
|
{
|
||||||
|
foreach (var index in Enumerable.Range(_array.Length, GrowSize))
|
||||||
|
_freePlaces.AddLast(index);
|
||||||
|
|
||||||
|
T?[] nextStorage = new T[_array.Length + GrowSize];
|
||||||
|
Array.Copy(_array, nextStorage, _array.Length);
|
||||||
|
_array = nextStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Free(int index)
|
||||||
|
{
|
||||||
|
_freePlaces.AddFirst(index);
|
||||||
|
_array[index] = default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,12 +9,14 @@ namespace mROA.Implementation
|
|||||||
public static Dictionary<Type, Type> RemoteTypes = new();
|
public static Dictionary<Type, Type> RemoteTypes = new();
|
||||||
private IRepresentationModuleProducer? _representationProducer;
|
private IRepresentationModuleProducer? _representationProducer;
|
||||||
|
|
||||||
|
public int HostId { get; set; }
|
||||||
|
|
||||||
public int ResisterObject<T>(object o, IEndPointContext context)
|
public int ResisterObject<T>(object o, IEndPointContext context)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearObject(int id)
|
public void ClearObject(ComplexObjectIdentifier id)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
@@ -31,7 +33,7 @@ namespace mROA.Implementation
|
|||||||
return remote;
|
return remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetObject<T>(int id)
|
public T? GetObject<T>(ComplexObjectIdentifier id)
|
||||||
{
|
{
|
||||||
if (_representationProducer == null)
|
if (_representationProducer == null)
|
||||||
throw new NullReferenceException("representation producer is not initialized");
|
throw new NullReferenceException("representation producer is not initialized");
|
||||||
|
|||||||
Reference in New Issue
Block a user