org.jactr.core.chunk.basic
Class AbstractChunk

java.lang.Object
  extended by org.jactr.core.chunk.basic.AbstractChunk
All Implemented Interfaces:
java.lang.Comparable<IChunk>, IChunk, Commentable, IMetaContainer
Direct Known Subclasses:
DefaultChunk5

public abstract class AbstractChunk
extends java.lang.Object
implements IChunk

abstract chunk that handles most common logic for the developer.

Author:
harrison

Constructor Summary
AbstractChunk(IModel model)
           
 
Method Summary
 void addListener(IChunkListener cl, java.util.concurrent.Executor executor)
          note : non-locking
 void addListener(IParameterListener pl, java.util.concurrent.Executor executor)
          note : non-locking
 int compareTo(IChunk comparison)
          note : non-locking
 void dispatch(ChunkEvent chunkEvent)
          dispatch an event.
 void dispatch(ParameterEvent pEvent)
          dispatch parameter event
 void dispose()
          called when one is sure that this chunk will NEVER be used.
 void encode(double when)
          note : non-locking
 boolean equalsSymbolic(IChunk chunk)
          returns true if the symbolic contents of the two chunks are the same, i.e.
 java.lang.String getComment()
          note : non-locking
 java.lang.Object getMetaData(java.lang.String key)
          note : non-locking
 java.util.Collection<java.lang.String> getMetaDataKeys()
          return all the keys
 IModel getModel()
          get the model that is responsible for this chunk, note: the chunk may not have been encoded yet
 java.util.concurrent.locks.Lock getReadLock()
          return the read lock for this chunk.
abstract  ISubsymbolicChunk getSubsymbolicChunk()
          return the subsymbolic portion of the chunk
abstract  ISymbolicChunk getSymbolicChunk()
          return the symbolic component of the chunk
 java.util.concurrent.locks.Lock getWriteLock()
          return the read lock for this chunk.
 boolean hasBeenDisposed()
          note : non-locking
 boolean hasListeners()
          note : non-locking
 boolean hasParameterListeners()
          note : non-locking
 boolean isA(IChunkType ct)
          note : non-locking
 boolean isAStrict(IChunkType ct)
          note : non-locking
 boolean isEncoded()
          note : non-locking
 boolean isMutable()
          note : non-locking
 void removeListener(IChunkListener cl)
          note : non-locking
 void removeListener(IParameterListener pl)
          note : non-locking
 void replaceContents(IChunk masterChunk)
          replace the contents of this chunk with those of masterChunk.
 void setComment(java.lang.String comment)
          note : non-locking
 void setMetaData(java.lang.String key, java.lang.Object value)
          Sets the MetaData attribute of the MetaContainer object
 void setMutable(boolean isMutable)
          note : non-locking
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractChunk

public AbstractChunk(IModel model)
Method Detail

getModel

public IModel getModel()
Description copied from interface: IChunk
get the model that is responsible for this chunk, note: the chunk may not have been encoded yet

Specified by:
getModel in interface IChunk
Returns:
See Also:
IChunk.getModel()

dispatch

public void dispatch(ChunkEvent chunkEvent)
Description copied from interface: IChunk
dispatch an event. this is public so that ISymbolicChunk and ISubsymbolicChunk can access it and is not intended to be called by those outside the chunk domain

Specified by:
dispatch in interface IChunk
Parameters:
chunkEvent -
See Also:
IChunk.dispatch(org.jactr.core.chunk.event.ChunkEvent)

dispatch

public void dispatch(ParameterEvent pEvent)
Description copied from interface: IChunk
dispatch parameter event

Specified by:
dispatch in interface IChunk
Parameters:
pEvent -
See Also:
IChunk.dispatch(org.jactr.core.event.ParameterEvent)

hasParameterListeners

public boolean hasParameterListeners()
note : non-locking

Specified by:
hasParameterListeners in interface IChunk
Returns:
See Also:
IChunk.hasParameterListeners()

hasListeners

public boolean hasListeners()
note : non-locking

Specified by:
hasListeners in interface IChunk
Returns:
See Also:
IChunk.hasListeners()

addListener

public void addListener(IChunkListener cl,
                        java.util.concurrent.Executor executor)
note : non-locking

Specified by:
addListener in interface IChunk
Parameters:
cl -
executor -
See Also:
IChunk.addListener(org.jactr.core.chunk.event.IChunkListener, java.util.concurrent.Executor)

addListener

public void addListener(IParameterListener pl,
                        java.util.concurrent.Executor executor)
note : non-locking

Specified by:
addListener in interface IChunk
Parameters:
pl -
executor -
See Also:
IChunk.addListener(org.jactr.core.event.IParameterListener, java.util.concurrent.Executor)

removeListener

public void removeListener(IChunkListener cl)
note : non-locking

Specified by:
removeListener in interface IChunk
Parameters:
cl -
See Also:
IChunk.removeListener(org.jactr.core.chunk.event.IChunkListener)

removeListener

public void removeListener(IParameterListener pl)
note : non-locking

Specified by:
removeListener in interface IChunk
Parameters:
pl -
See Also:
IChunk.removeListener(org.jactr.core.event.IParameterListener)

getSubsymbolicChunk

public abstract ISubsymbolicChunk getSubsymbolicChunk()
Description copied from interface: IChunk
return the subsymbolic portion of the chunk

Specified by:
getSubsymbolicChunk in interface IChunk
Returns:
See Also:
IChunk.getSubsymbolicChunk()

getSymbolicChunk

public abstract ISymbolicChunk getSymbolicChunk()
Description copied from interface: IChunk
return the symbolic component of the chunk

Specified by:
getSymbolicChunk in interface IChunk
Returns:
See Also:
IChunk.getSymbolicChunk()

replaceContents

public void replaceContents(IChunk masterChunk)
replace the contents of this chunk with those of masterChunk. this is done after the merge is complete. note : locking

Parameters:
masterChunk -

compareTo

public int compareTo(IChunk comparison)
note : non-locking

Specified by:
compareTo in interface java.lang.Comparable<IChunk>
Parameters:
comparison -
Returns:
See Also:
Comparable.compareTo(java.lang.Object)

dispose

public void dispose()
Description copied from interface: IChunk
called when one is sure that this chunk will NEVER be used. This should only be called by the IDeclarativeModule. To dispose of a chunk, use IDeclarativeModule.dispose(IChunk) instead

Specified by:
dispose in interface IChunk
See Also:
IChunk.dispose()

hasBeenDisposed

public boolean hasBeenDisposed()
note : non-locking

Specified by:
hasBeenDisposed in interface IChunk
Returns:
See Also:
IChunk.hasBeenDisposed()

encode

public void encode(double when)
note : non-locking

Specified by:
encode in interface IChunk
Parameters:
when - TODO
See Also:
IChunk.encode(double)

isEncoded

public boolean isEncoded()
note : non-locking

Specified by:
isEncoded in interface IChunk
Returns:
See Also:
IChunk.isEncoded()

isA

public boolean isA(IChunkType ct)
note : non-locking

Specified by:
isA in interface IChunk
Parameters:
ct -
Returns:
See Also:
IChunk.isA(org.jactr.core.chunktype.IChunkType)

isAStrict

public boolean isAStrict(IChunkType ct)
note : non-locking

Specified by:
isAStrict in interface IChunk
Parameters:
ct -
Returns:
See Also:
IChunk.isAStrict(org.jactr.core.chunktype.IChunkType)

setComment

public void setComment(java.lang.String comment)
note : non-locking

Specified by:
setComment in interface Commentable
Parameters:
comment -
See Also:
Commentable.setComment(java.lang.String)

getComment

public java.lang.String getComment()
note : non-locking

Specified by:
getComment in interface Commentable
Returns:
See Also:
Commentable.getComment()

getMetaData

public java.lang.Object getMetaData(java.lang.String key)
note : non-locking

Specified by:
getMetaData in interface IMetaContainer
Parameters:
key -
Returns:
See Also:
IMetaContainer.getMetaData(java.lang.String)

setMetaData

public void setMetaData(java.lang.String key,
                        java.lang.Object value)
Description copied from interface: IMetaContainer
Sets the MetaData attribute of the MetaContainer object

Specified by:
setMetaData in interface IMetaContainer
Parameters:
key -
value -
See Also:
IMetaContainer.setMetaData(java.lang.String, java.lang.Object)

getMetaDataKeys

public java.util.Collection<java.lang.String> getMetaDataKeys()
Description copied from interface: IMetaContainer
return all the keys

Specified by:
getMetaDataKeys in interface IMetaContainer
Returns:
See Also:
IMetaContainer.getMetaDataKeys()

isMutable

public boolean isMutable()
note : non-locking

Specified by:
isMutable in interface IChunk
Returns:
See Also:
IChunk.isMutable()

setMutable

public void setMutable(boolean isMutable)
note : non-locking

Specified by:
setMutable in interface IChunk
Parameters:
isMutable -
See Also:
IChunk.setMutable(boolean)

equalsSymbolic

public boolean equalsSymbolic(IChunk chunk)
Description copied from interface: IChunk
returns true if the symbolic contents of the two chunks are the same, i.e. same chunktype and slot values

Specified by:
equalsSymbolic in interface IChunk
Parameters:
chunk - cannot be null
Returns:
true if they are the same symbolically
See Also:
IChunk.equalsSymbolic(org.jactr.core.chunk.IChunk)

getReadLock

public final java.util.concurrent.locks.Lock getReadLock()
Description copied from interface: IChunk
return the read lock for this chunk. this is an internal method made public so that all sym/subsym chunks can access it.
These locks are provided for fine-grained locking. Course use (spanning complex methods) makes deadlock a possibility.
when using the read or write locks it is important to make sure that Lock.unlock() is wrapped within the finally clause.

Additionally, to prevent deadlock, only one chunk at a time should be locked and the locks must be released before event notification.
You should also not save references to the lock, as merging may change the lock, rendering saved references invalid.

Specified by:
getReadLock in interface IChunk
Returns:
See Also:
IChunk.getReadLock()

getWriteLock

public final java.util.concurrent.locks.Lock getWriteLock()
Description copied from interface: IChunk
return the read lock for this chunk. this is an internal method made public so that all sym/subsym chunks can access it
These locks are provided for fine-grained locking. Course use (spanning complex methods) makes deadlock a possibility.
when using the read or write locks it is important to make sure that Lock.unlock() is wrapped within the finally clause.

Additionally, to prevent deadlock, only one chunk at a time should be locked and the locks must be released before event notification.
You should also not save references to the lock, as merging may change the lock, rendering saved references invalid.

Specified by:
getWriteLock in interface IChunk
Returns:
See Also:
IChunk.getWriteLock()