org.jactr.modules.pm.common.memory.map
Class DefaultFINSTFeatureMap

java.lang.Object
  extended by org.jactr.modules.pm.common.memory.map.DefaultFINSTFeatureMap
All Implemented Interfaces:
IAfferentObjectListener, IFeatureMap<FINSTState>, IFINSTFeatureMap
Direct Known Subclasses:
FINSTAuralFeatureMap, FINSTVisualFeatureMap

public class DefaultFINSTFeatureMap
extends java.lang.Object
implements IFINSTFeatureMap

FINST tracking feature map that is used by both the aural and visual modules. Unlike all the other IFeatureMaps, this one is accessed by both the common reality and model threads. As such, it is necessary to use a ReentrantReadWriteLock to protect the data. Commonreality accesses this feature map (like all the other feature maps) through the afferentObjectAdded(IAfferentObject), afferentObjectRemoved(IAfferentObject), afferentObjectUpdated(IAfferentObject, IObjectDelta) methods. The model thread accesses it indirectly through the FlagAsOld timed event which is posted by any call to flagAsAttended(IIdentifier, IChunk, double), flagAsNew(IIdentifier, IChunk, double), or flagAsOld(IIdentifier, IChunk).

Without this thread synchronization, deadlock or concurrent modifications would occur.

There is still much improvement that can be made in terms of the granularity and speed, the current thread safety is course and rather slow. [the old, unprotected version ran allowed models to run at 500x real time, this version brings it down to 250x]

Note: this does not fire events

Author:
developer

Constructor Summary
DefaultFINSTFeatureMap(IModel model, java.lang.String attendedSlotName)
           
 
Method Summary
 void addListener(IFeatureMapListener listener, java.util.concurrent.Executor executor)
           
 void afferentObjectAdded(org.commonreality.object.IAfferentObject object)
           
 void afferentObjectRemoved(org.commonreality.object.IAfferentObject object)
           
 void afferentObjectUpdated(org.commonreality.object.IAfferentObject object, org.commonreality.object.delta.IObjectDelta delta)
           
 void clear()
           
 void dispose()
           
 void fillSlotValues(ChunkTypeRequest mutableRequest, org.commonreality.identifier.IIdentifier identifier, IChunk encodedChunk, ChunkTypeRequest originalSearchRequest)
          fill the slot values accordingly for this identifier at the mutablePattern location this is then used to further specify the actual location chunk that will be returned
 void flagAsAttended(org.commonreality.identifier.IIdentifier identifier, IChunk chunk, double duration)
           
 void flagAsNew(org.commonreality.identifier.IIdentifier identifier, IChunk chunk, double duration)
           
 void flagAsOld(org.commonreality.identifier.IIdentifier identifier, IChunk chunk)
           
 void getAttended(java.util.Set<org.commonreality.identifier.IIdentifier> destination)
           
 void getCandidateRealObjects(ChunkTypeRequest request, java.util.Set<org.commonreality.identifier.IIdentifier> container)
          return all the identifiers of all possible objects that can exist at the visual location defined by this search pattern if nothing is available, and empty collection is to be returned
 FINSTState getInformation(org.commonreality.identifier.IIdentifier identifier)
          returns the feature value for this object
 int getMaximumFINSTs()
           
 void getNew(java.util.Set<org.commonreality.identifier.IIdentifier> destination)
           
 void getOld(java.util.Set<org.commonreality.identifier.IIdentifier> destination)
           
 IPerceptualMemory getPerceptualMemory()
           
 boolean isAttended(org.commonreality.identifier.IIdentifier identifier)
           
 boolean isInterestedIn(ChunkTypeRequest request)
           
 boolean isInterestedIn(org.commonreality.object.IAfferentObject object)
           
 boolean isNew(org.commonreality.identifier.IIdentifier identifier)
           
 boolean isOld(org.commonreality.identifier.IIdentifier identifier)
           
 void normalizeRequest(ChunkTypeRequest request)
          provides an opportunity to normalize any varialbes.
 void removeListener(IFeatureMapListener listener)
           
 void reset()
          reset all the finsts
 void setMaximumFINSTs(int max)
           
 void setPerceptualMemory(IPerceptualMemory memory)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFINSTFeatureMap

public DefaultFINSTFeatureMap(IModel model,
                              java.lang.String attendedSlotName)
Method Detail

addListener

public void addListener(IFeatureMapListener listener,
                        java.util.concurrent.Executor executor)
Specified by:
addListener in interface IFeatureMap<FINSTState>

removeListener

public void removeListener(IFeatureMapListener listener)
Specified by:
removeListener in interface IFeatureMap<FINSTState>

setPerceptualMemory

public void setPerceptualMemory(IPerceptualMemory memory)
Specified by:
setPerceptualMemory in interface IFeatureMap<FINSTState>

getPerceptualMemory

public IPerceptualMemory getPerceptualMemory()
Specified by:
getPerceptualMemory in interface IFeatureMap<FINSTState>

getNew

public void getNew(java.util.Set<org.commonreality.identifier.IIdentifier> destination)
Specified by:
getNew in interface IFINSTFeatureMap
See Also:
org.jactr.modules.pm.common.memory.map.IFINSTFeatureMap#getNew()

isNew

public boolean isNew(org.commonreality.identifier.IIdentifier identifier)
Specified by:
isNew in interface IFINSTFeatureMap

getOld

public void getOld(java.util.Set<org.commonreality.identifier.IIdentifier> destination)
Specified by:
getOld in interface IFINSTFeatureMap

isOld

public boolean isOld(org.commonreality.identifier.IIdentifier identifier)
Specified by:
isOld in interface IFINSTFeatureMap

getAttended

public void getAttended(java.util.Set<org.commonreality.identifier.IIdentifier> destination)
Specified by:
getAttended in interface IFINSTFeatureMap

isAttended

public boolean isAttended(org.commonreality.identifier.IIdentifier identifier)
Specified by:
isAttended in interface IFINSTFeatureMap

getMaximumFINSTs

public int getMaximumFINSTs()
Specified by:
getMaximumFINSTs in interface IFINSTFeatureMap

setMaximumFINSTs

public void setMaximumFINSTs(int max)
Specified by:
setMaximumFINSTs in interface IFINSTFeatureMap

flagAsAttended

public void flagAsAttended(org.commonreality.identifier.IIdentifier identifier,
                           IChunk chunk,
                           double duration)
Specified by:
flagAsAttended in interface IFINSTFeatureMap
See Also:
org.jactr.modules.pm.common.memory.map.IFINSTFeatureMap#flagAsAttended(org.commonreality.identifier.IIdentifier, org.jactr.core.chunk.IChunk)

flagAsNew

public void flagAsNew(org.commonreality.identifier.IIdentifier identifier,
                      IChunk chunk,
                      double duration)
Specified by:
flagAsNew in interface IFINSTFeatureMap
See Also:
org.jactr.modules.pm.common.memory.map.IFINSTFeatureMap#flagAsNew(org.commonreality.identifier.IIdentifier, org.jactr.core.chunk.IChunk)

flagAsOld

public void flagAsOld(org.commonreality.identifier.IIdentifier identifier,
                      IChunk chunk)
Specified by:
flagAsOld in interface IFINSTFeatureMap
See Also:
IFINSTFeatureMap.flagAsOld(org.commonreality.identifier.IIdentifier, org.jactr.core.chunk.IChunk)

reset

public void reset()
Description copied from interface: IFINSTFeatureMap
reset all the finsts

Specified by:
reset in interface IFINSTFeatureMap
See Also:
IFINSTFeatureMap.reset()

clear

public void clear()
Specified by:
clear in interface IFeatureMap<FINSTState>
See Also:
IFeatureMap.clear()

dispose

public void dispose()
Specified by:
dispose in interface IFeatureMap<FINSTState>
See Also:
IFeatureMap.dispose()

fillSlotValues

public void fillSlotValues(ChunkTypeRequest mutableRequest,
                           org.commonreality.identifier.IIdentifier identifier,
                           IChunk encodedChunk,
                           ChunkTypeRequest originalSearchRequest)
Description copied from interface: IFeatureMap
fill the slot values accordingly for this identifier at the mutablePattern location this is then used to further specify the actual location chunk that will be returned

Specified by:
fillSlotValues in interface IFeatureMap<FINSTState>
Parameters:
mutableRequest - the pseudo visual location to be setup
encodedChunk - TODO
See Also:
IFeatureMap.fillSlotValues(ChunkTypeRequest, org.commonreality.identifier.IIdentifier, IChunk, ChunkTypeRequest)

getInformation

public FINSTState getInformation(org.commonreality.identifier.IIdentifier identifier)
Description copied from interface: IFeatureMap
returns the feature value for this object

Specified by:
getInformation in interface IFeatureMap<FINSTState>
Returns:

getCandidateRealObjects

public void getCandidateRealObjects(ChunkTypeRequest request,
                                    java.util.Set<org.commonreality.identifier.IIdentifier> container)
Description copied from interface: IFeatureMap
return all the identifiers of all possible objects that can exist at the visual location defined by this search pattern if nothing is available, and empty collection is to be returned

Specified by:
getCandidateRealObjects in interface IFeatureMap<FINSTState>
See Also:
IFeatureMap.getCandidateRealObjects(ChunkTypeRequest, Set)

afferentObjectAdded

public void afferentObjectAdded(org.commonreality.object.IAfferentObject object)
Specified by:
afferentObjectAdded in interface IAfferentObjectListener
See Also:
IAfferentObjectListener.afferentObjectAdded(org.commonreality.object.IAfferentObject)

afferentObjectRemoved

public void afferentObjectRemoved(org.commonreality.object.IAfferentObject object)
Specified by:
afferentObjectRemoved in interface IAfferentObjectListener
See Also:
IAfferentObjectListener.afferentObjectRemoved(org.commonreality.object.IAfferentObject)

afferentObjectUpdated

public void afferentObjectUpdated(org.commonreality.object.IAfferentObject object,
                                  org.commonreality.object.delta.IObjectDelta delta)
Specified by:
afferentObjectUpdated in interface IAfferentObjectListener
See Also:
IAfferentObjectListener.afferentObjectUpdated(org.commonreality.object.IAfferentObject, org.commonreality.object.delta.IObjectDelta)

isInterestedIn

public boolean isInterestedIn(org.commonreality.object.IAfferentObject object)
Specified by:
isInterestedIn in interface IAfferentObjectListener
See Also:
IAfferentObjectListener.isInterestedIn(org.commonreality.object.IAfferentObject)

isInterestedIn

public boolean isInterestedIn(ChunkTypeRequest request)
Specified by:
isInterestedIn in interface IFeatureMap<FINSTState>

normalizeRequest

public void normalizeRequest(ChunkTypeRequest request)
Description copied from interface: IFeatureMap
provides an opportunity to normalize any varialbes. will only be called if IFeatureMap.isInterestedIn(ChunkTypeRequest)

Specified by:
normalizeRequest in interface IFeatureMap<FINSTState>