public abstract class Codelet extends java.lang.Object implements java.lang.Runnable, MemoryObserver
Modifier and Type | Field and Description |
---|---|
protected double |
activation
Activation level of the Codelet.
|
protected java.util.List<Memory> |
broadcast
Input memories, the ones that were broadcasted.
|
protected java.util.List<Memory> |
inputs
Input memories, the ones that are read.
|
protected boolean |
isMemoryObserver
defines if codelet is a memory observer (runs when memory input changes)
|
java.util.concurrent.locks.Lock |
lock
This variable is a safe lock for multithread access
|
protected boolean |
loop
defines if proc() should be automatically called in a loop
|
protected java.lang.String |
name
Gives this codelet a name, mainly for debugging purposes
|
protected java.util.List<Memory> |
outputs
Output memories, the ones that are written.
|
protected double |
threshold
Threshold of the codelet, which is used to decide if it runs or not.
|
protected long |
timeStep
If the proc() method is set to be called automatically in a loop, this
variable stores the time step for such a loop.
|
Constructor and Description |
---|
Codelet() |
Modifier and Type | Method and Description |
---|---|
abstract void |
accessMemoryObjects()
This method is used in every Codelet to capture input, broadcast and
output MemoryObjects which shall be used in the proc() method.
|
void |
addBroadcast(Memory b)
Adds a memory to the broadcast list.
|
void |
addBroadcasts(java.util.List<Memory> broadcast)
Adds a list of memories to the broadcast input list.
|
void |
addInput(Memory input)
Add one memory to the input list.
|
void |
addInputs(java.util.List<Memory> inputs)
Add a list of memories to the input list.
|
void |
addOutput(Memory output)
Add a memory to the output list.
|
void |
addOutputs(java.util.List<Memory> outputs)
Adds a list of memories to the output list.
|
abstract void |
calculateActivation()
This abstract method must be implemented by the user.
|
double |
getActivation()
Gets this Codelet activation.
|
java.util.List<Memory> |
getBroadcast()
Gets the list of broadcast memories.
|
Memory |
getBroadcast(java.lang.String name)
Returns a specific memory (with the given name) from the broadcast list
of the Codelet.
|
Memory |
getBroadcast(java.lang.String type,
int index)
Return a memory if its name is found at the broadcast list ...
|
boolean |
getEnabled()
Gets the enable status.
|
Memory |
getInput(java.lang.String name)
Gets a certain memory from the input list by its name.
|
Memory |
getInput(java.lang.String type,
int index)
This method returns an input memory from its input list.
|
java.util.List<Memory> |
getInputs()
Gets the input memories list.
|
java.util.ArrayList<Memory> |
getInputsOfType(java.lang.String type)
Gets a list of input memories of a certain type.
|
java.lang.String |
getName()
Gets this Codelet name.
|
Memory |
getOutput(java.lang.String name)
Gets a Memory from the output list by its name.
|
Memory |
getOutput(java.lang.String type,
int index)
This method returns an output memory from its output list.
|
java.util.List<Memory> |
getOutputs()
Gets the list of output memories.
|
java.util.ArrayList<Memory> |
getOutputsOfType(java.lang.String type)
Gets a list of output memories of a certain type.
|
java.lang.String |
getThreadName()
Gets the Codelet's Java Thread name, for debugging purposes.
|
double |
getThreshold()
Gets the Codelet's threshold.
|
long |
getTimeStep()
Gets the Codelet' s timestep.
|
boolean |
impendingAccess(Codelet accesing)
Safe access to other Codelets through reentrant locks.
|
boolean |
impendingAccessBuffer(MemoryBuffer accesing)
Safe access to MemoryBuffers through reentrant locks
|
boolean |
isLoop()
Gets if this Codelet is looping.
|
boolean |
isProfiling()
Gets if this Codelet is profiling.
|
void |
notifyCodelet()
runs when codelet is a memory observer and memory input changes
|
abstract void |
proc()
Main Codelet function, to be implemented in each subclass.
|
void |
removeFromInput(java.util.List<Memory> inputs)
Removes a given list of memories from the input list.
|
void |
removeFromOutput(java.util.List<Memory> outputs)
Removes a given memory list from the output list.
|
void |
removesInput(Memory input)
Removes a given memory from the input list.
|
void |
removesOutput(Memory output)
Removes a given memory from the output list.
|
void |
run()
When first activated, the thread containing this codelet runs the proc()
method
|
void |
setActivation(double activation)
Sets this codelet's activation.
|
void |
setBroadcast(java.util.List<Memory> broadcast)
Sets the list of broadcast memories.
|
void |
setCodeletProfiler(java.lang.String filePath,
java.lang.String fileName,
java.lang.String mindIdentifier,
java.lang.Integer queueSize,
java.lang.Long intervalTimeMillis,
CodeletsProfiler.FileFormat fileFormat)
Sets Codelet Profiler
|
void |
setEnabled(boolean status)
Set the enable status.
|
void |
setInputs(java.util.List<Memory> inputs)
Sets the input memories list.
|
void |
setIsMemoryObserver(boolean isMemoryObserver)
Sets this Codelet to be a memory observer.
|
void |
setLoop(boolean loop)
Sets this Codelet to loop.
|
void |
setName(java.lang.String name)
Sets this Codelet name.
|
void |
setOutputs(java.util.List<Memory> outputs)
Sets the list of output memories.
|
void |
setProfiling(boolean isProfiling)
Sets if this Codelet is profiling.
|
void |
setThreshold(double threshold)
Sets the Codelet's threshold.
|
void |
setTimeStep(long timeStep)
Sets the Codelet's timestep.
|
boolean |
shouldLoop()
Gets if this Codelet is looping.
|
void |
start()
Starts this codelet execution.
|
void |
stop()
Tells this codelet to stop looping (stops running)
|
java.lang.String |
toString() |
protected double activation
protected double threshold
protected java.util.List<Memory> inputs
protected java.util.List<Memory> outputs
protected java.util.List<Memory> broadcast
protected boolean loop
protected boolean isMemoryObserver
protected long timeStep
protected java.lang.String name
public java.util.concurrent.locks.Lock lock
public abstract void accessMemoryObjects()
public abstract void calculateActivation()
public abstract void proc()
public void run()
run
in interface java.lang.Runnable
public void start()
public void stop()
public boolean impendingAccess(Codelet accesing)
accesing
- the Codelet accessing.public boolean impendingAccessBuffer(MemoryBuffer accesing)
accesing
- the Memory Buffer accessing.public boolean shouldLoop()
public void setLoop(boolean loop)
loop
- the loop to setpublic boolean getEnabled()
public void setEnabled(boolean status)
status
- the new enable statuspublic java.lang.String getName()
public void setName(java.lang.String name)
name
- the name to setpublic boolean isLoop()
public double getActivation()
public void setActivation(double activation) throws CodeletActivationBoundsException
activation
- the activation to setCodeletActivationBoundsException
- exception triggered if an activation lower than 0 or bigger
than 1 is setpublic java.util.List<Memory> getInputs()
public void setInputs(java.util.List<Memory> inputs)
inputs
- the inputs to set.public void addInput(Memory input)
input
- one input to set.public void addInputs(java.util.List<Memory> inputs)
inputs
- a list of inputs.public void addOutput(Memory output)
output
- one output to set.public void removesOutput(Memory output)
output
- the memory to be removed from output.public void removesInput(Memory input)
input
- the memory to be removed from input.public void removeFromOutput(java.util.List<Memory> outputs)
outputs
- the list of memories to be removed from output.public void removeFromInput(java.util.List<Memory> inputs)
inputs
- the list of memories to be removed from input.public void addOutputs(java.util.List<Memory> outputs)
outputs
- the list of memories to be added to the output.public java.util.List<Memory> getOutputs()
public java.util.ArrayList<Memory> getOutputsOfType(java.lang.String type)
type
- the type of memories to be fetched from the output.public java.util.ArrayList<Memory> getInputsOfType(java.lang.String type)
type
- the type of memories to be retrieved.public void setOutputs(java.util.List<Memory> outputs)
outputs
- the outputs to set.public java.util.List<Memory> getBroadcast()
public void setBroadcast(java.util.List<Memory> broadcast)
broadcast
- the broadcast to set.public Memory getBroadcast(java.lang.String name)
name
- the name of a memory to be retrieved at the broadcast list.public void addBroadcast(Memory b)
b
- one broadcast input to set.public void addBroadcasts(java.util.List<Memory> broadcast)
broadcast
- one input to set.public java.lang.String getThreadName()
public java.lang.String toString()
toString
in class java.lang.Object
public Memory getInput(java.lang.String type, int index)
type
- type of memory it needs.index
- position of memory in the sublist.public Memory getInput(java.lang.String name)
name
- the name of the memory being searched.public Memory getOutput(java.lang.String type, int index)
type
- type of memory it needs.index
- position of memory in the sublist.public Memory getOutput(java.lang.String name)
name
- the name of the memory.public Memory getBroadcast(java.lang.String type, int index)
type
- the name of the memory to be retrieved in the broadcast list.index
- the index to be considered while multiple equal names are
found within the broadcast list.public double getThreshold()
public void setThreshold(double threshold) throws CodeletThresholdBoundsException
threshold
- the threshold to be set.CodeletThresholdBoundsException
- the exception thrown if the threshold value is less than zero
or greater than 1.public long getTimeStep()
public void setTimeStep(long timeStep)
timeStep
- the timeStep to set.public boolean isProfiling()
public void setProfiling(boolean isProfiling)
isProfiling
- the isProfiling to setpublic void setIsMemoryObserver(boolean isMemoryObserver)
isMemoryObserver
- the isMemoryObserver to setpublic void setCodeletProfiler(java.lang.String filePath, java.lang.String fileName, java.lang.String mindIdentifier, java.lang.Integer queueSize, java.lang.Long intervalTimeMillis, CodeletsProfiler.FileFormat fileFormat)
filePath
- path to create filefileName
- name filemindIdentifier
- mind identifier in filequeueSize
- max queue size which a write in file must be doneintervalTimeMillis
- max interval in millis which a write in file must be donefileFormat
- desired file format CSV or JSONpublic void notifyCodelet()
notifyCodelet
in interface MemoryObserver