[ohla-devel] SF.net SVN: ohla: [109] trunk/rti/src/java/net/sf/ohla/rti1516/federation
Status: Beta
Brought to you by:
mnewcomb
From: <mne...@us...> - 2007-02-13 02:29:13
|
Revision: 109 http://svn.sourceforge.net/ohla/?rev=109&view=rev Author: mnewcomb Date: 2007-02-12 18:29:11 -0800 (Mon, 12 Feb 2007) Log Message: ----------- - refactoring Modified Paths: -------------- trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java Added Paths: ----------- trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecutionTimeManager.java Removed Paths: ------------- trunk/rti/src/java/net/sf/ohla/rti1516/federation/time/TimeKeeper.java Modified: trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java 2007-02-13 02:08:08 UTC (rev 108) +++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecution.java 2007-02-13 02:29:11 UTC (rev 109) @@ -6,8 +6,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; @@ -21,7 +19,6 @@ import net.sf.ohla.rti1516.fdd.FDD; import net.sf.ohla.rti1516.fdd.ObjectClass; import net.sf.ohla.rti1516.federation.objects.ObjectManager; -import net.sf.ohla.rti1516.federation.time.TimeKeeper; import net.sf.ohla.rti1516.messages.AttributeOwnershipAcquisition; import net.sf.ohla.rti1516.messages.AttributeOwnershipAcquisitionIfAvailable; import net.sf.ohla.rti1516.messages.AttributeOwnershipDivestitureIfWanted; @@ -134,7 +131,7 @@ protected ObjectManager objectManager = new ObjectManager(this); - protected TimeKeeper timeKeeper; + protected FederationExecutionTimeManager federationExecutionTimeManager; protected AtomicInteger objectInstanceCount = new AtomicInteger(Integer.MIN_VALUE); @@ -208,7 +205,7 @@ federatesLock.lock(); try { - if (timeKeeper != null) + if (federationExecutionTimeManager != null) { // TODO: ensure each federate has the same mobile federate services } @@ -216,7 +213,7 @@ { // use the first federate's mobile services // - timeKeeper = new TimeKeeper( + federationExecutionTimeManager = new FederationExecutionTimeManager( this, joinFederationExecution.getMobileFederateServices()); } @@ -229,7 +226,7 @@ WriteFuture writeFuture = session.write(new DefaultResponse( joinFederationExecution.getId(), new JoinFederationExecutionResponse( - federateHandle, fdd, timeKeeper.getGALT()))); + federateHandle, fdd, federationExecutionTimeManager.getGALT()))); log.debug(marker, "federate joined: {}", federate); @@ -1298,7 +1295,7 @@ federationExecutionStateLock.readLock().lock(); try { - timeKeeper.enableTimeRegulation( + federationExecutionTimeManager.enableTimeRegulation( federate, enableTimeRegulation.getLookahead()); } finally @@ -1313,7 +1310,7 @@ federationExecutionStateLock.readLock().lock(); try { - timeKeeper.disableTimeRegulation(federate); + federationExecutionTimeManager.disableTimeRegulation(federate); } finally { @@ -1327,7 +1324,7 @@ federationExecutionStateLock.readLock().lock(); try { - timeKeeper.enableTimeConstrained(federate); + federationExecutionTimeManager.enableTimeConstrained(federate); } finally { @@ -1341,7 +1338,7 @@ federationExecutionStateLock.readLock().lock(); try { - timeKeeper.disableTimeConstrained(federate); + federationExecutionTimeManager.disableTimeConstrained(federate); } finally { @@ -1355,7 +1352,7 @@ federationExecutionStateLock.readLock().lock(); try { - timeKeeper.timeAdvanceRequest(federate, timeAdvanceRequest.getTime()); + federationExecutionTimeManager.timeAdvanceRequest(federate, timeAdvanceRequest.getTime()); } finally { @@ -1369,7 +1366,7 @@ federationExecutionStateLock.readLock().lock(); try { - timeKeeper.timeAdvanceRequestAvailable( + federationExecutionTimeManager.timeAdvanceRequestAvailable( federate, timeAdvanceRequestAvailable.getTime()); } finally Copied: trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecutionTimeManager.java (from rev 104, trunk/rti/src/java/net/sf/ohla/rti1516/federation/time/TimeKeeper.java) =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecutionTimeManager.java (rev 0) +++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/FederationExecutionTimeManager.java 2007-02-13 02:29:11 UTC (rev 109) @@ -0,0 +1,172 @@ +package net.sf.ohla.rti1516.federation; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import hla.rti1516.IllegalTimeArithmetic; +import hla.rti1516.LogicalTime; +import hla.rti1516.LogicalTimeInterval; +import hla.rti1516.MobileFederateServices; + +public class FederationExecutionTimeManager +{ + private static final Logger log = LoggerFactory.getLogger( + FederationExecutionTimeManager.class); + + protected FederationExecution federationExecution; + + protected MobileFederateServices mobileFederateServices; + + protected LogicalTime galt; + + protected Lock timeLock = new ReentrantLock(true); + + protected Set<Federate> timeRegulatingFederates = new HashSet<Federate>(); + protected Set<Federate> timeConstrainedFederates = new HashSet<Federate>(); + + public FederationExecutionTimeManager(FederationExecution federationExecution, + MobileFederateServices mobileFederateServices) + { + this.federationExecution = federationExecution; + this.mobileFederateServices = mobileFederateServices; + + galt = mobileFederateServices.timeFactory.makeInitial(); + } + + public LogicalTime getGALT() + { + return galt; + } + + public void enableTimeRegulation(Federate federate, + LogicalTimeInterval lookahead) + { + timeLock.lock(); + try + { + timeRegulatingFederates.add(federate); + + federate.enableTimeRegulation(galt, lookahead); + } + catch (IllegalTimeArithmetic ita) + { + log.error("unable to enable time regulation", ita); + } + finally + { + timeLock.unlock(); + } + } + + public void disableTimeRegulation(Federate federate) + { + timeLock.lock(); + try + { + timeRegulatingFederates.remove(federate); + + federate.disableTimeRegulation(); + } + finally + { + timeLock.unlock(); + } + } + + public void enableTimeConstrained(Federate federate) + { + timeLock.lock(); + try + { + timeConstrainedFederates.add(federate); + + federate.enableTimeConstrained(galt); + } + finally + { + timeLock.unlock(); + } + } + + public void disableTimeConstrained(Federate federate) + { + timeLock.lock(); + try + { + timeConstrainedFederates.remove(federate); + + federate.disableTimeConstrained(); + } + finally + { + timeLock.unlock(); + } + } + + public void timeAdvanceRequest(Federate federate, LogicalTime time) + { + timeLock.lock(); + try + { + assert galt.compareTo(time) >= 0; + + federate.timeAdvanceRequest(time); + + boolean galtAdvanced = false; + + if (timeRegulatingFederates.contains(federate)) + { + LogicalTime newGALT = mobileFederateServices.timeFactory.makeFinal(); + for (Federate f : timeRegulatingFederates) + { + newGALT = min(newGALT, f.getLITS()); + } + + galtAdvanced = galt.compareTo(newGALT) < 0; + if (galtAdvanced) + { + galt = newGALT; + } + } + + if (galtAdvanced) + { + federationExecution.getFederatesLock().lock(); + try + { + for (Federate f : federationExecution.getFederates().values()) + { + f.galtAdvanced(galt); + } + } + finally + { + federationExecution.getFederatesLock().unlock(); + } + } + } + catch (IllegalTimeArithmetic ita) + { + log.error("unable to request time advance", ita); + } + finally + { + timeLock.unlock(); + } + } + + public void timeAdvanceRequestAvailable(Federate federate, LogicalTime time) + { + timeAdvanceRequest(federate, min(time, galt)); + } + + protected LogicalTime min(LogicalTime lhs, LogicalTime rhs) + { + return lhs.compareTo(rhs) <= 0 ? lhs : rhs; + } +} Deleted: trunk/rti/src/java/net/sf/ohla/rti1516/federation/time/TimeKeeper.java =================================================================== --- trunk/rti/src/java/net/sf/ohla/rti1516/federation/time/TimeKeeper.java 2007-02-13 02:08:08 UTC (rev 108) +++ trunk/rti/src/java/net/sf/ohla/rti1516/federation/time/TimeKeeper.java 2007-02-13 02:29:11 UTC (rev 109) @@ -1,174 +0,0 @@ -package net.sf.ohla.rti1516.federation.time; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import net.sf.ohla.rti1516.federation.Federate; -import net.sf.ohla.rti1516.federation.FederationExecution; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import hla.rti1516.IllegalTimeArithmetic; -import hla.rti1516.LogicalTime; -import hla.rti1516.LogicalTimeInterval; -import hla.rti1516.MobileFederateServices; - -public class TimeKeeper -{ - private static final Logger log = LoggerFactory.getLogger(TimeKeeper.class); - - protected FederationExecution federationExecution; - - protected MobileFederateServices mobileFederateServices; - - protected LogicalTime galt; - - protected Lock timeLock = new ReentrantLock(true); - - protected Set<Federate> timeRegulatingFederates = new HashSet<Federate>(); - protected Set<Federate> timeConstrainedFederates = new HashSet<Federate>(); - - public TimeKeeper(FederationExecution federationExecution, - MobileFederateServices mobileFederateServices) - { - this.federationExecution = federationExecution; - this.mobileFederateServices = mobileFederateServices; - - galt = mobileFederateServices.timeFactory.makeInitial(); - } - - public LogicalTime getGALT() - { - return galt; - } - - public void enableTimeRegulation(Federate federate, - LogicalTimeInterval lookahead) - { - timeLock.lock(); - try - { - timeRegulatingFederates.add(federate); - - federate.enableTimeRegulation(galt, lookahead); - } - catch (IllegalTimeArithmetic ita) - { - log.error("unable to enable time regulation", ita); - } - finally - { - timeLock.unlock(); - } - } - - public void disableTimeRegulation(Federate federate) - { - timeLock.lock(); - try - { - timeRegulatingFederates.remove(federate); - - federate.disableTimeRegulation(); - } - finally - { - timeLock.unlock(); - } - } - - public void enableTimeConstrained(Federate federate) - { - timeLock.lock(); - try - { - timeConstrainedFederates.add(federate); - - federate.enableTimeConstrained(galt); - } - finally - { - timeLock.unlock(); - } - } - - public void disableTimeConstrained(Federate federate) - { - timeLock.lock(); - try - { - timeConstrainedFederates.remove(federate); - - federate.disableTimeConstrained(); - } - finally - { - timeLock.unlock(); - } - } - - public void timeAdvanceRequest(Federate federate, LogicalTime time) - { - timeLock.lock(); - try - { - assert galt.compareTo(time) >= 0; - - federate.timeAdvanceRequest(time); - - boolean galtAdvanced = false; - - if (timeRegulatingFederates.contains(federate)) - { - LogicalTime newGALT = mobileFederateServices.timeFactory.makeFinal(); - for (Federate f : timeRegulatingFederates) - { - newGALT = min(newGALT, f.getLITS()); - } - - galtAdvanced = galt.compareTo(newGALT) < 0; - if (galtAdvanced) - { - galt = newGALT; - } - } - - if (galtAdvanced) - { - federationExecution.getFederatesLock().lock(); - try - { - for (Federate f : federationExecution.getFederates().values()) - { - f.galtAdvanced(galt); - } - } - finally - { - federationExecution.getFederatesLock().unlock(); - } - } - } - catch (IllegalTimeArithmetic ita) - { - log.error("unable to request time advance", ita); - } - finally - { - timeLock.unlock(); - } - } - - public void timeAdvanceRequestAvailable(Federate federate, LogicalTime time) - { - timeAdvanceRequest(federate, min(time, galt)); - } - - protected LogicalTime min(LogicalTime lhs, LogicalTime rhs) - { - return lhs.compareTo(rhs) <= 0 ? lhs : rhs; - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |