[ohla-devel] SF.net SVN: ohla: [26] trunk
Status: Beta
Brought to you by:
mnewcomb
From: <mne...@us...> - 2006-11-15 01:31:11
|
Revision: 26 http://svn.sourceforge.net/ohla/?rev=26&view=rev Author: mnewcomb Date: 2006-11-14 17:31:09 -0800 (Tue, 14 Nov 2006) Log Message: ----------- more time management support Modified Paths: -------------- trunk/rti/src/java/net/sf/ohla/rti1516/fdd/Attribute.java trunk/rti/src/java/net/sf/ohla/rti1516/fdd/FDD.java trunk/rti/src/java/net/sf/ohla/rti1516/fdd/InteractionClass.java trunk/rti/src/java/net/sf/ohla/rti1516/federate/Federate.java trunk/rti/src/java/net/sf/ohla/rti1516/federate/time/TimeManager.java trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java trunk/rti/src/java/net/sf/ohla/rti1516/federation/TimeKeeper.java trunk/testsuite/src/java/net/sf/ohla/rti1516/BaseTestNG.java trunk/testsuite/src/java/net/sf/ohla/rti1516/DataDistributionManagementTestNG.java trunk/testsuite/src/java/net/sf/ohla/rti1516/DeclarationManagementTestNG.java trunk/testsuite/src/java/net/sf/ohla/rti1516/FederationManagementTestNG.java trunk/testsuite/src/java/net/sf/ohla/rti1516/ObjectManagementTestNG.java trunk/testsuite/src/java/net/sf/ohla/rti1516/OwnershipManagementTestNG.java trunk/testsuite/src/java/net/sf/ohla/rti1516/SupportServicesTestNG.java Added Paths: ----------- trunk/rti/src/java/net/sf/ohla/rti1516/federate/time/TimeAdvanceType.java Modified: trunk/rti/src/java/net/sf/ohla/rti1516/fdd/Attribute.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/fdd/Attribute.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/rti/src/java/net/sf/ohla/rti1516/fdd/Attribute.java 2006-11-15 01:31:09 UTC (rev 26) @@ -30,11 +30,7 @@ import hla.rti1516.AttributeHandle; import hla.rti1516.ErrorReadingFDD; import hla.rti1516.OrderType; -import static hla.rti1516.OrderType.RECEIVE; -import static hla.rti1516.OrderType.TIMESTAMP; import hla.rti1516.TransportationType; -import static hla.rti1516.TransportationType.HLA_BEST_EFFORT; -import static hla.rti1516.TransportationType.HLA_RELIABLE; public class Attribute implements Serializable @@ -113,11 +109,11 @@ if ("timestamp".equalsIgnoreCase(order)) { - orderType = TIMESTAMP; + orderType = OrderType.TIMESTAMP; } else if ("receive".equalsIgnoreCase(this.order)) { - orderType = RECEIVE; + orderType = OrderType.RECEIVE; } else { @@ -142,11 +138,11 @@ if ("hlabesteffort".equalsIgnoreCase(transportation)) { - transportationType = HLA_BEST_EFFORT; + transportationType = TransportationType.HLA_BEST_EFFORT; } else if ("hlareliable".equalsIgnoreCase(transportation)) { - transportationType = HLA_RELIABLE; + transportationType = TransportationType.HLA_RELIABLE; } else { Modified: trunk/rti/src/java/net/sf/ohla/rti1516/fdd/FDD.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/fdd/FDD.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/rti/src/java/net/sf/ohla/rti1516/fdd/FDD.java 2006-11-15 01:31:09 UTC (rev 26) @@ -57,13 +57,9 @@ import hla.rti1516.ObjectClassHandle; import hla.rti1516.ObjectClassNotDefined; import hla.rti1516.OrderType; -import static hla.rti1516.OrderType.RECEIVE; -import static hla.rti1516.OrderType.TIMESTAMP; import hla.rti1516.ParameterHandle; import hla.rti1516.RangeBounds; import hla.rti1516.TransportationType; -import static hla.rti1516.TransportationType.HLA_BEST_EFFORT; -import static hla.rti1516.TransportationType.HLA_RELIABLE; public class FDD implements Serializable @@ -80,11 +76,11 @@ static { - orderTypeNames.put(TIMESTAMP, "TimeStamp"); - orderTypeNames.put(RECEIVE, "Receive"); + orderTypeNames.put(OrderType.TIMESTAMP, "TimeStamp"); + orderTypeNames.put(OrderType.RECEIVE, "Receive"); - orderTypesByName.put("TimeStamp", TIMESTAMP); - orderTypesByName.put("Receive", RECEIVE); + orderTypesByName.put("TimeStamp", OrderType.TIMESTAMP); + orderTypesByName.put("Receive", OrderType.RECEIVE); } protected static Map<TransportationType, String> transportationTypeNames = @@ -94,11 +90,15 @@ static { - transportationTypeNames.put(HLA_RELIABLE, "HLAreliable"); - transportationTypeNames.put(HLA_BEST_EFFORT, "HLAbestEffort"); + transportationTypeNames.put( + TransportationType.HLA_RELIABLE, "HLAreliable"); + transportationTypeNames.put( + TransportationType.HLA_BEST_EFFORT, "HLAbestEffort"); - transportationTypesByName.put("HLAreliable", HLA_RELIABLE); - transportationTypesByName.put("HLAbestEffort", HLA_BEST_EFFORT); + transportationTypesByName.put( + "HLAreliable", TransportationType.HLA_RELIABLE); + transportationTypesByName.put( + "HLAbestEffort", TransportationType.HLA_BEST_EFFORT); } protected Map<ObjectClassHandle, ObjectClass> objectClasses = Modified: trunk/rti/src/java/net/sf/ohla/rti1516/fdd/InteractionClass.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/fdd/InteractionClass.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/rti/src/java/net/sf/ohla/rti1516/fdd/InteractionClass.java 2006-11-15 01:31:09 UTC (rev 26) @@ -35,12 +35,8 @@ import hla.rti1516.InteractionParameterNotDefined; import hla.rti1516.NameNotFound; import hla.rti1516.OrderType; -import static hla.rti1516.OrderType.RECEIVE; -import static hla.rti1516.OrderType.TIMESTAMP; import hla.rti1516.ParameterHandle; import hla.rti1516.TransportationType; -import static hla.rti1516.TransportationType.HLA_BEST_EFFORT; -import static hla.rti1516.TransportationType.HLA_RELIABLE; public class InteractionClass implements Serializable @@ -211,11 +207,11 @@ if ("timestamp".equalsIgnoreCase(order)) { - orderType = TIMESTAMP; + orderType = OrderType.TIMESTAMP; } else if ("receive".equalsIgnoreCase(this.order)) { - orderType = RECEIVE; + orderType = OrderType.RECEIVE; } else { @@ -245,11 +241,11 @@ if ("hlabesteffort".equalsIgnoreCase(transportation)) { - transportationType = HLA_BEST_EFFORT; + transportationType = TransportationType.HLA_BEST_EFFORT; } else if ("hlareliable".equalsIgnoreCase(transportation)) { - transportationType = HLA_RELIABLE; + transportationType = TransportationType.HLA_RELIABLE; } else { Modified: trunk/rti/src/java/net/sf/ohla/rti1516/federate/Federate.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/federate/Federate.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/rti/src/java/net/sf/ohla/rti1516/federate/Federate.java 2006-11-15 01:31:09 UTC (rev 26) @@ -202,8 +202,6 @@ import hla.rti1516.ObjectInstanceNameNotReserved; import hla.rti1516.ObjectInstanceNotKnown; import hla.rti1516.OrderType; -import static hla.rti1516.OrderType.RECEIVE; -import static hla.rti1516.OrderType.TIMESTAMP; import hla.rti1516.OwnershipAcquisitionPending; import hla.rti1516.ParameterHandle; import hla.rti1516.ParameterHandleFactory; @@ -1486,13 +1484,13 @@ timeManager.getTimeLock().readLock().lock(); try { - timeManager.checkIfInvalidLogicalTime(updateTime); + timeManager.updateAttributeValues(updateTime); OrderType sentOrderType = timeManager.isTimeRegulating() && updateTime != null ? - TIMESTAMP : RECEIVE; + OrderType.TIMESTAMP : OrderType.RECEIVE; - if (sentOrderType == TIMESTAMP) + if (sentOrderType == OrderType.TIMESTAMP) { messageRetractionHandle = messageRetractionManager.add(updateTime); } @@ -1563,13 +1561,13 @@ timeManager.getTimeLock().readLock().lock(); try { - timeManager.checkIfInvalidLogicalTime(sendTime); + timeManager.sendInteraction(sendTime); OrderType sentOrderType = timeManager.isTimeRegulating() && sendTime != null ? - TIMESTAMP : RECEIVE; + OrderType.TIMESTAMP : OrderType.RECEIVE; - if (sentOrderType == TIMESTAMP) + if (sentOrderType == OrderType.TIMESTAMP) { messageRetractionHandle = messageRetractionManager.add(sendTime); } @@ -1626,13 +1624,13 @@ timeManager.getTimeLock().readLock().lock(); try { - timeManager.checkIfInvalidLogicalTime(deleteTime); + timeManager.deleteObjectInstance(deleteTime); OrderType sentOrderType = timeManager.isTimeRegulating() && deleteTime != null ? - TIMESTAMP : RECEIVE; + OrderType.TIMESTAMP : OrderType.RECEIVE; - if (sentOrderType == TIMESTAMP) + if (sentOrderType == OrderType.TIMESTAMP) { messageRetractionHandle = messageRetractionManager.add(deleteTime); } @@ -2692,10 +2690,10 @@ OrderType sentOrderType = timeManager.isTimeRegulating() && sendTime != null ? - TIMESTAMP : RECEIVE; + OrderType.TIMESTAMP : OrderType.RECEIVE; MessageRetractionHandle messageRetractionHandle = null; - if (sentOrderType == TIMESTAMP) + if (sentOrderType == OrderType.TIMESTAMP) { messageRetractionHandle = messageRetractionManager.add(sendTime); } @@ -3444,11 +3442,11 @@ (ReflectAttributeValues) message; OrderType receivedOrderType = - reflectAttributeValues.getSentOrderType() == TIMESTAMP && - timeManager.isTimeConstrained() ? TIMESTAMP : RECEIVE; + reflectAttributeValues.getSentOrderType() == OrderType.TIMESTAMP && + timeManager.isTimeConstrained() ? OrderType.TIMESTAMP : OrderType.RECEIVE; reflectAttributeValues.setReceivedOrderType(receivedOrderType); - if (receivedOrderType == RECEIVE) + if (receivedOrderType == OrderType.RECEIVE) { // receive order callbacks need to be held until released if we are // constrained and in the time granted state if asynchronous delivery is @@ -3479,12 +3477,12 @@ ReceiveInteraction receiveInteraction = (ReceiveInteraction) message; OrderType receivedOrderType = - receiveInteraction.getSentOrderType() == TIMESTAMP && - timeManager.isTimeConstrained() ? TIMESTAMP : RECEIVE; + receiveInteraction.getSentOrderType() == OrderType.TIMESTAMP && + timeManager.isTimeConstrained() ? OrderType.TIMESTAMP : OrderType.RECEIVE; receiveInteraction.setReceivedOrderType(receivedOrderType); - if (receivedOrderType == RECEIVE) + if (receivedOrderType == OrderType.RECEIVE) { // receive order callbacks need to be held until released if we are // constrained and in the time granted state, if asynchronous delivery is @@ -3708,13 +3706,37 @@ public void federationSaved() throws FederateInternalError { - federateAmbassador.federationSaved(); + federateStateLock.writeLock().lock(); + try + { + federateAmbassador.federationSaved(); + } + finally + { + federateState = FederateState.ACTIVE; + + // TODO: unhold callbacks? + + federateStateLock.writeLock().unlock(); + } } public void federationNotSaved(SaveFailureReason reason) throws FederateInternalError { - federateAmbassador.federationNotSaved(reason); + federateStateLock.writeLock().lock(); + try + { + federateAmbassador.federationNotSaved(reason); + } + finally + { + federateState = FederateState.ACTIVE; + + // TODO: unhold callbacks? + + federateStateLock.writeLock().unlock(); + } } public void federationSaveStatusResponse( @@ -4163,21 +4185,21 @@ throws InvalidLogicalTime, NoRequestToEnableTimeRegulationWasPending, FederateInternalError { - federateAmbassador.timeRegulationEnabled(time); + timeManager.timeRegulationEnabled(time, federateAmbassador); } public void timeConstrainedEnabled(LogicalTime time) throws InvalidLogicalTime, NoRequestToEnableTimeConstrainedWasPending, FederateInternalError { - federateAmbassador.timeConstrainedEnabled(time); + timeManager.timeConstrainedEnabled(time, federateAmbassador); } public void timeAdvanceGrant(LogicalTime time) throws InvalidLogicalTime, JoinedFederateIsNotInTimeAdvancingState, FederateInternalError { - federateAmbassador.timeAdvanceGrant(time); + timeManager.timeAdvanceGrant(time, federateAmbassador); } public void requestRetraction(MessageRetractionHandle messageRetractionHandle) Added: trunk/rti/src/java/net/sf/ohla/rti1516/federate/time/TimeAdvanceType.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/federate/time/TimeAdvanceType.java (rev 0) +++ trunk/rti/src/java/net/sf/ohla/rti1516/federate/time/TimeAdvanceType.java 2006-11-15 01:31:09 UTC (rev 26) @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2006, Michael Newcomb + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.sf.ohla.rti1516.federate.time; + +public enum TimeAdvanceType +{ + TIME_ADVANCE_REQUEST, TIME_ADVANCE_REQUEST_AVAILABLE, + NEXT_MESSAGE_REQUEST, NEXT_MESSAGE_REQUEST_AVAILABLE, + FLUSH_QUEUE_REQUEST +} Modified: trunk/rti/src/java/net/sf/ohla/rti1516/federate/time/TimeManager.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/federate/time/TimeManager.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/rti/src/java/net/sf/ohla/rti1516/federate/time/TimeManager.java 2006-11-15 01:31:09 UTC (rev 26) @@ -20,14 +20,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import net.sf.ohla.rti1516.federate.Federate; -import static net.sf.ohla.rti1516.federate.time.TemporalState.TIME_ADVANCING; -import static net.sf.ohla.rti1516.federate.time.TemporalState.TIME_GRANTED; -import static net.sf.ohla.rti1516.federate.time.TimeConstrainedState.BECOMING_TIME_CONSTRAINED; -import static net.sf.ohla.rti1516.federate.time.TimeConstrainedState.NOT_TIME_CONSTRAINED; -import static net.sf.ohla.rti1516.federate.time.TimeConstrainedState.TIME_CONSTRAINED; -import static net.sf.ohla.rti1516.federate.time.TimeRegulatingState.BECOMING_TIME_REGULATING; -import static net.sf.ohla.rti1516.federate.time.TimeRegulatingState.NOT_TIME_REGULATING; -import static net.sf.ohla.rti1516.federate.time.TimeRegulatingState.TIME_REGULATING; import net.sf.ohla.rti1516.messages.DisableTimeConstrained; import net.sf.ohla.rti1516.messages.DisableTimeRegulation; import net.sf.ohla.rti1516.messages.EnableTimeConstrained; @@ -38,6 +30,11 @@ import org.apache.mina.common.WriteFuture; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import hla.rti1516.FederateAmbassador; +import hla.rti1516.IllegalTimeArithmetic; import hla.rti1516.InTimeAdvancingState; import hla.rti1516.InvalidLogicalTime; import hla.rti1516.InvalidLookahead; @@ -55,20 +52,27 @@ public class TimeManager { + private static final Logger log = LoggerFactory.getLogger(TimeManager.class); + protected Federate federate; protected ReadWriteLock timeLock = new ReentrantReadWriteLock(true); - protected TemporalState temporalState = TIME_GRANTED; - protected TimeRegulatingState timeRegulatingState = NOT_TIME_REGULATING; - protected TimeConstrainedState timeConstrainedState = NOT_TIME_CONSTRAINED; + protected TemporalState temporalState = TemporalState.TIME_GRANTED; + protected TimeRegulatingState timeRegulatingState = + TimeRegulatingState.NOT_TIME_REGULATING; + protected TimeConstrainedState timeConstrainedState = + TimeConstrainedState.NOT_TIME_CONSTRAINED; - protected LogicalTime time; + protected LogicalTime federateTime; protected LogicalTime galt; protected LogicalTime lits; protected LogicalTimeInterval lookahead; + protected LogicalTime advanceRequestTime; + protected TimeAdvanceType advanceRequestTimeType; + public TimeManager(Federate federate) { this.federate = federate; @@ -81,22 +85,22 @@ public boolean isTimeRegulating() { - return timeRegulatingState == TIME_REGULATING; + return timeRegulatingState == TimeRegulatingState.TIME_REGULATING; } public boolean isTimeConstrained() { - return timeConstrainedState == TIME_CONSTRAINED; + return timeConstrainedState == TimeConstrainedState.TIME_CONSTRAINED; } public boolean isTimeAdvancing() { - return temporalState == TIME_ADVANCING; + return temporalState == TemporalState.TIME_ADVANCING; } public boolean isTimeGranted() { - return temporalState == TIME_GRANTED; + return temporalState == TemporalState.TIME_GRANTED; } public boolean isTimeConstrainedAndTimeGranted() @@ -111,7 +115,7 @@ timeLock.writeLock().lock(); try { - if (timeRegulatingState == TIME_REGULATING) + if (timeRegulatingState == TimeRegulatingState.TIME_REGULATING) { throw new TimeRegulationAlreadyEnabled(); } @@ -134,7 +138,7 @@ this.lookahead = lookahead; - timeRegulatingState = BECOMING_TIME_REGULATING; + timeRegulatingState = TimeRegulatingState.BECOMING_TIME_REGULATING; } finally { @@ -162,7 +166,7 @@ throw new RTIinternalError("error communicating with RTI"); } - timeRegulatingState = NOT_TIME_REGULATING; + timeRegulatingState = TimeRegulatingState.NOT_TIME_REGULATING; } finally { @@ -177,7 +181,7 @@ timeLock.writeLock().lock(); try { - if (timeConstrainedState == TIME_CONSTRAINED) + if (timeConstrainedState == TimeConstrainedState.TIME_CONSTRAINED) { throw new TimeConstrainedAlreadyEnabled(); } @@ -198,7 +202,7 @@ throw new RTIinternalError("error communicating with RTI"); } - timeConstrainedState = BECOMING_TIME_CONSTRAINED; + timeConstrainedState = TimeConstrainedState.BECOMING_TIME_CONSTRAINED; } finally { @@ -226,7 +230,7 @@ throw new RTIinternalError("error communicating with RTI"); } - timeConstrainedState = NOT_TIME_CONSTRAINED; + timeConstrainedState = TimeConstrainedState.NOT_TIME_CONSTRAINED; // TODO: release all TSO messages } @@ -250,6 +254,9 @@ checkIfRequestForTimeRegulationPending(); checkIfRequestForTimeConstrainedPending(); + advanceRequestTime = time; + advanceRequestTimeType = TimeAdvanceType.TIME_ADVANCE_REQUEST; + WriteFuture writeFuture = federate.getRTISession().write(new TimeAdvanceRequest(time)); @@ -264,7 +271,7 @@ // TODO: will need to send to peers as well - temporalState = TIME_ADVANCING; + temporalState = TemporalState.TIME_ADVANCING; // release any callbacks held until we are time advancing // @@ -290,6 +297,8 @@ checkIfRequestForTimeRegulationPending(); checkIfRequestForTimeConstrainedPending(); + advanceRequestTime = time; + WriteFuture writeFuture = federate.getRTISession().write(new TimeAdvanceRequestAvailable(time)); @@ -302,7 +311,7 @@ throw new RTIinternalError("error communicating with RTI"); } - temporalState = TIME_ADVANCING; + temporalState = TemporalState.TIME_ADVANCING; // release any callbacks held until we are time advancing // @@ -328,6 +337,8 @@ checkIfRequestForTimeRegulationPending(); checkIfRequestForTimeConstrainedPending(); + advanceRequestTime = time; + WriteFuture writeFuture = federate.getRTISession().write(new TimeAdvanceRequest(time)); @@ -340,7 +351,7 @@ throw new RTIinternalError("error communicating with RTI"); } - temporalState = TIME_ADVANCING; + temporalState = TemporalState.TIME_ADVANCING; // release any callbacks held until we are time advancing // @@ -366,6 +377,8 @@ checkIfRequestForTimeConstrainedPending(); checkIfRequestForTimeRegulationPending(); + advanceRequestTime = time; + WriteFuture writeFuture = federate.getRTISession().write(new TimeAdvanceRequest(time)); @@ -378,7 +391,7 @@ throw new RTIinternalError("error communicating with RTI"); } - temporalState = TIME_ADVANCING; + temporalState = TemporalState.TIME_ADVANCING; // release any callbacks held until we are time advancing // @@ -404,6 +417,8 @@ checkIfRequestForTimeRegulationPending(); checkIfRequestForTimeConstrainedPending(); + advanceRequestTime = time; + WriteFuture writeFuture = federate.getRTISession().write(new TimeAdvanceRequest(time)); @@ -416,7 +431,7 @@ throw new RTIinternalError("error communicating with RTI"); } - temporalState = TIME_ADVANCING; + temporalState = TemporalState.TIME_ADVANCING; // release any callbacks held until we are time advancing // @@ -452,7 +467,7 @@ timeLock.readLock().lock(); try { - return time; + return federateTime; } finally { @@ -525,6 +540,68 @@ } } + public void timeRegulationEnabled(LogicalTime time, + FederateAmbassador federateAmbassador) + { + timeLock.writeLock().lock(); + try + { + federateTime = time; + + federateAmbassador.timeRegulationEnabled(time); + } + catch (Throwable t) + { + log.warn(String.format( + "federate unable enable time regulation to: %s", time), t); + } + finally + { + timeLock.writeLock().unlock(); + } + } + + public void timeConstrainedEnabled(LogicalTime time, + FederateAmbassador federateAmbassador) + { + timeLock.writeLock().lock(); + try + { + federateTime = time; + + federateAmbassador.timeConstrainedEnabled(time); + } + catch (Throwable t) + { + log.warn(String.format( + "federate unable enable time constrained to: %s", time), t); + } + finally + { + timeLock.writeLock().unlock(); + } + } + + public void timeAdvanceGrant(LogicalTime time, + FederateAmbassador federateAmbassador) + { + timeLock.writeLock().lock(); + try + { + federateTime = time; + + federateAmbassador.timeAdvanceGrant(time); + } + catch (Throwable t) + { + log.warn(String.format("federate unable to advance to: %s", time), t); + } + finally + { + timeLock.writeLock().unlock(); + } + } + public void checkIfInTimeAdvancingState() throws InTimeAdvancingState { @@ -546,7 +623,7 @@ public void checkIfRequestForTimeRegulationPending() throws RequestForTimeRegulationPending { - if (timeRegulatingState == BECOMING_TIME_REGULATING) + if (timeRegulatingState == TimeRegulatingState.BECOMING_TIME_REGULATING) { throw new RequestForTimeRegulationPending(); } @@ -564,7 +641,7 @@ public void checkIfRequestForTimeConstrainedPending() throws RequestForTimeConstrainedPending { - if (timeConstrainedState == BECOMING_TIME_CONSTRAINED) + if (timeConstrainedState == TimeConstrainedState.BECOMING_TIME_CONSTRAINED) { throw new RequestForTimeConstrainedPending(); } @@ -573,21 +650,105 @@ public void checkIfLogicalTimeAlreadyPassed(LogicalTime time) throws LogicalTimeAlreadyPassed { - if (time.compareTo(this.time) <= 0) + if (time.compareTo(federateTime) <= 0) { throw new LogicalTimeAlreadyPassed( - String.format("%s <= %s", time, this.time)); + String.format("%s <= %s", time, federateTime)); } } public void checkIfInvalidLogicalTime(LogicalTime time) throws InvalidLogicalTime { + if (time == null) + { + throw new InvalidLogicalTime("null"); + } + + // TODO: check against factory type? } public void checkIfInvalidLookahead(LogicalTimeInterval lookahead) throws InvalidLookahead { + if (lookahead == null) + { + throw new InvalidLookahead("null"); + } + + // TODO: check against factory type? } + + public void updateAttributeValues(LogicalTime updateTime) + throws InvalidLogicalTime + { + checkIfInvalidTimestamp(updateTime); + } + + public void sendInteraction(LogicalTime sendTime) + throws InvalidLogicalTime + { + checkIfInvalidTimestamp(sendTime); + } + + public void deleteObjectInstance(LogicalTime deleteTime) + throws InvalidLogicalTime + { + checkIfInvalidTimestamp(deleteTime); + } + + public void checkIfInvalidTimestamp(LogicalTime time) + throws InvalidLogicalTime + { + checkIfInvalidLogicalTime(time); + + LogicalTime minimumTime = + isTimeAdvancing() ? advanceRequestTime : federateTime; + switch (advanceRequestTimeType) + { + case TIME_ADVANCE_REQUEST: + case NEXT_MESSAGE_REQUEST: + { + if (lookahead.isZero()) + { + // handle special case when lookahead is 0 + + if (time.compareTo(minimumTime) <= 0) + { + throw new InvalidLogicalTime( + String.format("%s <= %s", time, minimumTime)); + } + + break; + } + } + case TIME_ADVANCE_REQUEST_AVAILABLE: + case NEXT_MESSAGE_REQUEST_AVAILABLE: + case FLUSH_QUEUE_REQUEST: + { + try + { + LogicalTime minimumTimePlusLookahead = minimumTime.add(lookahead); + + if (time.compareTo(minimumTimePlusLookahead) < 0) + { + throw new InvalidLogicalTime(String.format( + "%s < %s (%s + %s)", time, minimumTimePlusLookahead, + minimumTime, lookahead)); + } + } + catch (IllegalTimeArithmetic ita) + { + throw new InvalidLogicalTime(ita); + } + + break; + } + default: + { + assert false : + String.format("unknown TimeAdvanceType: %s", advanceRequestTimeType); + } + } + } } - Modified: trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java 2006-11-15 01:31:09 UTC (rev 26) @@ -1269,8 +1269,8 @@ federationExecutionStateLock.readLock().lock(); try { - timeKeeper.enableTimeRegulation( - getFederateHandle(session), enableTimeRegulation.getLookahead()); + timeKeeper.enableTimeRegulation(session, getFederateHandle(session), + enableTimeRegulation.getLookahead()); } finally { @@ -1298,7 +1298,7 @@ federationExecutionStateLock.readLock().lock(); try { - timeKeeper.enableTimeConstrained(getFederateHandle(session)); + timeKeeper.enableTimeConstrained(session, getFederateHandle(session)); } finally { @@ -1479,9 +1479,18 @@ federatesLock.lock(); try { - if (federateSessions.isEmpty()) + if (joinFederationExecution.getMobileFederateServices() == null) { - // this the first federate, use it's mobile federate services + log.warn("federate did not specify MobileFederateServices: {}", + federateHandle); + } + else if (timeKeeper != null) + { + // TODO: ensure each federate has the same mobile federate services + } + else + { + // use the first non-null mobile federate services // timeKeeper = new TimeKeeper( this, joinFederationExecution.getMobileFederateServices()); Modified: trunk/rti/src/java/net/sf/ohla/rti1516/federation/TimeKeeper.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/federation/TimeKeeper.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/TimeKeeper.java 2006-11-15 01:31:09 UTC (rev 26) @@ -8,7 +8,11 @@ import java.util.concurrent.locks.ReentrantLock; import net.sf.ohla.rti1516.federate.callbacks.TimeAdvanceGrant; +import net.sf.ohla.rti1516.federate.callbacks.TimeRegulationEnabled; +import net.sf.ohla.rti1516.federate.callbacks.TimeConstrainedEnabled; +import org.apache.mina.common.IoSession; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,13 +54,16 @@ minAdvanceRequest = mobileFederateServices.timeFactory.makeFinal(); } - public void enableTimeRegulation(FederateHandle federateHandle, + public void enableTimeRegulation(IoSession session, + FederateHandle federateHandle, LogicalTimeInterval lookahead) { timeLock.lock(); try { timeRegulatingFederates.put(federateHandle, lookahead); + + session.write(new TimeRegulationEnabled(time)); } finally { @@ -77,12 +84,15 @@ } } - public void enableTimeConstrained(FederateHandle federateHandle) + public void enableTimeConstrained(IoSession session, + FederateHandle federateHandle) { timeLock.lock(); try { timeConstrainedFederates.add(federateHandle); + + session.write(new TimeConstrainedEnabled(time)); } finally { Modified: trunk/testsuite/src/java/net/sf/ohla/rti1516/BaseTestNG.java =================================================================== --- trunk/testsuite/src/java/net/sf/ohla/rti1516/BaseTestNG.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/testsuite/src/java/net/sf/ohla/rti1516/BaseTestNG.java 2006-11-15 01:31:09 UTC (rev 26) @@ -26,6 +26,7 @@ import org.testng.annotations.Test; import hla.rti1516.RTIambassador; +import hla.rti1516.MobileFederateServices; import hla.rti1516.jlc.RtiFactory; import hla.rti1516.jlc.RtiFactoryFactory; @@ -39,6 +40,10 @@ protected int rtiAmbassadorCount; protected List<RTIambassador> rtiAmbassadors; + protected MobileFederateServices mobileFederateServices = + new MobileFederateServices( + new Integer64TimeFactory(), new Integer64TimeIntervalFactory()); + protected BaseTestNG() { this(1); Modified: trunk/testsuite/src/java/net/sf/ohla/rti1516/DataDistributionManagementTestNG.java =================================================================== --- trunk/testsuite/src/java/net/sf/ohla/rti1516/DataDistributionManagementTestNG.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/testsuite/src/java/net/sf/ohla/rti1516/DataDistributionManagementTestNG.java 2006-11-15 01:31:09 UTC (rev 26) @@ -21,12 +21,12 @@ import org.testng.annotations.Test; import hla.rti1516.jlc.NullFederateAmbassador; -import static hla.rti1516.ResignAction.NO_ACTION; import hla.rti1516.DimensionHandleSet; import hla.rti1516.DimensionHandle; import hla.rti1516.RegionHandle; import hla.rti1516.RangeBounds; import hla.rti1516.RegionHandleSet; +import hla.rti1516.ResignAction; public class DataDistributionManagementTestNG extends BaseTestNG @@ -78,8 +78,8 @@ public void teardown() throws Exception { - rtiAmbassadors.get(0).resignFederationExecution(NO_ACTION); - rtiAmbassadors.get(1).resignFederationExecution(NO_ACTION); + rtiAmbassadors.get(0).resignFederationExecution(ResignAction.NO_ACTION); + rtiAmbassadors.get(1).resignFederationExecution(ResignAction.NO_ACTION); rtiAmbassadors.get(0).destroyFederationExecution(FEDERATION_NAME); } Modified: trunk/testsuite/src/java/net/sf/ohla/rti1516/DeclarationManagementTestNG.java =================================================================== --- trunk/testsuite/src/java/net/sf/ohla/rti1516/DeclarationManagementTestNG.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/testsuite/src/java/net/sf/ohla/rti1516/DeclarationManagementTestNG.java 2006-11-15 01:31:09 UTC (rev 26) @@ -25,7 +25,7 @@ import hla.rti1516.InteractionClassNotDefined; import hla.rti1516.ObjectClassHandle; import hla.rti1516.ObjectClassNotDefined; -import static hla.rti1516.ResignAction.NO_ACTION; +import hla.rti1516.ResignAction; import hla.rti1516.jlc.NullFederateAmbassador; @Test(groups = {"Declaration Management"}) @@ -67,7 +67,7 @@ public void teardown() throws Exception { - rtiAmbassadors.get(0).resignFederationExecution(NO_ACTION); + rtiAmbassadors.get(0).resignFederationExecution(ResignAction.NO_ACTION); rtiAmbassadors.get(0).destroyFederationExecution(FEDERATION_NAME); } Modified: trunk/testsuite/src/java/net/sf/ohla/rti1516/FederationManagementTestNG.java =================================================================== --- trunk/testsuite/src/java/net/sf/ohla/rti1516/FederationManagementTestNG.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/testsuite/src/java/net/sf/ohla/rti1516/FederationManagementTestNG.java 2006-11-15 01:31:09 UTC (rev 26) @@ -38,7 +38,7 @@ import hla.rti1516.FederateInternalError; import hla.rti1516.SynchronizationPointFailureReason; import hla.rti1516.SynchronizationPointLabelNotAnnounced; -import static hla.rti1516.ResignAction.NO_ACTION; +import hla.rti1516.ResignAction; import hla.rti1516.jlc.NullFederateAmbassador; @Test(groups = {"Federation Managmenet"}) @@ -137,9 +137,9 @@ public void testResignFederationExecution() throws Exception { - rtiAmbassadors.get(0).resignFederationExecution(NO_ACTION); - rtiAmbassadors.get(1).resignFederationExecution(NO_ACTION); - rtiAmbassadors.get(2).resignFederationExecution(NO_ACTION); + rtiAmbassadors.get(0).resignFederationExecution(ResignAction.NO_ACTION); + rtiAmbassadors.get(1).resignFederationExecution(ResignAction.NO_ACTION); + rtiAmbassadors.get(2).resignFederationExecution(ResignAction.NO_ACTION); } @Test(expectedExceptions = {FederationExecutionDoesNotExist.class}) @@ -155,7 +155,7 @@ public void testResignFederationExecutionThatNotAMember() throws Exception { - rtiAmbassadors.get(0).resignFederationExecution(NO_ACTION); + rtiAmbassadors.get(0).resignFederationExecution(ResignAction.NO_ACTION); } @Test(dependsOnMethods = {"testJoinFederationExecutionAgain"}) Modified: trunk/testsuite/src/java/net/sf/ohla/rti1516/ObjectManagementTestNG.java =================================================================== --- trunk/testsuite/src/java/net/sf/ohla/rti1516/ObjectManagementTestNG.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/testsuite/src/java/net/sf/ohla/rti1516/ObjectManagementTestNG.java 2006-11-15 01:31:09 UTC (rev 26) @@ -44,9 +44,9 @@ import hla.rti1516.ParameterHandle; import hla.rti1516.ParameterHandleValueMap; import hla.rti1516.RTIambassador; -import static hla.rti1516.ResignAction.NO_ACTION; import hla.rti1516.TransportationType; import hla.rti1516.UnknownName; +import hla.rti1516.ResignAction; import hla.rti1516.jlc.NullFederateAmbassador; @Test(groups = {"Object Management"}) @@ -166,9 +166,9 @@ public void teardown() throws Exception { - rtiAmbassadors.get(0).resignFederationExecution(NO_ACTION); - rtiAmbassadors.get(1).resignFederationExecution(NO_ACTION); - rtiAmbassadors.get(2).resignFederationExecution(NO_ACTION); + rtiAmbassadors.get(0).resignFederationExecution(ResignAction.NO_ACTION); + rtiAmbassadors.get(1).resignFederationExecution(ResignAction.NO_ACTION); + rtiAmbassadors.get(2).resignFederationExecution(ResignAction.NO_ACTION); rtiAmbassadors.get(0).destroyFederationExecution(FEDERATION_NAME); } Modified: trunk/testsuite/src/java/net/sf/ohla/rti1516/OwnershipManagementTestNG.java =================================================================== --- trunk/testsuite/src/java/net/sf/ohla/rti1516/OwnershipManagementTestNG.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/testsuite/src/java/net/sf/ohla/rti1516/OwnershipManagementTestNG.java 2006-11-15 01:31:09 UTC (rev 26) @@ -41,8 +41,8 @@ import hla.rti1516.ObjectInstanceNotKnown; import hla.rti1516.OrderType; import hla.rti1516.RTIambassador; -import static hla.rti1516.ResignAction.NO_ACTION; import hla.rti1516.TransportationType; +import hla.rti1516.ResignAction; import hla.rti1516.jlc.NullFederateAmbassador; @Test(groups = {"Ownership Management"}) @@ -122,8 +122,8 @@ { rtiAmbassadors.get(0).deleteObjectInstance(objectInstanceHandle, null); - rtiAmbassadors.get(0).resignFederationExecution(NO_ACTION); - rtiAmbassadors.get(1).resignFederationExecution(NO_ACTION); + rtiAmbassadors.get(0).resignFederationExecution(ResignAction.NO_ACTION); + rtiAmbassadors.get(1).resignFederationExecution(ResignAction.NO_ACTION); rtiAmbassadors.get(0).destroyFederationExecution(FEDERATION_NAME); } Modified: trunk/testsuite/src/java/net/sf/ohla/rti1516/SupportServicesTestNG.java =================================================================== --- trunk/testsuite/src/java/net/sf/ohla/rti1516/SupportServicesTestNG.java 2006-11-13 03:27:31 UTC (rev 25) +++ trunk/testsuite/src/java/net/sf/ohla/rti1516/SupportServicesTestNG.java 2006-11-15 01:31:09 UTC (rev 26) @@ -36,8 +36,8 @@ import hla.rti1516.ObjectClassHandle; import hla.rti1516.OrderType; import hla.rti1516.ParameterHandle; -import static hla.rti1516.ResignAction.NO_ACTION; import hla.rti1516.TransportationType; +import hla.rti1516.ResignAction; import hla.rti1516.jlc.NullFederateAmbassador; @Test(groups = {"Support Services"}) @@ -57,7 +57,7 @@ public void teardown() throws Exception { - rtiAmbassadors.get(0).resignFederationExecution(NO_ACTION); + rtiAmbassadors.get(0).resignFederationExecution(ResignAction.NO_ACTION); rtiAmbassadors.get(0).destroyFederationExecution(FEDERATION_NAME); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |