Пример #1
0
        private void Initialize(string domainModelName, int memoryStoreVacuumIntervalInSeconds, ITransactionManager transactionManager, IHyperstoreTrace trace, IStatistics stat)
        {
            DebugContract.RequiresNotEmpty(domainModelName);
            DebugContract.Requires(transactionManager);

            _trace = trace ?? new EmptyHyperstoreTrace();
            _transactionManager = transactionManager;
            if (memoryStoreVacuumIntervalInSeconds < 0)
            {
                memoryStoreVacuumIntervalInSeconds = defaultInterval;
            }

            _jobScheduler  = new JobScheduler(Vacuum, TimeSpan.FromSeconds(memoryStoreVacuumIntervalInSeconds));
            _involvedSlots = PlatformServices.Current.CreateConcurrentQueue <SlotList>();

            if (stat == null)
            {
                stat = EmptyStatistics.DefaultInstance;
            }

            _vaccumCounter = VACUUM_EVICTIONS_THROTTLE;

            _statAddValue      = stat.RegisterCounter("MemoryStore", String.Format("#AddValue {0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statGeIGraphNode  = stat.RegisterCounter("MemoryStore", String.Format("#GeIGraphNode {0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statUpdateValue   = stat.RegisterCounter("MemoryStore", String.Format("#UpdateValue {0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statRemoveValue   = stat.RegisterCounter("MemoryStore", String.Format("#RemoveValue {0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statVaccumCount   = stat.RegisterCounter("MemoryStore", String.Format("#Vaccum{0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statVaccumAverage = stat.RegisterCounter("MemoryStore", String.Format("VaccumAvgTimes{0}", domainModelName), domainModelName, StatisticCounterType.Average);
            _statVaccumSkipped = stat.RegisterCounter("MemoryStore", String.Format("#VaccumSkipped{0}", domainModelName), domainModelName, StatisticCounterType.Value);
        }
Пример #2
0
        protected void Configure(IDomainModel domainModel)
        {
            DebugContract.Requires(domainModel);
            if (_domainModel != null)
            {
                return;
            }

            _trace       = domainModel.Resolve <IHyperstoreTrace>(false) ?? new EmptyHyperstoreTrace();
            _domainModel = domainModel;

            var kv = _services.Resolve <IKeyValueStore>() ?? new Hyperstore.Modeling.MemoryStore.TransactionalMemoryStore(domainModel);

            _storage = kv;
            if (kv is IDomainService)
            {
                ((IDomainService)kv).SetDomain(domainModel);
            }
            _indexManager = new Hyperstore.Modeling.HyperGraph.Index.MemoryIndexManager(this); // TODO lier avec TransactionalMemoryStore
            _loader       = _services.Resolve <IGraphAdapter>();
            if (_loader is IDomainService)
            {
                ((IDomainService)_loader).SetDomain(domainModel);
            }
            _lazyLoader = _loader as ISupportsLazyLoading;
        }
Пример #3
0
        /// <summary>
        ///     Constructeur interne. Il est appelé par le store quand il crée la session
        /// </summary>
        /// <param name="store">The store.</param>
        /// <param name="cfg">The CFG.</param>
        internal Session(IHyperstore store, SessionConfiguration cfg)
        {
            DebugContract.Requires(store, "store");

            if (SessionIndex == null)
            {
                SessionIndex = s_sessionSequences.GetFirstFreeValue();
            }

            _trace = store.Trace;

            var ctx = SessionDataContext;

            if (ctx == null)
            {
                // _statSessionCount.Incr();

                // Nouvelle session
                ctx = new SessionDataContext // TODO optimize memory size
                {
                    TrackingData          = new SessionTrackingData(this),
                    SessionIsolationLevel = cfg.IsolationLevel,
                    Locks              = new List <ILockInfo>(),
                    ReadOnly           = cfg.Readonly,
                    ReadOnlyStatus     = cfg.Readonly,
                    Current            = this,
                    OriginStoreId      = cfg.Origin ?? store.Id,
                    Mode               = cfg.Mode,
                    SessionId          = cfg.SessionId != 0 ? cfg.SessionId : Interlocked.Increment(ref s_sessionIdSequences),
                    Store              = store,
                    CancellationToken  = cfg.CancellationToken,
                    Enlistment         = new List <ISessionEnlistmentNotification>(),
                    SessionInfos       = new Stack <SessionLocalInfo>(),
                    TopLevelSession    = this,
                    DefaultDomainModel = cfg.DefaultDomainModel,
                };

                SessionDataContext = ctx;

                _scope = Hyperstore.Modeling.Platform.PlatformServices.Current.CreateTransactionScope(this, cfg);
            }
            else if (ctx.SessionInfos.Count == 0)
            {
                throw new HyperstoreException(ExceptionMessages.CannotCreateNestedSessionInDisposingSession);
            }

            ctx.SessionInfos.Push(new SessionLocalInfo
            {
                DefaultDomainModel = cfg.DefaultDomainModel ?? ctx.DefaultDomainModel,
                Mode          = cfg.Mode | ctx.Mode,
                OriginStoreId = cfg.Origin ?? ctx.OriginStoreId
            });
        }
Пример #4
0
        internal LockManager(IServicesContainer services)
        {
            Contract.Requires(services, "services");

            _trace = services.Resolve <IHyperstoreTrace>() ?? new EmptyHyperstoreTrace();

            var defaultMaxTimeBeforeDeadlockInSeconds = services.GetSettingValue <int?>(Setting.MaxTimeBeforeDeadlockInMs);
            var n = defaultMaxTimeBeforeDeadlockInSeconds != null ? defaultMaxTimeBeforeDeadlockInSeconds.Value : DEFAULT_DEADLOCK_TIME;

            if (n < 0)
            {
                n = DEFAULT_DEADLOCK_TIME;
            }
            DeadLockLimitTimeInMs = n;
        }
        internal MemoryTransaction(IHyperstoreTrace trace, ITransactionManager transactionManager, long id, SessionIsolationLevel isolationLevel)
        {
            DebugContract.Requires(transactionManager);
            DebugContract.Requires(trace);

            if (isolationLevel != SessionIsolationLevel.ReadCommitted && isolationLevel != SessionIsolationLevel.Serializable)
            {
                throw new ArgumentOutOfRangeException("Only ReadCommitted or Serializable is allowed.");
            }

            Id = id;
            _isolationLevel     = isolationLevel;
            _transactionManager = transactionManager;
            _nestedStatus       = new Stack <TransactionStatus>();
            PushNestedTransaction();
            _currentStatus = TransactionStatus.Active;
        }
Пример #6
0
 public TransactionalMemoryStore(string domainModelName, int memoryStoreVacuumIntervalInSeconds, ITransactionManager transactionManager, IHyperstoreTrace trace = null, IStatistics stat = null)
 {
     Initialize(domainModelName, memoryStoreVacuumIntervalInSeconds, transactionManager, trace, stat);
 }
Пример #7
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Constructor.
 /// </summary>
 /// <param name="services">
 ///  The services.
 /// </param>
 ///-------------------------------------------------------------------------------------------------
 public TransactionManager(IServicesContainer services)
 {
     DebugContract.Requires(services);
     _trace = services.Resolve <IHyperstoreTrace>() ?? new EmptyHyperstoreTrace();
 }