/* Method that helps to pass a GRANT status */ public void UpdateFederate() { // If it is a joined federate if (this.federate != null && ((Sxtafederate)this.federate).HLAisJoined) { // Compute GALT ComputeGALT(); if (this.federate.HLAtimeManagerState == HLAtimeState.TimeAdvancing) { if (log.IsDebugEnabled) { log.Debug("Execute UpdateFederate"); } if (TimeAdvanceRequestProperty == Status.PENDING) { if (PendingTime.CompareTo(federate.HLAGALT) < 0) { GrantFederateAdvancing(PendingTime); } else { // All messages with time stamp <= GALT are sent to the calling federate lrc.TickTSO(federate.HLAGALT); } } else if (TimeAdvanceRequestAvailableProperty == Status.PENDING) { if (PendingTime.CompareTo(federate.HLAGALT) <= 0) { if (bTimeRegulating == Status.PENDING) { TimeRegulating = Status.ON; federateAmbassador.TimeRegulationEnabled(PendingTime); } if (bTimeConstrained == Status.PENDING) { TimeConstrained = Status.ON; federateAmbassador.TimeConstrainedEnabled(PendingTime); } GrantFederateAdvancing(PendingTime); } else { // All messages with time stamp <= GALT are sent to the calling federate lrc.TickTSO(federate.HLAGALT); } } else if (NextMessageRequestProperty == Status.PENDING) { ComputeLITS(); if (this.federate.HLALITS.CompareTo(PendingTime) <= 0 && this.federate.HLALITS.CompareTo(federate.HLAGALT) < 0) { GrantFederateAdvancing(this.federate.HLALITS); } else if (PendingTime.CompareTo(federate.HLAGALT) < 0) { GrantFederateAdvancing(PendingTime); } } else if (NextMessageRequestAvailableProperty == Status.PENDING) { ComputeLITS(); if (this.federate.HLALITS.CompareTo(PendingTime) <= 0 && this.federate.HLALITS.CompareTo(federate.HLAGALT) <= 0) { GrantFederateAdvancing(this.federate.HLALITS); } else if (PendingTime.CompareTo(federate.HLAGALT) <= 0) { GrantFederateAdvancing(PendingTime); } } } } }
public void EnableTimeRegulation(ILogicalTimeInterval theLookahead) { lock (this) { /* 1. Process exceptions */ VerifyFederateIsExecutionMember(); CheckIsRegulating(); // If the calling federate is in pending on calling the enabledTimeRegulation service CheckTimeRegulationPending(); CheckValidLookahead(theLookahead); // if the calling federate is in time advancing state CheckAdvancing(); /* 2. Compute logical time */ ILogicalTime maxTime = federate.HLAlogicalTime.Add(theLookahead); String federationName = ((Sxtafederate)this.federate).HLAfederationNameJoined; IList <Sxtafederate> constrainedFederates = metaFederateAmbassador.GetConstrainedFederates(federationName); foreach (Sxtafederate constrainedFederate in constrainedFederates) { // it is not the calling federate if (constrainedFederate != this.federate) { if (constrainedFederate.HLAlogicalTime.CompareTo(maxTime) >= 0) { maxTime = constrainedFederate.HLAlogicalTime; // COMMENT ANGEL: He omitido lo del EPSILON porque no entiendo que función tiene // CONTESTACIÓN: Debe añadirse una cantidad suficientemente peq para que no sea justamente el tiempo lógico del regulado maxTime = maxTime.Add(logicalTimeIntervalFactory.MakeEpsilon()); } } } PendingTime = maxTime.Subtract(theLookahead); /* 3. Set lookahead and pending flag */ federate.HLAlookahead = theLookahead; TimeRegulating = Status.PENDING; /* 4. Send all RO messages to the calling federate */ lrc.TickRO(); /* 5. Judge whether the calling federate is granted to be regulating */ if (this.federate.HLAtimeConstrained) { // The invocation of this service shall be considered an implicit TARA service invocation bTimeAdvanceRequestAvailable = Status.PENDING; ComputeGALT(); if (PendingTime.CompareTo(federate.HLAGALT) <= 0) { // All messages with time stamp <= pending time in the calling // federate's TSO queue are sent to the federate lrc.TickTSO(PendingTime); bTimeAdvanceRequestAvailable = Status.ON; TimeRegulating = Status.ON; this.federate.HLAlogicalTime = PendingTime; this.federateAmbassador.TimeRegulationEnabled(federate.HLAlogicalTime); } else { // All messages with time stamp <= GALT in the calling // federate's TSO queue are sent to the federate lrc.TickTSO(federate.HLAGALT); } } else { bTimeAdvanceRequestAvailable = Status.ON; TimeRegulating = Status.ON; this.federate.HLAlogicalTime = PendingTime; this.federateAmbassador.TimeRegulationEnabled(federate.HLAlogicalTime); } } }