core
Class VSInternalProcess

java.lang.Object
  extended by prefs.VSPrefs
      extended by prefs.VSSerializablePrefs
          extended by core.VSAbstractProcess
              extended by core.VSInternalProcess
All Implemented Interfaces:
VSSerializable

public class VSInternalProcess
extends VSAbstractProcess

The class VSInternalProcess, an object of this class represents a process of a simulator.

Author:
Paul C. Buetow

Field Summary
 
Fields inherited from class core.VSAbstractProcess
clockOffset, clockVariance, crashedColor, crashHistory, currentColor, DEFAULT_COLOR_VALUE_KEYS, DEFAULT_FLOAT_VALUE_KEYS, DEFAULT_INTEGER_VALUE_KEYS, DEFAULT_LONG_VALUE_KEYS, DEFAULT_STRING_VALUE_KEYS, globalTime, hasCrashed, hasStarted, isCrashed, isHighlighted, isPaused, lamportTime, lamportTimeHistory, localTime, loging, prefs, processID, processNum, protocolsToReset, random, randomCrashTask, serialVersionUID, simulatorVisualization, tasks, timeModified, tmpColor, vectorTime, vectorTimeHistory
 
Fields inherited from class prefs.VSPrefs
BOOLEAN_PREFIX, COLOR_PREFIX, FLOAT_PREFIX, id, INTEGER_PREFIX, LONG_PREFIX, STRING_PREFIX, VECTOR_PREFIX
 
Constructor Summary
VSInternalProcess(VSPrefs prefs, int processNum, VSSimulatorVisualization simulatorVisualization, VSLogging loging)
          Instantiates a new process.
 
Method Summary
 void addClockOffset(long add)
          Adds the clock offset.
 void addedAProcess()
          Added a process.
protected  void createRandomCrashTask_()
           
 void createRandomCrashTask()
          Creates the random crash task.
 void finish()
          The process' state is 'Finish'.
 long getARandomMessageOutageTime(long durationTime, VSInternalProcess receiverProcess)
          Gets the a random message outage time.
 java.awt.Color getColor()
          Gets the current process' color.
 java.awt.Color getCrashedColor()
          Gets the color of this process if it's crashed.
 VSTask getCrashTask()
          Gets the random crash task.
 long getDurationTime()
           
protected  VSAbstractProtocol getProtocolObject_(java.lang.String protocolClassname)
           
 VSAbstractProtocol getProtocolObject(java.lang.String protocolClassname)
          Gets the protocol object.
 int getRandomPercentage()
          Creates a random percentage 0..100 using the process' own pseudo random number generator object of the VSRandom class.
 VSSimulatorVisualization getSimulatorCanvas()
          Gets the simulator canvas.
 VSPriorityQueue<VSTask> getTasks()
          Gets the tasks of the process.
 void highlightOff()
          Unhighlights the process.
 void highlightOn()
          Highlights the process.
 boolean isPaused()
          Checks if the process is paused.
 void pause()
          The process' state is 'pause'.
 void play()
          The process' state is 'play'.
 void removedAProcessAtIndex(int index)
          Removes the process at the specified index.
 void reset()
          Resets the process.
 void sendMessage(VSMessage message)
          Called by a task if the process sends a message.
 void setGlobalTime(long globalTime)
          Sets the global time.
 void setLocalTime(long localTime)
          Sets the local time.
 void setTasks(VSPriorityQueue<VSTask> tasks)
          Sets the tasks of the process.
 void syncTime(long globalTime)
          Syncs the process' time.
 boolean timeModified()
          Checks if the time has been modified.
 void timeModified(boolean timeModified)
          Sets if the time has been modified by a task.
protected  void updateFromPrefs_()
           
 void updateFromPrefs()
          Called from the VSProcessEditor, after finishing editing! This makes sure that the VSInternalProcess object is using the up to date prefs!
 void updatePrefs()
          Called from the VSProcessEditor, before starting editing! This makes sure that the editor edits the up to date prefs of the process!
 
Methods inherited from class core.VSAbstractProcess
deserialize, equals, fillWithDefaults, getARandomCrashTime, getClockVariance, getCrashHistoryArray, getGlobalTime, getLamportTime, getLamportTimeArray, getPrefs, getProcessID, getProcessNum, getTime, getVectorTime, getVectorTimeArray, hasCrashed, increaseLamportTime, increaseVectorAndLamportTimeIfAll, increaseVectorTime, init, initTimeFormats, isCrashed, isCrashed, log, resetTimeFormats, serialize, setClockVariance, setCurrentColor, setLamportTime, setProcessID, setTime, toString, toStringFull, updateLamportTime, updateVectorTime
 
Methods inherited from class prefs.VSPrefs
clear, copyBooleans, copyColors, copyFloats, copyIntegers, copyLongs, copyStrings, deserialize_, getAllFullKeys, getBoolean, getBooleanKeySet, getBooleanObj, getColor, getColorKeySet, getDescription, getFloat, getFloatKeySet, getFloatObj, getID, getInteger, getIntegerKeySet, getIntegerObj, getLong, getLongKeySet, getLongObj, getObject, getRestriction, getString, getStringKeySet, getUnit, getVector, getVectorKeySet, initBoolean, initBoolean, initBoolean, initColor, initColor, initDescription, initFloat, initFloat, initFloat, initFloat, initInteger, initInteger, initInteger, initInteger, initInteger, initInteger, initLong, initLong, initLong, initLong, initRestriction, initString, initString, initUnit, initVector, initVector, initVector, isEmpty, objectExists, removeObject, serialize_, setBoolean, setBoolean, setColor, setFloat, setFloat, setInteger, setInteger, setLong, setLong, setObject, setString, setVector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VSInternalProcess

public VSInternalProcess(VSPrefs prefs,
                         int processNum,
                         VSSimulatorVisualization simulatorVisualization,
                         VSLogging loging)
Instantiates a new process.

Parameters:
prefs - the simulator's default prefs
processNum - the process num
simulatorVisualization - the simulator canvas
loging - the loging object
Method Detail

updateFromPrefs

public void updateFromPrefs()
Called from the VSProcessEditor, after finishing editing! This makes sure that the VSInternalProcess object is using the up to date prefs!


updatePrefs

public void updatePrefs()
Called from the VSProcessEditor, before starting editing! This makes sure that the editor edits the up to date prefs of the process!


syncTime

public void syncTime(long globalTime)
Syncs the process' time. This method is using the clockOffset and clockVariance variables. This method is called repeatedly from the VSSimulatorVisualization in order to update the process' local and global time values.

Parameters:
globalTime - the global time.

highlightOn

public void highlightOn()
Highlights the process.


highlightOff

public void highlightOff()
Unhighlights the process.


reset

public void reset()
Resets the process.


createRandomCrashTask

public void createRandomCrashTask()
Creates the random crash task. The crash task will be created only if the process is not crashed atm. and if VSInternalProcess.getARandomCrashTime() * returns a non-negative value. The random crash task uses the simulaion's global time for its scheduling.


getRandomPercentage

public int getRandomPercentage()
Creates a random percentage 0..100 using the process' own pseudo random number generator object of the VSRandom class.

Overrides:
getRandomPercentage in class VSAbstractProcess
Returns:
A random percentage 0..100.

addClockOffset

public void addClockOffset(long add)
Adds the clock offset. This method is used by the task manager. The clock offset identifies if the local time of the process has changed and how much..

Overrides:
addClockOffset in class VSAbstractProcess
Parameters:
add - the clock offset to add.

play

public void play()
The process' state is 'play'. Called by the simulator canvas.


pause

public void pause()
The process' state is 'pause'. Called by the simulator canvas.


finish

public void finish()
The process' state is 'Finish'. Called by the simulator canvas.


getColor

public java.awt.Color getColor()
Gets the current process' color.

Returns:
the current color of the process.

getCrashedColor

public java.awt.Color getCrashedColor()
Gets the color of this process if it's crashed.

Returns:
the crashed color

timeModified

public boolean timeModified()
Checks if the time has been modified. by a task. This mehod is needed by the task manager in order to add a clock offset to the process object.

Returns:
true, if yes

timeModified

public void timeModified(boolean timeModified)
Sets if the time has been modified by a task.

Parameters:
timeModified - true, if it has been modified.

setGlobalTime

public void setGlobalTime(long globalTime)
Sets the global time.

Parameters:
globalTime - the new global time

getDurationTime

public long getDurationTime()

getARandomMessageOutageTime

public long getARandomMessageOutageTime(long durationTime,
                                        VSInternalProcess receiverProcess)
Gets the a random message outage time.

Parameters:
durationTime - the duration time
Returns:
the a random message outage time. It will be -1 if the message will not get lost at all.

getCrashTask

public VSTask getCrashTask()
Gets the random crash task.

Returns:
the random crash task

isPaused

public boolean isPaused()
Checks if the process is paused.

Returns:
true, if is paused

sendMessage

public void sendMessage(VSMessage message)
Called by a task if the process sends a message.

Parameters:
message - the message to send.

getSimulatorCanvas

public VSSimulatorVisualization getSimulatorCanvas()
Gets the simulator canvas.

Returns:
the simulator canvas

removedAProcessAtIndex

public void removedAProcessAtIndex(int index)
Removes the process at the specified index. Called by the simulator canvas if a process has been removed from the simulator. Needed in order to update the vector time and the local processNum.

Parameters:
index - the index the process has to get removed.

addedAProcess

public void addedAProcess()
Added a process. Needed in order to update the vector time's size. Called by the simulator canvas if a process has been added to the simulator.


getTasks

public VSPriorityQueue<VSTask> getTasks()
Gets the tasks of the process.

Returns:
The tasks

setTasks

public void setTasks(VSPriorityQueue<VSTask> tasks)
Sets the tasks of the process.

Parameters:
tasks - The tasks

getProtocolObject

public VSAbstractProtocol getProtocolObject(java.lang.String protocolClassname)
Gets the protocol object.

Parameters:
protocolClassname - the protocol classname
Returns:
the protocol object

setLocalTime

public void setLocalTime(long localTime)
Sets the local time.

Parameters:
localTime - the new local time.

updateFromPrefs_

protected void updateFromPrefs_()
Specified by:
updateFromPrefs_ in class VSAbstractProcess

createRandomCrashTask_

protected void createRandomCrashTask_()
Specified by:
createRandomCrashTask_ in class VSAbstractProcess

getProtocolObject_

protected VSAbstractProtocol getProtocolObject_(java.lang.String protocolClassname)
Specified by:
getProtocolObject_ in class VSAbstractProcess