copyright The Portico Project 2008.

org.portico.lrc
Class LRCState

java.lang.Object
  extended by org.portico.lrc.LRCState

public class LRCState
extends Object

This class contains all the state information that relates to a specific LRC instance. Rather than pollute the LRC code with all this state-data, it was factored into this separate class. The data here represents the state of the LRC (and the federate that is using it) at any given time. Further entities are stored and accessible through here, including the LRCInstanceRepository that contains a cache of all the relevant object and attribute information that the LRC knows about (such as handles, owners, etc...). Also contained is the LRCInterestManager, which holds all the publication and subscription interests for the federate.

The LRCState class also contains a number of helper methods that can perform common validation checks and can throw the appropriate exception types if the LRC is currently not in a valid state for a particular action to occur.

The LRCState also provides a facility that allows arbitrary properties to be stored within it. This is intended to provided a baseline facility that plugins can use to store and fetch information (rather than having to come up with something of their own). See the getProperty and setProperty method families.


Nested Class Summary
static class LRCState.Status
          This enum is used to describe the current constrained and regulating state of the LRC
static class LRCState.SyncPoint
          This enum governs sync point status
 
Field Summary
private  boolean advancing
           
private  boolean async
           
private  LRCState.Status constrained
           
private  int federateHandle
           
private  String federateName
           
private  String federationName
           
private  ObjectModel fom
           
private  LRCInterestManager interestManager
           
private  boolean joined
           
private  double lookahead
           
private  Map<String,Object> properties
           
private  LRCRegionStore regionStore
           
private  LRCState.Status regulating
           
private  LRCInstanceRepository repository
           
private  HashMap<String,LRCState.SyncPoint> syncPoints
           
private  LRC theLRC
           
private  boolean ticking
           
private  double timeCurrent
           
private  double timeRequested
           
 
Constructor Summary
LRCState(LRC theLRC)
          Create a new LRCState that is linked to the given LRC.
 
Method Summary
 void achieveSyncPoint(String label)
          Mark the given sync point as achieved by this federate.
 void checkAccess()
          Check to see if we are currently ticking (and thus not able to make an RTI callback).
 void checkAdvancing()
          Check to see if we are advancing.
 void checkJoined()
          This method checks to see if the federate associated with this LRC is joined to a federation.
 void checkRestore()
          Checks to see whether or not the LRC is currently in the middle of a restore process.
 void checkSave()
          Checks to see whether or not the LRC is currently in the middle of a save process.
 void checkSyncAnnounced(String label)
          Checks to see if the given synchronization point label has been announced
 void checkSyncNotAchieved(String label)
          Checks to see if the given sync point has already been acheived.
 void checkTimeConstrained()
          Check to see if there is a time constrained enable pending.
 void checkTimeRegulation()
          Check to see if there is a time regulation enable pending.
 void checkValidTime(double time)
          Validate that the given time is valid for the current state (that it is equal to or greater than the current LBTS for this federate).
 void federationSynchronized(String label)
          Remove the given sync point from the store.
 boolean getAsynchronousDelivery()
           
 LRCState.Status getConstrained()
           
 double getCurrentTime()
           
 int getFederateHandle()
           
 String getFederateName()
           
 String getFederationName()
           
 ObjectModel getFOM()
           
 double getLBTS()
          The current requested time + the current look ahead.
 double getLookahead()
           
 LRCInstanceRepository getLRCInstanceRepository()
           
 LRCInterestManager getLRCInterestManager()
           
 LRCRegionStore getLRCRegionStore()
           
 Map<String,Object> getProperties()
          Gets the properties map directly.
 Object getProperty(String key)
          Fetch the value of a previously bound property.
<X> X
getProperty(String key, Class<X> type)
          This is the same as getProperty(String) except that you can specify the type which the contained value should be.
 LRCState.Status getRegulating()
           
 double getRequestedTime()
           
 boolean hasProperty(String key)
          Return true if there is a contained property for the given key, false otherwise.
 boolean isAdvancing()
           
 boolean isConstrained()
           
 boolean isJoined()
           
 boolean isRegulating()
           
 boolean isTicking()
           
 void registerSyncPoint(String label)
          Register the given sync point with the LRC.
 void reinitialize()
          This method clears out any previous status that was contained within the instance.
 void setAdvancing(boolean advancing)
           
 void setAsynchronousDelivery(boolean value)
          This will enable/disable asynchronous delivery.
 void setConstrained(LRCState.Status status)
          Enable/Disable time constrained.
 void setCurrentTime(double time)
           
 void setFederateHandle(int federateHandle)
           
 void setFederateName(String federateName)
           
 void setFederationName(String federationName)
           
 void setFOM(ObjectModel fom)
           
 void setJoined(boolean joined)
           
 void setLookahead(double lookahead)
           
 void setProperty(String key, Object value)
          Add a property to the state.
 void setRegulating(LRCState.Status status)
           
 void setRequestedTime(double time)
           
 void setTicking(boolean ticking)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

private Map<String,Object> properties

theLRC

private LRC theLRC

federateName

private String federateName

federateHandle

private int federateHandle

federationName

private String federationName

joined

private boolean joined

fom

private ObjectModel fom

constrained

private LRCState.Status constrained

regulating

private LRCState.Status regulating

async

private boolean async

advancing

private boolean advancing

ticking

private boolean ticking

timeCurrent

private double timeCurrent

timeRequested

private double timeRequested

lookahead

private double lookahead

interestManager

private LRCInterestManager interestManager

syncPoints

private HashMap<String,LRCState.SyncPoint> syncPoints

repository

private LRCInstanceRepository repository

regionStore

private LRCRegionStore regionStore
Constructor Detail

LRCState

public LRCState(LRC theLRC)
Create a new LRCState that is linked to the given LRC. This constructor calls the reinitialize() method once it is finished in order to set up the initial state.

Method Detail

reinitialize

public void reinitialize()
This method clears out any previous status that was contained within the instance. It is used to given the LRCState its initial values during construction, and it also used to clear out any stale data once a federate resigns from a federation (so that when it joins again, it does so with a clean slate).


registerSyncPoint

public void registerSyncPoint(String label)
Register the given sync point with the LRC. A point should only be registered when the RTI announces it to us (not on the actual register request). This should only be called by handlers in the callback sink. NOTE: This will overwrite any previous sync point that existed in the LRC with the same name (thus, re-announcement of a sync-point should work)


achieveSyncPoint

public void achieveSyncPoint(String label)
                      throws JSynchronizationLabelNotAnnounced
Mark the given sync point as achieved by this federate. When the FEDERATION has achieved the point, it will be removed (not marked as achieved). This should only be called by handlers in the request sink.

Throws:
JSynchronizationLabelNotAnnounced

federationSynchronized

public void federationSynchronized(String label)
Remove the given sync point from the store. This should only occur when the federation becomes synchronized (and thus, only be called from handlers in the callback sink)


checkAccess

public void checkAccess()
                 throws JConcurrentAccessAttempted
Check to see if we are currently ticking (and thus not able to make an RTI callback). If we are currently ticking, a JConcurrentAccessAttempted

Throws:
JConcurrentAccessAttempted

checkAdvancing

public void checkAdvancing()
                    throws JTimeAdvanceAlreadyInProgress
Check to see if we are advancing. If we are, throw an exception.

Throws:
JTimeAdvanceAlreadyInProgress

checkTimeRegulation

public void checkTimeRegulation()
                         throws JEnableTimeRegulationPending
Check to see if there is a time regulation enable pending. If there is, throw an exception

Throws:
JEnableTimeRegulationPending

checkTimeConstrained

public void checkTimeConstrained()
                          throws JEnableTimeConstrainedPending
Check to see if there is a time constrained enable pending. If there is, throw an exception

Throws:
JEnableTimeConstrainedPending

checkValidTime

public void checkValidTime(double time)
                    throws JInvalidFederationTime
Validate that the given time is valid for the current state (that it is equal to or greater than the current LBTS for this federate).

Throws:
JInvalidFederationTime

checkSave

public void checkSave()
               throws JSaveInProgress
Checks to see whether or not the LRC is currently in the middle of a save process. If it is, it throws a JSaveInProgress exception.

Throws:
JSaveInProgress

checkRestore

public void checkRestore()
                  throws JRestoreInProgress
Checks to see whether or not the LRC is currently in the middle of a restore process. If it is, it throws a JRestoreInProgress exception.

Throws:
JRestoreInProgress

checkJoined

public void checkJoined()
                 throws JFederateNotExecutionMember
This method checks to see if the federate associated with this LRC is joined to a federation. If it is not, a FederateNotExecutionMember exception is thrown.

Throws:
JFederateNotExecutionMember

checkSyncAnnounced

public void checkSyncAnnounced(String label)
                        throws JSynchronizationLabelNotAnnounced
Checks to see if the given synchronization point label has been announced

Throws:
JSynchronizationLabelNotAnnounced

checkSyncNotAchieved

public void checkSyncNotAchieved(String label)
                          throws JRTIinternalError
Checks to see if the given sync point has already been acheived. If it has, an exception is thrown.

Throws:
JRTIinternalError

getFederateName

public String getFederateName()

setFederateName

public void setFederateName(String federateName)

getFederateHandle

public int getFederateHandle()

setFederateHandle

public void setFederateHandle(int federateHandle)

getFederationName

public String getFederationName()

setFederationName

public void setFederationName(String federationName)

isJoined

public boolean isJoined()

setJoined

public void setJoined(boolean joined)

getCurrentTime

public double getCurrentTime()

setCurrentTime

public void setCurrentTime(double time)

getRequestedTime

public double getRequestedTime()

setRequestedTime

public void setRequestedTime(double time)

getLookahead

public double getLookahead()

setLookahead

public void setLookahead(double lookahead)

getLBTS

public double getLBTS()
The current requested time + the current look ahead.

NOTE: The requested time is used as it takes into account time advance requests. In the situation where we have no active request, the requested time should be the same as the current time.


getConstrained

public LRCState.Status getConstrained()

setConstrained

public void setConstrained(LRCState.Status status)
Enable/Disable time constrained. Note that this will notify the LRCQueue (as it is caching this value), so there is no need to notify it directly.


isConstrained

public boolean isConstrained()

getRegulating

public LRCState.Status getRegulating()

setRegulating

public void setRegulating(LRCState.Status status)

isRegulating

public boolean isRegulating()

isAdvancing

public boolean isAdvancing()

setAsynchronousDelivery

public void setAsynchronousDelivery(boolean value)
This will enable/disable asynchronous delivery. Note that this method will contact the LRCQueue (as it is caching this value). So there is no need for you to do so.


getAsynchronousDelivery

public boolean getAsynchronousDelivery()

setAdvancing

public void setAdvancing(boolean advancing)

isTicking

public boolean isTicking()

setTicking

public void setTicking(boolean ticking)

getFOM

public ObjectModel getFOM()

setFOM

public void setFOM(ObjectModel fom)

getLRCInterestManager

public LRCInterestManager getLRCInterestManager()

getLRCInstanceRepository

public LRCInstanceRepository getLRCInstanceRepository()

getLRCRegionStore

public LRCRegionStore getLRCRegionStore()

setProperty

public void setProperty(String key,
                        Object value)
Add a property to the state. This facility is meant to be used by handlers/plugins that need to a place to store information. If the key already exists, it will overwrite any value that existed with the given value.


getProperty

public Object getProperty(String key)
Fetch the value of a previously bound property. If there is no property for that key, null will be returned.


getProperty

public <X> X getProperty(String key,
                         Class<X> type)
This is the same as getProperty(String) except that you can specify the type which the contained value should be. If there is no value for that key or the type of the value does not match up with the given value, null is returned. Otherwise, the value is cast to the given type and returned.


hasProperty

public boolean hasProperty(String key)
Return true if there is a contained property for the given key, false otherwise.


getProperties

public Map<String,Object> getProperties()
Gets the properties map directly.


copyright The Portico Project 2008.