net.sourceforge.basher.impl
Class AbstractFileCollector

java.lang.Object
  extended by net.sourceforge.basher.impl.AbstractCollector
      extended by net.sourceforge.basher.impl.AbstractFileCollector
All Implemented Interfaces:
EventListener, Collector, BasherEventListener, org.ops4j.gaderian.events.RegistryShutdownListener
Direct Known Subclasses:
CSVFileCollector, XMLFileCollector

public abstract class AbstractFileCollector
extends AbstractCollector

Version:
$Revision$
Author:
Johan Lindquist

Nested Class Summary
static class AbstractFileCollector.Classifier
           
 class AbstractFileCollector.FileEntry
           
static class AbstractFileCollector.Type
           
 
Field Summary
protected  String _collectionDirectory
           
protected  Map<String,net.sourceforge.basher.impl.AbstractFileCollector.OpenFile> _openFiles
           
protected  File _parent
           
 
Fields inherited from class net.sourceforge.basher.impl.AbstractCollector
_log, _timeSource
 
Constructor Summary
AbstractFileCollector()
           
 
Method Summary
protected  void closeOpenResources()
           
protected  void dumpAverage(Average average)
          Writes the specified Average to the averag file.
 void fail(TaskExecutionContext taskExecutionContext, long elapsedTime, long elapsedTimeNanos, Throwable throwable)
          Writes the result of a failed task to the failure file.
protected abstract  String formatAverage(Average average)
           
protected abstract  String formatExecution(String taskName, long elapsedTime, long elapsedTimeNanos)
           
protected  BufferedWriter getWriter(String fileKey, AbstractFileCollector.Classifier classifier, Object... headerParams)
          Retrieves (and possibly creates) a new writer on to which to write data
protected  void initializeCollector(BasherContext basherContext)
           
 void initializeService()
          Initializes the service.
 Average markAverage()
          Ensures the average over the last time slice is written to disk.
 void notRun(TaskExecutionContext taskExecutionContext, long elapsedTime, long elapsedTimeNanos)
          Writes the result of a not tun task execution to the notrun file.
 void setAverageFilenamePrefix(String averageFilenamePrefix)
           
 void setAverageFooter(String averageFooter)
           
 void setAverageHeader(String averageHeader)
           
 void setExecutionFooter(String executionFooter)
           
 void setExecutionHeader(String executionHeader)
           
 void setExtension(String extension)
           
 void setNumThreads(int numThreads)
           
 void setQueueCapacity(int queueCapacity)
           
 void setTimeOut(long timeOut)
           
 void success(TaskExecutionContext taskExecutionContext, long elapsedTime, long elapsedTimeNanos)
          Writes the result of a successful task execution to the success file.
protected  void writeToFile(AbstractFileCollector.Type type, String taskName, long elapsedTime, long elapsedTimeNanos)
          Writes the time the specified task took to execute.
 
Methods inherited from class net.sourceforge.basher.impl.AbstractCollector
basherEvent, getAverages, getFailures, getNotRun, getSuccesses, getTotal, isCollecting, registryDidShutdown, setLog, setTimeSource, startCollecting, stopCollecting
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_openFiles

protected final Map<String,net.sourceforge.basher.impl.AbstractFileCollector.OpenFile> _openFiles

_parent

protected File _parent

_collectionDirectory

protected String _collectionDirectory
Constructor Detail

AbstractFileCollector

public AbstractFileCollector()
Method Detail

setNumThreads

public void setNumThreads(int numThreads)

setTimeOut

public void setTimeOut(long timeOut)

setQueueCapacity

public void setQueueCapacity(int queueCapacity)

setAverageFooter

public void setAverageFooter(String averageFooter)

setExecutionFooter

public void setExecutionFooter(String executionFooter)

setAverageHeader

public void setAverageHeader(String averageHeader)

setExecutionHeader

public void setExecutionHeader(String executionHeader)

setExtension

public void setExtension(String extension)

setAverageFilenamePrefix

public void setAverageFilenamePrefix(String averageFilenamePrefix)

initializeService

public void initializeService()
                       throws Exception
Initializes the service.

Throws:
Exception - If the script directory does not exist or can not be written to

success

public void success(TaskExecutionContext taskExecutionContext,
                    long elapsedTime,
                    long elapsedTimeNanos)
Writes the result of a successful task execution to the success file.

Specified by:
success in interface Collector
Overrides:
success in class AbstractCollector
Parameters:
taskExecutionContext - The task execution context wrapping the executed task.
elapsedTime - Time of execution
elapsedTimeNanos -

fail

public void fail(TaskExecutionContext taskExecutionContext,
                 long elapsedTime,
                 long elapsedTimeNanos,
                 Throwable throwable)
Writes the result of a failed task to the failure file.

Specified by:
fail in interface Collector
Overrides:
fail in class AbstractCollector
Parameters:
taskExecutionContext - The task execution context wrapping the task that failed.
elapsedTime - Time of execution
elapsedTimeNanos -
throwable - The reason (if specified) for the failure

closeOpenResources

protected void closeOpenResources()
Specified by:
closeOpenResources in class AbstractCollector

initializeCollector

protected void initializeCollector(BasherContext basherContext)
                            throws Exception
Specified by:
initializeCollector in class AbstractCollector
Throws:
Exception

notRun

public void notRun(TaskExecutionContext taskExecutionContext,
                   long elapsedTime,
                   long elapsedTimeNanos)
Writes the result of a not tun task execution to the notrun file.

Specified by:
notRun in interface Collector
Overrides:
notRun in class AbstractCollector
Parameters:
taskExecutionContext - The task that didn't run.
elapsedTime - Time of execution
elapsedTimeNanos -

dumpAverage

protected void dumpAverage(Average average)
Writes the specified Average to the averag file.

Parameters:
average - The average to write to disk

formatAverage

protected abstract String formatAverage(Average average)

formatExecution

protected abstract String formatExecution(String taskName,
                                          long elapsedTime,
                                          long elapsedTimeNanos)

writeToFile

protected void writeToFile(AbstractFileCollector.Type type,
                           String taskName,
                           long elapsedTime,
                           long elapsedTimeNanos)
Writes the time the specified task took to execute.

Parameters:
type -
taskName - The name of the task (used for the filename as well)
elapsedTime - Time the task took to execute
elapsedTimeNanos -

markAverage

public Average markAverage()
Ensures the average over the last time slice is written to disk. Informs the collector that a collection period has finished.

Specified by:
markAverage in interface Collector
Overrides:
markAverage in class AbstractCollector
Returns:
The average over the last time slice.

getWriter

protected BufferedWriter getWriter(String fileKey,
                                   AbstractFileCollector.Classifier classifier,
                                   Object... headerParams)
                            throws IOException
Retrieves (and possibly creates) a new writer on to which to write data

Parameters:
fileKey - The identifier of the buffer
classifier -
Returns:
The buffer
Throws:
IOException - If the retrieval (create) fails


Copyright © 2006-2010 Basher Team. All Rights Reserved.