org.griphyn.vdl.router
Class BookKeeper

java.lang.Object
  extended by org.griphyn.vdl.router.BookKeeper

public class BookKeeper
extends Object

This class stores state when constructing the DAG for output. It is expected that for each DAG generation, one instance of this class performs the state tracking. The class is tightly coupled to the class that performs the routing.

Version:
$Revision: 50 $
Author:
Jens-S. V??ckler, Yong Zhao
See Also:
Route

Field Summary
private static String filenamechars
          Where to draw filename characters from.
private  ADAG m_dax
          The content of the abstract DAG for XML (DAX) is created after the alternatives are found.
private  SequenceMapping m_mapping
          Unfortunately, for this release, we need to map the shortID of a derivation to some number that is acceptable to NMTOKEN, ID and IDREF.
private  HashMap m_parent
          This map tracks the set of parents for each child derivation.
private  ListStack m_profileStack
          The Profile elements in nested compound TR can be equally nested.
private  Random m_rng
          To create temporary filenames, we need an entropy source.
private  HashSet m_tempfiles
          The temporary files must be unique on a per-workflow basis.
private  ArrayList m_transformations
          The names of compound transformations that we got through.
private  HashMap m_visited
          This contains the set of visited derivations.
(package private) static String XXXXXX
          String constant describing the six X.
 
Constructor Summary
BookKeeper()
          Default ctor.
 
Method Summary
 void addFilenames(Collection lfnset)
          This method helps to track the input and output files.
 boolean addJob(Job job)
          Accessor: Appends a job definition to the DAX structure.
 boolean addParent(HasPass current, Set parents)
          Adds a parent set for the given element to the state
 boolean addVisited(HasPass current, Set real)
          This method marks a derivation as visited in the set of visited nodes.
private  int adjustJobLevels(String startjob, int distance)
          Accessor: Recursively adjusts job level backwards.
 String createTempName(String hint, String suffix)
          Creates a unique temporary filename.
 List getAllProfiles()
          Accessor: obtains all profiles on the profile stack.
 String getAllTransformations()
          Accessor: obtains all transformations that were pushed as space separated string.
 HasPass getCurrent()
          Obtains the current cursor position.
 ADAG getDAX(String name)
          Accessor: Returns the constructed internal DAX keeper.
private  int getJobLevel(String jobid)
          Accessor: Obtains the level of a given job from the DAX structure.
 Set getVisited(HasPass dv)
           
 boolean isEmpty()
          Detects valid results in the ADAG as opposed to an empty shell.
 String jobOf(String id)
          Obtains an existing mapping of a DV indentification to a job id.
 String mapJob(String id)
          Maps a DV identification to a name that can be put into the XML datatypes NMTOKEN, ID and IDREF.
 List popProfile()
          Accessor: pop a vector of profiles from the profile stack.
 String popTransformation()
          Accessor: pop an FQDI from the stack of transformations.
 void pushProfile(List profiles)
          Accessor: push a vector of profiles down the profile stack.
 void pushTransformation(String fqdi)
          Accessor: push the FQDI of a transformation onto a stack.
 void setCurrent(HasPass dv)
          This method updates the "cursor" position with a new derivation.
 String toString()
          dumps the state of this object into human readable format.
 void toString(Writer stream)
          This method is a possibly more memory efficient version of constructing a DAG.
 String toXML(String indent, String namespace)
          Dumps the state of this object into machine readable XML.
 void toXML(Writer stream, String indent)
          This method is a possibly more memory efficient version of constructing a DAX.
 void toXML(Writer stream, String indent, String namespace)
          This method is a possibly more memory efficient version of constructing a DAX.
 boolean wasVisited(HasPass dv)
          Checks if a node was previously visited.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_visited

private HashMap m_visited
This contains the set of visited derivations.


m_parent

private HashMap m_parent
This map tracks the set of parents for each child derivation. Each value item in the map is a set.


m_dax

private ADAG m_dax
The content of the abstract DAG for XML (DAX) is created after the alternatives are found. Maybe in a later version, it will be created in parallel with adding derivations?


m_mapping

private SequenceMapping m_mapping
Unfortunately, for this release, we need to map the shortID of a derivation to some number that is acceptable to NMTOKEN, ID and IDREF.


m_profileStack

private ListStack m_profileStack
The Profile elements in nested compound TR can be equally nested.


m_transformations

private ArrayList m_transformations
The names of compound transformations that we got through. This data will also be added to the job description once a job is added to the book-keeper.


m_tempfiles

private HashSet m_tempfiles
The temporary files must be unique on a per-workflow basis.


m_rng

private Random m_rng
To create temporary filenames, we need an entropy source.


XXXXXX

static final String XXXXXX
String constant describing the six X.

See Also:
Constant Field Values

filenamechars

private static final String filenamechars
Where to draw filename characters from.

See Also:
Constant Field Values
Constructor Detail

BookKeeper

public BookKeeper()
Default ctor.

Method Detail

pushProfile

public void pushProfile(List profiles)
Accessor: push a vector of profiles down the profile stack.

Parameters:
profiles - is a list of profiles, may be empty.
See Also:
popProfile()

popProfile

public List popProfile()
Accessor: pop a vector of profiles from the profile stack.

Returns:
the last active vector of profiles, may be empty.
See Also:
pushProfile( java.util.List )

getAllProfiles

public List getAllProfiles()
Accessor: obtains all profiles on the profile stack.

Returns:
all stacked profiles in one structure, may be empty.

pushTransformation

public void pushTransformation(String fqdi)
Accessor: push the FQDI of a transformation onto a stack.

Parameters:
fqdi - is the fully-qualified definition identifier.
See Also:
popTransformation()

popTransformation

public String popTransformation()
Accessor: pop an FQDI from the stack of transformations.

Returns:
the last FQDI pushed, may be empty for an empty stack.
See Also:
pushTransformation( String )

getAllTransformations

public String getAllTransformations()
Accessor: obtains all transformations that were pushed as space separated string.

Returns:
all transformation names, may be empty.
See Also:
addJob( Job )

getDAX

public ADAG getDAX(String name)
Accessor: Returns the constructed internal DAX keeper.

Returns:
the abstract DAX description. Note that this may be empty!

addJob

public boolean addJob(Job job)
Accessor: Appends a job definition to the DAX structure.


setCurrent

public void setCurrent(HasPass dv)
This method updates the "cursor" position with a new derivation. The cursor helps tracking derivations while a DAG is being produced.

Parameters:
dv - is the new current derivation that the cursor will be set to.
See Also:
getCurrent()

getCurrent

public HasPass getCurrent()
Obtains the current cursor position.

Returns:
the derivation that the cursor is located at.
See Also:
setCurrent( HasPass )

mapJob

public String mapJob(String id)
Maps a DV identification to a name that can be put into the XML datatypes NMTOKEN, ID and IDREF. The identification used to be the DV's short ID, but recent changes use the full ID.

Parameters:
id - is the derivation identifier
Returns:
an XML-compatible job id

jobOf

public String jobOf(String id)
Obtains an existing mapping of a DV indentification to a job id. The identification used to be the DV's short ID, but recent changes use the full ID.

Parameters:
id - is the derivation identifier
Returns:
a job identifier, or null if no such mapping exists.

getJobLevel

private int getJobLevel(String jobid)
Accessor: Obtains the level of a given job from the DAX structure.

Parameters:
jobid - is the job identifier
Returns:
the level of the job, or -1 in case of error (no such job).

adjustJobLevels

private int adjustJobLevels(String startjob,
                            int distance)
Accessor: Recursively adjusts job level backwards.

See Also:
ADAG.adjustLevels( String, int )

addParent

public boolean addParent(HasPass current,
                         Set parents)
Adds a parent set for the given element to the state

Parameters:
current - is the current derivation to add parents for
parents - are the parents, any number, to add for the given element
Returns:
true, if the parent was not know before or the currelem is empty, false, if the parent was added previously.

addVisited

public boolean addVisited(HasPass current,
                          Set real)
This method marks a derivation as visited in the set of visited nodes.

Parameters:
current - is the caller to add to the visited node set.
real - is the value to add for the given caller.
Returns:
true, if the caller was previously unknown to the visited set.

wasVisited

public boolean wasVisited(HasPass dv)
Checks if a node was previously visited. The visited nodes have to be tracked in any kind of breadth first and depth first search.

Parameters:
dv - is the derivation to check, if it was visited before.
Returns:
true, if the derivation was already visited previously.

getVisited

public Set getVisited(HasPass dv)

addFilenames

public void addFilenames(Collection lfnset)
This method helps to track the input and output files. From this information, the input, intermediary and output files of the complete DAG can be constructed. This method does allow for inout.

Parameters:
lfnset - is a set of LFN instances, which encapsulate their respective linkage.
See Also:
AbstractCollection.addAll( java.util.Collection )

createTempName

public String createTempName(String hint,
                             String suffix)
Creates a unique temporary filename. The new name is registered locally to ensure uniqueness. A string of multiple capitol X, at least six, is replaced with some random factor.

Parameters:
hint - is a filename hint.
suffix - is the suffix for the filename.
Returns:
a somewhat unique filename - for this workflow only.

isEmpty

public boolean isEmpty()
Detects valid results in the ADAG as opposed to an empty shell.

Returns:
true, if the ADAG is an empty shell.

toString

public void toString(Writer stream)
              throws IOException
This method is a possibly more memory efficient version of constructing a DAG.

Parameters:
stream - is a generic stream to put textual results onto.
Throws:
IOException

toString

public String toString()
dumps the state of this object into human readable format.

Overrides:
toString in class Object

toXML

public void toXML(Writer stream,
                  String indent,
                  String namespace)
           throws IOException
This method is a possibly more memory efficient version of constructing a DAX.

Parameters:
stream - is a generic stream to put XML results onto.
indent - is the initial indentation level.
namespace - is an optional XML namespace.
Throws:
IOException

toXML

public void toXML(Writer stream,
                  String indent)
           throws IOException
This method is a possibly more memory efficient version of constructing a DAX.

Parameters:
stream - is a generic stream to put XML results onto.
indent - is the initial indentation level.
Throws:
IOException

toXML

public String toXML(String indent,
                    String namespace)
Dumps the state of this object into machine readable XML.

Parameters:
indent - is the initial indentation level.
namespace - is an optional XML namespace.


Copyright © 2007 The University of Southern California. All Rights Reserved.