Exemplo n.º 1
0
        private async Task <IIndexWorkflowQueue> GetReincarnatedWorkflowQueue(IIndexWorkflowQueue workflowQ)
        {
            string primaryKey = workflowQ.GetPrimaryKeyString();
            IIndexWorkflowQueue        reincarnatedQ        = InsideRuntimeClient.Current.InternalGrainFactory.GetGrain <IIndexWorkflowQueue>(primaryKey);
            IIndexWorkflowQueueHandler reincarnatedQHandler = InsideRuntimeClient.Current.InternalGrainFactory.GetGrain <IIndexWorkflowQueueHandler>(primaryKey);
            await Task.WhenAll(reincarnatedQ.Initialize(workflowQ), reincarnatedQHandler.Initialize(workflowQ));

            return(reincarnatedQ);
        }
Exemplo n.º 2
0
 internal IndexWorkflowQueueHandlerBase(Type iGrainType, int queueSeqNum, SiloAddress silo, bool isDefinedAsFaultTolerantGrain, GrainReference parent)
 {
     _iGrainType  = iGrainType;
     _queueSeqNum = queueSeqNum;
     _isDefinedAsFaultTolerantGrain = isDefinedAsFaultTolerantGrain;
     _hasAnyTotalIndex = false;
     __indexes         = null;
     __workflowQueue   = null;
     _silo             = silo;
     _parent           = parent;
 }
Exemplo n.º 3
0
 private IIndexWorkflowQueue InitIndexWorkflowQueue()
 {
     if (_parent.IsSystemTarget)
     {
         return(__workflowQueue = InsideRuntimeClient.Current.InternalGrainFactory.GetSystemTarget <IIndexWorkflowQueue>(IndexWorkflowQueueBase.CreateIndexWorkflowQueueGrainId(_iGrainType, _queueSeqNum), _silo));
     }
     else
     {
         return(__workflowQueue = InsideRuntimeClient.Current.InternalGrainFactory.GetGrain <IIndexWorkflowQueue>(IndexWorkflowQueueBase.CreateIndexWorkflowQueuePrimaryKey(_iGrainType, _queueSeqNum)));
     }
 }
Exemplo n.º 4
0
 internal IndexWorkflowQueueHandlerBase(SiloIndexManager siloIndexManager, Type grainInterfaceType, int queueSeqNum, SiloAddress silo,
                                        bool isDefinedAsFaultTolerantGrain, Func <GrainReference> parentFunc)
 {
     _grainInterfaceType            = grainInterfaceType;
     _queueSeqNum                   = queueSeqNum;
     _isDefinedAsFaultTolerantGrain = isDefinedAsFaultTolerantGrain;
     _hasAnyTotalIndex              = false;
     __grainIndexes                 = null;
     __workflowQueue                = null;
     _silo             = silo;
     _siloIndexManager = siloIndexManager;
     _lazyParent       = new Lazy <GrainReference>(parentFunc, true);
 }
Exemplo n.º 5
0
        public Task Initialize(IIndexWorkflowQueue oldParentSystemTarget)
        {
            if (_base == null)
            {
                GrainReference oldParentSystemTargetRef = oldParentSystemTarget.AsWeaklyTypedReference();
                string[] parts = oldParentSystemTargetRef.GetPrimaryKeyString().Split('-');
                if (parts.Length != 2)
                {
                    throw new Exception("The primary key for IndexWorkflowQueueSystemTarget should only contain a single special character '-', while it contains multiple. The primary key is '" + oldParentSystemTargetRef.GetPrimaryKeyString() + "'");
                }

                Type grainInterfaceType = TypeUtils.ResolveType(parts[0]);
                int queueSequenceNumber = int.Parse(parts[1]);

                GrainReference thisRef = this.AsWeaklyTypedReference();
                _base = new IndexWorkflowQueueHandlerBase(grainInterfaceType, queueSequenceNumber, oldParentSystemTargetRef.SystemTargetSilo, true /*otherwise it shouldn't have reached here!*/, thisRef);
            }
            return TaskDone.Done;
        }
        public Task Initialize(IIndexWorkflowQueue oldParentGrainService)
        {
            if (_base == null)
            {
                GrainReference oldParentGrainServiceRef = oldParentGrainService.AsWeaklyTypedReference();
                string[]       parts = oldParentGrainServiceRef.GetPrimaryKeyString().Split('-');
                if (parts.Length != 2)
                {
                    throw new WorkflowIndexException("The primary key for IndexWorkflowQueueGrainService should only contain a single special character '-', while it contains multiple." +
                                                     " The primary key is '" + oldParentGrainServiceRef.GetPrimaryKeyString() + "'");
                }

                Type grainInterfaceType  = this.SiloIndexManager.CachedTypeResolver.ResolveType(parts[0]);
                int  queueSequenceNumber = int.Parse(parts[1]);

                _base = new IndexWorkflowQueueBase(this.SiloIndexManager, grainInterfaceType, queueSequenceNumber,
                                                   oldParentGrainServiceRef.GrainServiceSiloAddress, isDefinedAsFaultTolerantGrain: true,
                                                   parentFunc: () => this.AsWeaklyTypedReference());
            }
            return(Task.CompletedTask);
        }
 protected Task ApplyIndexUpdatesLazily(IDictionary <string, IMemberUpdate> updates,
                                        IList <Type> iGrainTypes,
                                        IIndexableGrain thisGrain,
                                        Guid workflowID)
 {
     if (iGrainTypes.Count() == 1)
     {
         IIndexWorkflowQueue workflowQ = GetWorkflowQueue(iGrainTypes[0]);
         return(workflowQ.AddToQueue(new IndexWorkflowRecord(workflowID, thisGrain, updates).AsImmutable()));
     }
     else
     {
         Task[] tasks = new Task[iGrainTypes.Count];
         int    i     = 0;
         foreach (Type iGrainType in iGrainTypes)
         {
             tasks[i++] = GetWorkflowQueue(iGrainType).AddToQueue(
                 new IndexWorkflowRecord(workflowID, thisGrain, updates).AsImmutable()
                 );
         }
         return(Task.WhenAll(tasks));
     }
 }
 public Task Initialize(IIndexWorkflowQueue oldParentGrainService)
 => throw new NotSupportedException();
Exemplo n.º 9
0
 private IIndexWorkflowQueue InitIndexWorkflowQueue()
 => __workflowQueue = _lazyParent.Value.IsGrainService
             ? _siloIndexManager.GetGrainService <IIndexWorkflowQueue>(IndexWorkflowQueueBase.CreateIndexWorkflowQueueGrainReference(_siloIndexManager, _grainInterfaceType, _queueSeqNum, _silo))
             : _siloIndexManager.GrainFactory.GetGrain <IIndexWorkflowQueue>(IndexWorkflowQueueBase.CreateIndexWorkflowQueuePrimaryKey(_grainInterfaceType, _queueSeqNum));
Exemplo n.º 10
0
 public Task Initialize(IIndexWorkflowQueue oldParentSystemTarget)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 11
0
        /// <summary>
        /// Handles the remaining work-flows of a specific grain interface of the grain
        /// </summary>
        /// <param name="iGrainType">the grain interface type being indexed</param>
        /// <param name="oldWorkflowQ">the previous work-flow queue responsible for handling the updates</param>
        /// <returns>the actual list of work-flow record IDs that were available in this queue</returns>
        private async Task <IEnumerable <Guid> > HandleRemainingWorkflows(Type iGrainType, IIndexWorkflowQueue oldWorkflowQ)
        {
            //keeps the reference to the reincarnated work-flow queue,
            //if the original work-flow queue (system target) did not respond.
            IIndexWorkflowQueue reincarnatedOldWorkflowQ = null;

            //keeps the list of work-flow records from the old work-flow queue
            Immutable <List <IndexWorkflowRecord> > remainingWorkflows;

            //first, we remove the work-flow queue associated with iGrainType (i.e., oldWorkflowQ)
            //so that another call to get the work-flow queue for iGrainType
            //gets the new work-flow queue responsible for iGrainType (otherwise oldWorkflowQ is returned)
            WorkflowQueues.Remove(iGrainType);
            IIndexWorkflowQueue newWorkflowQ = GetWorkflowQueue(iGrainType);

            //if the same work-flow queue is responsible we just check
            //what work-flow records are still in process
            if (newWorkflowQ.Equals(oldWorkflowQ))
            {
                remainingWorkflows = await oldWorkflowQ.GetRemainingWorkflowsIn(base.State.activeWorkflowsSet);

                if (remainingWorkflows.Value != null && remainingWorkflows.Value.Count() > 0)
                {
                    return(remainingWorkflows.Value.Select(w => w.WorkflowId));
                }
            }
            else //the work-flow queue responsible for iGrainType has changed
            {
                try
                {
                    //we try to contact the original oldWorkflowQ to
                    //get the list of remaining work-flow records
                    //in order to pass their responsibility to newWorkflowQ
                    remainingWorkflows = await oldWorkflowQ.GetRemainingWorkflowsIn(base.State.activeWorkflowsSet);
                }
                catch //the corresponding workflowQ is down, we should ask its reincarnated version
                {
                    //if anything bad happened, it means that oldWorkflowQ is not reachable.
                    //Then we get our hands to reincarnatedOldWorkflowQ to get the  list of remaining work-flow records
                    reincarnatedOldWorkflowQ = await GetReincarnatedWorkflowQueue(oldWorkflowQ);

                    remainingWorkflows = await reincarnatedOldWorkflowQ.GetRemainingWorkflowsIn(base.State.activeWorkflowsSet);
                }
                //if any work-flow is remaining unprocessed
                if (remainingWorkflows.Value != null && remainingWorkflows.Value.Count() > 0)
                {
                    //give the responsibility of handling the remaining
                    //work -flow records to the newWorkflowQ
                    await newWorkflowQ.AddAllToQueue(remainingWorkflows);

                    //check which was the target old work-flow queue that responded to our request
                    var targetOldWorkflowQueue = reincarnatedOldWorkflowQ != null ? reincarnatedOldWorkflowQ : oldWorkflowQ;

                    //it's good that we remove the work-flows from the queue,
                    //but we really don't have to wait for them
                    //worst-case, it will be processed again by the old-queue
                    targetOldWorkflowQueue.RemoveAllFromQueue(remainingWorkflows).Ignore();
                    return(remainingWorkflows.Value.Select(w => w.WorkflowId));
                }
            }
            //if there are no remaining work-flow records, an empty Enumerable is returned
            return(Enumerable.Empty <Guid>());
        }