com.grandcentral.appstats.impl
Class SynchronizedTaskImpl

java.lang.Object
  |
  +--com.grandcentral.appstats.impl.TaskImpl
        |
        +--com.grandcentral.appstats.impl.SynchronizedTaskImpl
All Implemented Interfaces:
java.io.Serializable, Task

public class SynchronizedTaskImpl
extends TaskImpl

Description: A synchronized Task implementation

Copyright: Copyright (c) 2002

Company: Grand Central Communications

Version:
1.0
Author:
Taras Shkvarchuk, Adrian Dorsman
See Also:
Serialized Form

Fields inherited from class com.grandcentral.appstats.impl.TaskImpl
INITIAL_MAP_SIZE, m_agg, m_children, m_errors, m_flushListeners, m_maxErrors, m_name, m_parent, m_statCalculators, m_statMap, m_updateTaskListeners
 
Fields inherited from interface com.grandcentral.appstats.Task
DEFAULT_MAXERRORS, STAT_ERRORCOUNT, TASK_STATE_DEFAULT_NAME, TASK_TIMER_DEFAULT_NAME
 
Constructor Summary
SynchronizedTaskImpl()
           
 
Method Summary
 void addChild(Task newChild)
          Adds a child subtask to this process.
 void addError(java.lang.Throwable ex)
          Adds an error to the list.
 void aggregate(Task task)
          Prcesses data from the finished task, updating any internal counters.
 void clear()
          clears all stats, errors, and calls clear() on all StatCalculators
 void clearErrors()
          deletes all errors from this Task
 Stat exists(java.lang.String statName)
          Returns Stat if stat by that name exists.
 void flush()
          Marks that this task's job is finished and allows parent Process to record this task's results.
 java.util.List getChildren()
          Returns all child tasks, or null if none are present.
 Counter getCounter(java.lang.String name)
          Returns named counter, if such counter does not exist, new one will be created
 java.util.List getErrors()
          Returns a list of Throwable errors registered with this Task.
 int getMaxErrorDepth()
           
 java.lang.String getName()
          Displayable name
 Task getParent()
          Returns parent object or null iof there is no parent
 java.lang.String getProperty(java.lang.String name)
           
 Stat getStat(java.lang.String name)
          Returns existing stat by statName, or creates a new one.
 Stat getStat(java.lang.String name, int type)
          convenience method to provide a stat with the specified type.
 StatAggregator getStatAggregator()
           
 Stat getStatByFullName(java.lang.String fullname)
          locates a Stat in this Task or a child task based on its fullname
 java.util.List getStatNames()
          Note: This MUST be a NEW list, to avoid ConcurrentModificationException.
 java.util.List getStatNames(int depth)
          This function returns stat names visible to this task.
 java.util.List getStats()
          Note: This MUST be a NEW list, to avoid ConcurrentModificationException in multithreaded envitoment
 java.util.List getStats(java.util.Collection names, int depth)
          Stats returned are those matching full names specified in the Collection.
 java.util.List getStats(int depth)
          This function returns stats visible to this task.
Note: If any stats belong to the children of this they are cloned.
 Timer getTimer(java.lang.String name)
          Returns a Timer for a given type of operation.
 void putCounter(Counter counter)
          Overwrites old counter with a new one.
 void putStat(Stat stat)
          stores a Stat in this stat.
 void putTimer(Timer timer)
           
 void registerFlushListener(FlushListener l)
           
 void registerStatCalculator(StatCalculator c, java.lang.String statName)
          StatCalculator is called upon Task flush/aggregation whenever a stat is encountered with the following statName.
 void registerUpdateTaskListener(UpdateTaskListener listener)
          Registers an updateTaskListener with this object
 void removeChild(Task oldChild)
          Removes a child task from the list of active children.
 void removeCounter(java.lang.String name)
           
 void removeFlushListener(FlushListener l)
           
protected  void removeParent()
           
 void removeStat(Stat stat)
           
 void removeStat(java.lang.String statName)
           
 void removeStatCalculator(java.lang.String statName)
           
 boolean removeStats(java.util.Collection c)
          Removes all Stats that are not present in the collection.
 void removeStatsThatStartWith(java.lang.String s)
          removes all stats whose statNames start with s.
 void removeTimer(java.lang.String name)
           
 void removeUpdateTaskListener(UpdateTaskListener listener)
          removes the task listener registered with a specific child
 void setMaxErrorDepth(int maxErrors)
          Alter the maximum number of most recent errors to keep in this Task.
 void setName(java.lang.String name)
          Sets name of this task.
protected  void setParent(Task parent)
           
 void setProperty(java.lang.String name, java.lang.String property)
          Note: if property is null, stat will get Removed even if it contains any additional data
 void setStatAggregator(StatAggregator sa)
           
 void update()
          Must be called by the viewer code, before accessing stats.
Causes all UpdateTaskListeners to update any fields in the task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchronizedTaskImpl

public SynchronizedTaskImpl()
Method Detail

setName

public void setName(java.lang.String name)
Description copied from class: TaskImpl
Sets name of this task. This name will be used during aggregation to indicate where stats came from. A taskname must not contain the Stat.DELIM_TASKPARENT character and must not be null.
Overrides:
setName in class TaskImpl
Following copied from class: com.grandcentral.appstats.impl.TaskImpl
Parameters:
name -  
Throws:
java.lang.IllegalArgumentException - if given name is not allowed

getName

public java.lang.String getName()
Description copied from interface: Task
Displayable name
Overrides:
getName in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Returns:
Name of the task

getStatAggregator

public StatAggregator getStatAggregator()
Overrides:
getStatAggregator in class TaskImpl

setStatAggregator

public void setStatAggregator(StatAggregator sa)
Overrides:
setStatAggregator in class TaskImpl

getTimer

public Timer getTimer(java.lang.String name)
               throws java.lang.ClassCastException
Description copied from interface: Task
Returns a Timer for a given type of operation. If no timer with the given name is registered, a new one will be created and returned.
One timer should be used only for ONE logical operation, it is allowed to stop and start the same Timer if operation if logicaly the same.
Overrides:
getTimer in class TaskImpl
Parameters:
name -  
Throws:
java.lang.ClassCastException -  

putTimer

public void putTimer(Timer timer)
Overrides:
putTimer in class TaskImpl

removeTimer

public void removeTimer(java.lang.String name)
Overrides:
removeTimer in class TaskImpl

putCounter

public void putCounter(Counter counter)
Description copied from interface: Task
Overwrites old counter with a new one.
Use with caution since something may still be updating the old counter.
Overrides:
putCounter in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Parameters:
counter -  

getCounter

public Counter getCounter(java.lang.String name)
Description copied from interface: Task
Returns named counter, if such counter does not exist, new one will be created
Overrides:
getCounter in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Parameters:
name - of the desired counter
Returns:
Counter type object

removeCounter

public void removeCounter(java.lang.String name)
Overrides:
removeCounter in class TaskImpl

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String property)
Description copied from class: TaskImpl
Note: if property is null, stat will get Removed even if it contains any additional data
Overrides:
setProperty in class TaskImpl
Following copied from class: com.grandcentral.appstats.impl.TaskImpl
Parameters:
property - set to null to REMOVE property

getProperty

public java.lang.String getProperty(java.lang.String name)
Overrides:
getProperty in class TaskImpl

putStat

public void putStat(Stat stat)
Description copied from interface: Task
stores a Stat in this stat. Overrides any previously stored stat w/ same statName.
Overrides:
putStat in class TaskImpl

removeStat

public void removeStat(java.lang.String statName)
Overrides:
removeStat in class TaskImpl

removeStat

public void removeStat(Stat stat)
Overrides:
removeStat in class TaskImpl

removeStatsThatStartWith

public void removeStatsThatStartWith(java.lang.String s)
Description copied from interface: Task
removes all stats whose statNames start with s. Anybody got a better naming convention?
Overrides:
removeStatsThatStartWith in class TaskImpl

getStat

public Stat getStat(java.lang.String name)
Description copied from interface: Task
Returns existing stat by statName, or creates a new one.
Overrides:
getStat in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Parameters:
name -  
Returns:
Stat, never null

getStat

public Stat getStat(java.lang.String name,
                    int type)
convenience method to provide a stat with the specified type. Will override any existing stat's type if it is different than the type passed into this method.
Overrides:
getStat in class TaskImpl

getStatByFullName

public Stat getStatByFullName(java.lang.String fullname)
Description copied from interface: Task
locates a Stat in this Task or a child task based on its fullname
Overrides:
getStatByFullName in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Returns:
a Stat if one found or null if none found
See Also:
Task.update(), Stat.getFullName()

getStats

public java.util.List getStats()
Description copied from class: TaskImpl
Note: This MUST be a NEW list, to avoid ConcurrentModificationException in multithreaded envitoment
Overrides:
getStats in class TaskImpl
Following copied from class: com.grandcentral.appstats.impl.TaskImpl
Returns:
List with the stats visible to this Task.

getStats

public java.util.List getStats(int depth)
Description copied from class: TaskImpl
This function returns stats visible to this task.
Note: If any stats belong to the children of this they are cloned.
Overrides:
getStats in class TaskImpl
Following copied from class: com.grandcentral.appstats.impl.TaskImpl
Parameters:
depth - number of levels to get stats of. [-1, 0, 1, 2, 3...) (-1)-full depth, (0)-just this task, (1)-immediate children, etc. Warning: Maximum depth is limited to abs(Integer.MIN_VALUE)
Returns:
List with all requested stats.

getStatNames

public java.util.List getStatNames()
Description copied from class: TaskImpl
Note: This MUST be a NEW list, to avoid ConcurrentModificationException.
Overrides:
getStatNames in class TaskImpl
Following copied from class: com.grandcentral.appstats.impl.TaskImpl
Returns:
List of stat names that belong to this task

getStatNames

public java.util.List getStatNames(int depth)
Description copied from class: TaskImpl
This function returns stat names visible to this task.
Overrides:
getStatNames in class TaskImpl
Following copied from class: com.grandcentral.appstats.impl.TaskImpl
Parameters:
depth - number of levels to get stats of. [-1, 0, 1, 2, 3...) (-1)-full depth, (0)-just this task, (1)-immediate children, etc. Warning: Maximum depth is limited to abs(Integer.MIN_VALUE)
Returns:
List with all requested stat names.

exists

public Stat exists(java.lang.String statName)
Description copied from interface: Task
Returns Stat if stat by that name exists. Otherwise null.
Overrides:
exists in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Parameters:
statName -  
Returns:
Stat or null

addError

public void addError(java.lang.Throwable ex)
Description copied from interface: Task
Adds an error to the list. Newly added error will appear 1st in the list. If maxErrorDepth is reached, last error will be removed from the list.
Overrides:
addError in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Parameters:
ex -  
See Also:
setMaxErrorDepth()

getErrors

public java.util.List getErrors()
Description copied from interface: Task
Returns a list of Throwable errors registered with this Task. The first error on the list will be the most recent; the last error will be the oldest.
Overrides:
getErrors in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Returns:
java.util.List

clearErrors

public void clearErrors()
Description copied from interface: Task
deletes all errors from this Task
Overrides:
clearErrors in class TaskImpl

setMaxErrorDepth

public void setMaxErrorDepth(int maxErrors)
Description copied from interface: Task
Alter the maximum number of most recent errors to keep in this Task. Default is 10. Set to -1 to keep all errors until explicitely cleared.
Overrides:
setMaxErrorDepth in class TaskImpl

getMaxErrorDepth

public int getMaxErrorDepth()
Overrides:
getMaxErrorDepth in class TaskImpl

flush

public void flush()
           throws DatatypeMismatchException
Marks that this task's job is finished and allows parent Process to record this task's results.
After data is recorded, all properties, counters, timers, etc are cleared. Name of the task is preserved.
The running timer of this task is stopped, but is NOT reset. Call startTaskTimer() before reuse. After this call task is ready to record new data.
Overrides:
flush in class TaskImpl
Following copied from class: com.grandcentral.appstats.impl.TaskImpl
See Also:
TaskImpl.update(), TaskImpl.aggregate(com.grandcentral.appstats.Task)

getParent

public Task getParent()
Description copied from interface: Task
Returns parent object or null iof there is no parent
Overrides:
getParent in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Returns:
Process

setParent

protected void setParent(Task parent)
Overrides:
setParent in class TaskImpl

removeParent

protected void removeParent()
Overrides:
removeParent in class TaskImpl

addChild

public void addChild(Task newChild)
Description copied from interface: Task
Adds a child subtask to this process.
Overrides:
addChild in class TaskImpl

removeChild

public void removeChild(Task oldChild)
Description copied from interface: Task
Removes a child task from the list of active children.
Overrides:
removeChild in class TaskImpl

getChildren

public java.util.List getChildren()
Description copied from interface: Task
Returns all child tasks, or null if none are present.
Overrides:
getChildren in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Returns:
List of Task objects

registerUpdateTaskListener

public void registerUpdateTaskListener(UpdateTaskListener listener)
Description copied from interface: Task
Registers an updateTaskListener with this object

References to UpdateTaskListeners are not serialized along with the Task since they may or may not be serializable themselves.

Overrides:
registerUpdateTaskListener in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Parameters:
newChild -  
handler -  

removeUpdateTaskListener

public void removeUpdateTaskListener(UpdateTaskListener listener)
removes the task listener registered with a specific child
Overrides:
removeUpdateTaskListener in class TaskImpl

update

public void update()
            throws DatatypeMismatchException
Description copied from interface: Task
Must be called by the viewer code, before accessing stats.
Causes all UpdateTaskListeners to update any fields in the task.
Overrides:
update in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Throws:
DatatypeMismatchException -  
See Also:
UpdateTaskListener

registerFlushListener

public void registerFlushListener(FlushListener l)
Overrides:
registerFlushListener in class TaskImpl

removeFlushListener

public void removeFlushListener(FlushListener l)
Overrides:
removeFlushListener in class TaskImpl

aggregate

public void aggregate(Task task)
Description copied from interface: Task
Prcesses data from the finished task, updating any internal counters. Triggers internal StatAggregator @see StatAggregator
Overrides:
aggregate in class TaskImpl

registerStatCalculator

public void registerStatCalculator(StatCalculator c,
                                   java.lang.String statName)
Description copied from interface: Task
StatCalculator is called upon Task flush/aggregation whenever a stat is encountered with the following statName. Future implementations might want to use a regex for pattern matching, though that seems overkill at this point.
Overrides:
registerStatCalculator in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Throws:
java.lang.IllegalArgumentException - if c instanceof FlushListener or UpdateTaskListener

removeStatCalculator

public void removeStatCalculator(java.lang.String statName)
Overrides:
removeStatCalculator in class TaskImpl

clear

public void clear()
Description copied from class: TaskImpl
clears all stats, errors, and calls clear() on all StatCalculators
Overrides:
clear in class TaskImpl

removeStats

public boolean removeStats(java.util.Collection c)
Description copied from interface: Task
Removes all Stats that are not present in the collection.
Overrides:
removeStats in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Parameters:
c - a Collection of Stat objects that are to be retained, or a Collection of Strings that are full names of stats to be retained.
Returns:
true if this Task changed as a result of the call

getStats

public java.util.List getStats(java.util.Collection names,
                               int depth)
Description copied from interface: Task
Stats returned are those matching full names specified in the Collection. Behaves like getStats(int) for the depth traversal.
Overrides:
getStats in class TaskImpl
Following copied from interface: com.grandcentral.appstats.Task
Parameters:
names - a Collection of Strings that are full names of wanted stats.
depth - number of levels to get stats of. [-1, 0, 1, 2, 3...)
Returns:
a new List with matching stats, or null.
See Also:
Task.getStats(int)