Ejemplo n.º 1
0
        /// <summary>
        /// Performs a commit
        /// </summary>
        /// <param name="workspaceId">Workspace ID</param>
        /// <param name="changeSet">Changes to commit</param>
        /// <returns>Changes which were commited</returns>
        public CommitResult <Guid> Commit(Guid workspaceId, IsolatedChangeSet <Guid, object, EdgeData> changeSet)
        {
            bool isSnapshotIsolation = workspaceStateProvider.WorkspaceIsolationLevel(workspaceId) == IsolationLevel.Snapshot;

            if (isSnapshotIsolation)
            {
                workspaceExclusiveLockProvider.EnterLockExclusive();
            }
            try
            {
                lock (commitSync)
                {
                    if (!workspaceStateProvider.IsWorkspaceExpired(workspaceId))
                    {
                        var result = commitDataService.AcceptCommit(changeSet);
                        workspaceStateProvider.UpdateWorspace(workspaceId, result.ResultSnapshotId);
                        subscriptionManagerService.InvokeEvents(workspaceId, result);
                        return(result);
                    }
                    else
                    {
                        throw new TimeoutException("Workspace timeout has elapsed");
                    }
                }
            }
            finally
            {
                if (isSnapshotIsolation)
                {
                    workspaceExclusiveLockProvider.ExitLockExclusive();
                }
            }
        }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            int nrThreads = 33;
            int nrRepeats = 300;
            int counter   = 0;

            for (int j = 0; j < nrRepeats; j++)
            {
                WorkspaceExclusiveLockProvider provider = new WorkspaceExclusiveLockProvider();
                Collection <Thread>            threads  = new Collection <Thread>();

                for (int i = 0; i < nrThreads; i++)
                {
                    Thread t = new Thread(() =>
                    {
                        provider.EnterLockExclusive();
                        Interlocked.Increment(ref counter);

                        Assert.AreEqual(1, counter);

                        Interlocked.Decrement(ref counter);

                        provider.ExitLockExclusive();
                    });

                    threads.Add(t);
                }


                foreach (var t in threads)
                {
                    t.Start();
                }

                foreach (var t in threads)
                {
                    t.Join();
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Updates given worksapce isolation level to snapshot.
 /// If given workspace isoaltion level is read only workspace isolation level cannot be updated and exception will be thrown.
 /// </summary>
 /// <typeparam name="TDataType"></typeparam>
 /// <param name="workspace"></param>
 public void UpdateWorkspaceToSnapshot <TDataType>(Workspace <TDataType> workspace)
 {
     workspaceExclusiveLockProvider.ExitLockExclusive();
     workspace.ChangeIsolationLevel(IsolationLevel.Snapshot);
 }