gov.nasa.arc.brahms.vm.rt
Class VMJavaObjectCtx

java.lang.Object
  extended by gov.nasa.arc.brahms.vm.rt.VMJavaObjectCtx
All Implemented Interfaces:
gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement

public class VMJavaObjectCtx
extends java.lang.Object
implements gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement

VMJavaObjectCtx is a Virtual Machine context object used for memory management of Java objects that are the subject of Brahms facts and beliefs.

Version:
$Revision: 1.3 $ $Date: 2011/06/15 12:55:13 $ $Author: rvanhoof $
Author:
Bob Nado

Constructor Summary
VMJavaObjectCtx(java.lang.Object object)
          Constructor, creates a new context for the specified Java object.
 
Method Summary
 void addDeletedListener(gov.nasa.arc.brahms.vm.memory.IDeletedListener listener)
          Registers the specified listener to be notified when this element was deleted.
 void addEventReference(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Adds the specified DiscreteEvent as an event in which this element is referenced.
 void addFrameBindingReference(ActiveInstance refHolder, gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode frame, gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode.FrameBinding binding)
          Adds the specified FrameBinding as a binding in which this element was used in a variable in the completed execution of the frame defined by the RSNFrameNode executed by the specified ActiveInstance.
 gov.nasa.arc.brahms.vm.memory.HardReference addHardReference(ActiveInstance refHolder, long time)
          Adds the specified refHolder as an ActiveInstance holding a hard reference to this concept.
 gov.nasa.arc.brahms.vm.memory.SoftReference addSoftReference(ActiveInstance refHolder, long time)
          Adds the specified refHolder as an ActiveInstance holding a soft reference to this concept.
 void addStatementReference(ActiveInstance refHolder, VMStatementCtx statement, long time)
          Adds the specified VMStatementCtx as a statement in which this element is referenced, either on the left or right hand side asserted by the specified ActiveInstance.
static VMJavaObjectCtx createContext(java.lang.Object object)
          Retrieve the VMJavaObjectCtx context for a given Java object or create a new one if it doesn't already exist.
 void finalizeDelete(long time)
          Finalizes the deletes of this element from memory, cleaning up any internal structures kept for this element and marking the element as deleted.
static VMJavaObjectCtx getContext(java.lang.Object object)
          Retrieve the VMJavaObjectCtx context for a given Java object
 java.lang.Object getElement()
          Returns the object for which memory is being managed.
 java.util.List<gov.nasa.arc.brahms.vm.memory.SoftReference> getSoftReferences()
          Returns a list of all the actors holding a soft reference to this element.
 boolean hasEventReferences()
          Indicates whether any events hold references to this element.
 boolean hasSoftReferences()
          Indicates whether there are any actors that hold a soft reference to this element.
 void initiateDelete(long time)
          Initiates the deletion of this element from memory causing the element to be marked as in the process of being deleted and causing the retraction of the facts referencing the element.
 boolean isDeleted()
          Indicates whether the element was deleted.
 boolean isDeleteInitiated()
          Indicates whether the process to start the deletion of the element was started.
 boolean isMarkedForGC()
          Indicates whether the element is marked for garbage collection.
static void removeContext(java.lang.Object object)
          Removes the context, if any, associated with a given Java object
 void removeEventReference(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
          Removes the specified DiscreteEvent as an event in which this element is referenced.
 void removeFrameBindingReference(ActiveInstance refHolder, gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode frame, gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode.FrameBinding binding)
          Removes the specified FrameBinding as a binding in which this element was used in a variable in the completed execution of the frame defined by the RSNFrameNode executed by the specified ActiveInstance.
 void removeHardReference(ActiveInstance refHolder, long time)
          Removes the specified refHolder as an ActiveInstance holding a hard reference to this concept.
 void removeSoftReference(ActiveInstance refHolder, long time)
          Removes the specified refHolder as an ActiveInstance holding a soft reference to this concept.
 void removeStatementReference(ActiveInstance refHolder, VMStatementCtx statement, long time)
          Removes the specified VMStatementCtx as a statement in which the element is referenced, either on the left or right hand side retracted by the specified ActiveInstance.
 void setMarkedForGC(boolean marked)
          Sets whether the element is marked for garbage collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VMJavaObjectCtx

public VMJavaObjectCtx(java.lang.Object object)
Constructor, creates a new context for the specified Java object.

Parameters:
object - the Java object for which a context is to be created
Method Detail

createContext

public static VMJavaObjectCtx createContext(java.lang.Object object)
Retrieve the VMJavaObjectCtx context for a given Java object or create a new one if it doesn't already exist.

Parameters:
object - the Java object whose context is to be retrieved or created
Returns:
VMJavaObjectCtx the context for the Java object

getContext

public static VMJavaObjectCtx getContext(java.lang.Object object)
Retrieve the VMJavaObjectCtx context for a given Java object

Parameters:
object - the Java object whose context is to be retrieved
Returns:
VMJavaObjectCtx the context for the Java object or null if none exists

removeContext

public static void removeContext(java.lang.Object object)
Removes the context, if any, associated with a given Java object

Parameters:
object - the Java object whose context object is to be removed

getElement

public java.lang.Object getElement()
                            throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Returns the object for which memory is being managed.

Specified by:
getElement in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Returns:
Object the object of memory management
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if there is an error obtaining the object

addHardReference

public gov.nasa.arc.brahms.vm.memory.HardReference addHardReference(ActiveInstance refHolder,
                                                                    long time)
Adds the specified refHolder as an ActiveInstance holding a hard reference to this concept. A hard reference is a reference held by an ActiveInstance that has behavior (frames) as a result of either creating the concept or as a result of a belief assertion in which the belief references this concept.

Specified by:
addHardReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
refHolder - the ActiveInstance holding a reference to this concept
time - the event time at which the reference is added
Returns:
HardReference the HardReference created for the ActiveInstance

removeHardReference

public void removeHardReference(ActiveInstance refHolder,
                                long time)
Removes the specified refHolder as an ActiveInstance holding a hard reference to this concept. A hard reference is a reference held by an ActiveInstance that has behavior (frames) as a result of either creating the concept or as a result of a belief assertion in which the belief references this concept.

If the specified refHolder is not listed as a concept holding a reference to this concept then this method is a no-op.

Specified by:
removeHardReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
refHolder - the ActiveInstance that no longer holds any references to this concept
time - the event time at which the reference is removed

addSoftReference

public gov.nasa.arc.brahms.vm.memory.SoftReference addSoftReference(ActiveInstance refHolder,
                                                                    long time)
Adds the specified refHolder as an ActiveInstance holding a soft reference to this concept. A soft reference is a reference held by an ActiveInstance that has no behavior (no frames) as a result of a belief assertion in which the belief references this concept.

Specified by:
addSoftReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
refHolder - the ActiveInstance holding a reference to this concept
time - the event time at which the reference is added
Returns:
SoftReference the SoftReference created for the ActiveInstance

removeSoftReference

public void removeSoftReference(ActiveInstance refHolder,
                                long time)
Removes the specified refHolder as an ActiveInstance holding a soft reference to this concept. A soft reference is a reference held by an ActiveInstance that has no behavior (no frames) as a result of a belief assertion in which the belief references this concept.

If the specified refHolder is not listed as a concept holding a reference to this concept then this method is a no-op.

Specified by:
removeSoftReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
refHolder - the ActiveInstance that no longers holds any references to this concept
time - the event time at which the reference is removed

hasSoftReferences

public boolean hasSoftReferences()
Indicates whether there are any actors that hold a soft reference to this element.

Specified by:
hasSoftReferences in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Returns:
boolean true if there are soft references, false otherwise

getSoftReferences

public java.util.List<gov.nasa.arc.brahms.vm.memory.SoftReference> getSoftReferences()
Returns a list of all the actors holding a soft reference to this element.

Specified by:
getSoftReferences in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Returns:
List the list of SoftReferences

addEventReference

public void addEventReference(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Adds the specified DiscreteEvent as an event in which this element is referenced. These references need to maintained to ensure that during the transfer of beliefs these beliefs can be asserted by the recipient before the element is actually deleted. An element could otherwise be deleted before the recipient has had a chance to assert beliefs about it and to claim ownership of a reference to the element.

Specified by:
addEventReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
evt - the DiscreteEvent in which the element is referenced

removeEventReference

public void removeEventReference(gov.nasa.arc.brahms.vm.events.DiscreteEvent evt)
Removes the specified DiscreteEvent as an event in which this element is referenced. These references need to maintained to ensure that during the transfer of beliefs these beliefs can be asserted by the recipient before the element is actually deleted. An element could otherwise be deleted before the recipient has had a chance to assert beliefs about it and to claim ownership of a reference to the element.

Specified by:
removeEventReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
evt - the DiscreteEvent in which the element is referenced

hasEventReferences

public boolean hasEventReferences()
Indicates whether any events hold references to this element.

Specified by:
hasEventReferences in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Returns:
boolean true if there are event references, false otherwise

addStatementReference

public void addStatementReference(ActiveInstance refHolder,
                                  VMStatementCtx statement,
                                  long time)
Adds the specified VMStatementCtx as a statement in which this element is referenced, either on the left or right hand side asserted by the specified ActiveInstance.

Specified by:
addStatementReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
refHolder - the ActiveInstance that asserted the statement referencing this element
statement - the VMStatementCtx to be added
time - the time at which the statement reference is added

removeStatementReference

public void removeStatementReference(ActiveInstance refHolder,
                                     VMStatementCtx statement,
                                     long time)
Removes the specified VMStatementCtx as a statement in which the element is referenced, either on the left or right hand side retracted by the specified ActiveInstance.

Specified by:
removeStatementReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
refHolder - the ActiveInstance that retracted the statement referencing this element
statement - the VMStatementCtx to be removed
time - the time at which the statement reference is removed

addFrameBindingReference

public void addFrameBindingReference(ActiveInstance refHolder,
                                     gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode frame,
                                     gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode.FrameBinding binding)
Adds the specified FrameBinding as a binding in which this element was used in a variable in the completed execution of the frame defined by the RSNFrameNode executed by the specified ActiveInstance. This binding only exists if the frame's repeat property is set to false.

Specified by:
addFrameBindingReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
refHolder - the ActiveInstance that executed the frame
frame - the RSNFrameNode in which the used binding is maintained
binding - the FrameBinding in which the element is referenced

removeFrameBindingReference

public void removeFrameBindingReference(ActiveInstance refHolder,
                                        gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode frame,
                                        gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode.FrameBinding binding)
Removes the specified FrameBinding as a binding in which this element was used in a variable in the completed execution of the frame defined by the RSNFrameNode executed by the specified ActiveInstance. This binding only exists if the frame's repeat property is set to false.

Specified by:
removeFrameBindingReference in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
refHolder - the ActiveInstance that executed the frame
frame - the RSNFrameNode in which the used binding is maintained
binding - the FrameBinding in which the element is referenced

setMarkedForGC

public void setMarkedForGC(boolean marked)
Sets whether the element is marked for garbage collection. True when the element was added to the garbage collector, false if the element is not yet added to the garbage collector.

Specified by:
setMarkedForGC in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
marked - true if marked, false if not

isMarkedForGC

public boolean isMarkedForGC()
Indicates whether the element is marked for garbage collection. True when the element was added to the garbage collector, false if the element is not yet added to the garbage collector.

Specified by:
isMarkedForGC in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Returns:
boolean true if marked, false if not

initiateDelete

public void initiateDelete(long time)
Initiates the deletion of this element from memory causing the element to be marked as in the process of being deleted and causing the retraction of the facts referencing the element.

Specified by:
initiateDelete in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
time - the event time at which the element's deletion is initiated

isDeleteInitiated

public boolean isDeleteInitiated()
Indicates whether the process to start the deletion of the element was started.

Specified by:
isDeleteInitiated in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Returns:
boolean true if the element is in the process of being deleted, false otherwise

finalizeDelete

public void finalizeDelete(long time)
Finalizes the deletes of this element from memory, cleaning up any internal structures kept for this element and marking the element as deleted.

Specified by:
finalizeDelete in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
time - the event time at which the element's deletion is finalized

addDeletedListener

public void addDeletedListener(gov.nasa.arc.brahms.vm.memory.IDeletedListener listener)
Registers the specified listener to be notified when this element was deleted. This listener is automatically deregistered after the listener was notified of the deletion.

Specified by:
addDeletedListener in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Parameters:
listener - the IDeletedListener to be added

isDeleted

public boolean isDeleted()
Indicates whether the element was deleted.

Specified by:
isDeleted in interface gov.nasa.arc.brahms.vm.memory.IMemoryManagedElement
Returns:
boolean true if the element was deleted, false otherwise


Copyright © 1997-2012 All Rights Reserved.