sfi.director.util.Tools Class Reference

List of all members.

Detailed Description

The Tools class is a collection of useful static methods.

Note that some of the methods are covered by recent Java versions but are re-implemented here for compatibility reasons.


Static Public Member Functions

static Object saveOurClass (Object anInstance)
 Classes of objects registered via this method are protected against the class garbage collection.
static String uniqId ()
 Returns a (hopefully) system-wide unique ID.
static boolean copy (InputStream fin, OutputStream fout, boolean continuous) throws DirectorException
 Copy all the data from an InputStream to an OutputStream.
static void copy (InputStream fin, OutputStream fout) throws DirectorException
 Copy in non-continuous mode.
static long digestData (InputStream fin, MessageDigest digest) throws IOException
 Read all data from InputStream and update a digest accordingly.
static MessageDigest md5sum (File file) throws DirectorException
 Compute md5 checksum for a file.
static MessageDigest md5sum (InputStream in) throws DirectorException
 Compute md5 checksum for a file.
static long copyData (InputStream fin, OutputStream out) throws IOException
 Copy all data from an InputStream to an OutputStream.
static long copyObject (Object source, OutputStream out, boolean closeOnTerm) throws IOException
 Copy object from into an OutputStream.
static int readEntire (InputStream in, byte buffer[], int offset, int length) throws IOException
 Read a block of data from an InputStream.
static int readEntire (InputStream in, byte buffer[], int length) throws IOException
 Read a block of data from an InputStream.
static void debug (LogEntry log)
 Log a debug message.
static void debug (int level, String message)
 Log a debug message if debug level is high enough for the message to be logged.
static void log (LogEntry log)
 Log a message.
static void log (int level, String message)
 Log a message at the specified priority level.
static void exit ()
 Exit without an error.
static void exit (int exitcode)
 Exit with specified exit code.
static void rememberCleanup (CleanUpable cleanup)
 Mark an object as to be cleaned up by exit().
static String join (Vector list, String separator)
 Join the string representation of a list of objects into one single resulting string.
static String join (Enumeration list, String separator)
 Join the string representation of an enumeration of strings into one single resulting string.
static Vector split (String str, String separator)
 Split a string into a vector of strings.
static Vector split (String str)
 Split a string into a vector of strings.
static Hashtable getOpt (String args[], String argopts[]) throws ArgumentException
 Process command line arguments.
static void attachErrorLogger (final Process proc)
 Attach an thread to a process' error stream logging every error message via the default logger.
static Process exec (String cmd) throws IOException
 Execute a command.
static Process exec (String cmd[]) throws IOException
 Execute a command.
static Vector runParsePerl (String split, String code, String args[]) throws DirectorException
static int execWait (String cmd[])
 Execute a command, attach an error logger, wait for the command's termination and return its exit code to the caller.
static String[] ShellCommand (String command)
 Accepts a shell command string, returns a String array containing the same command ready for execution via exec() and the system's command shell.
static int execWait (String cmd[], boolean logErrors)
 Execute a command, optionally attach an error logger, wait for the command's termination and return its exit code to the caller.
static int execWait (String cmd[], boolean logErrors, long timeout)
 Execute a command, optionally attach an error logger, wait for the command's termination and return its exit code to the caller.
static void consume (final InputStream stream)
static int workingWaitFor (Process process, boolean outConsumed, boolean errorConsumed) throws InterruptedException
static int workingWaitFor (Process process, boolean outConsumed, boolean errorConsumed, final long timeout) throws InterruptedException
 do a Process.waitFor() and consume the exec()-ed commands output in order to avoid hangs.
static Enumeration execUtility (String cmd[]) throws DirectorException
 run a command and read its output via an Enumeration.
static Enumeration execFilter (String cmd[], final Object source) throws DirectorException
 run a command, pipe the source string in and make the output accessible via the returned Enumeration.
static String findAuth (String principal)
 Find an authentication database entry for a given principal (login name).
static int findUidNumber (int start) throws DirectorException
 By using the people database find an unused uid number higher than the specified start limit.
static int findUidNumber (int start, int end) throws DirectorException
 By using the people database find an unused uid between two given limits.
static int findGidNumber (int start) throws DirectorException
 By using the people database find an unused gid number higher than the specified start limit.
static int findGidNumber (int start, int end) throws DirectorException
 By using the people database find an unused uid between two given limits.
static int findFreeNumber (int start, int end, String field) throws DirectorException
 By using the people database find an unused uid or gid number between two given limits.
static void sort (Vector v, MyComparator c)
 Sort a vector in the order specified by the given comparator.
static void sort (Object arr[], MyComparator c)
 Sort an array in the order specified by the given comparator.
static String expand (String str, final DBObject dbo) throws DirectorException
 Expand variable references in a string using the attributes of the given database entry as variable/value pairs.
static String expand (String str, final ExpandVars expander) throws DirectorException
 Expand variable references in a string using the given ExpandVars class to expand variable names into their values.
static String applyModifier (String modifier, String val, final ExpandVars expander) throws DirectorException
 Apply a variable modifier to a value.
static void background ()
 Put the current thread into the background (= decrease its priority).
static void executeLocalqueue ()
 Do something reasonable with the jobs in the local job queue.
static void doEvent (DBObject dbo, final DBConnection dir, final Record data, final String type)
static void doEvent (DBObject dbo, final DBConnection dir, final Record data, final String type, boolean warnIfNotApplicable)
 Execute an event for a given database entry and the given corresponding object editor data.
static void makeZip (File what, String prefix, OutputStream out) throws DirectorException
 Zip the given file and send the zip file to the given stream.
static void makeZip (File what, String prefix, ZipOutputStream out) throws DirectorException
static String timeStamp ()
 Return a string representing the current time in a (director) standard format.
static String timeStamp (Date time)
 Return a string representing the passed time in a (director) standard format.
static void main (String args[])
static DBObject fieldToDBObject (Field f)
static Record toDBEditRecord (DBObject dbo)
static DBObject toDBObject (Record rec)
static String getUser ()
static void trackJob (Workflow workflow) throws DirectorException
static String stacktrace (Throwable e)
static Enumeration getHostnames (String name)
 Get all names of a specific host/alias from the hosts directory.
static void removeDir (File dir) throws DirectorException
 Remove a file/directory recursively.
static String asciify (String message)
 translate some international characters in a string into an ASCII representation
static String daytimeStamp (Date time)
 Return a string representing the current day time.
static String daytimeStamp ()
static void setThreadSubStatus (String status)
static void backupFile (File file)
 Same as backupFile(), but saves file without checking if there is already an identical backup copy.
static void backupFile (File target, boolean onlyIfDifferent)
 Save a backup copy of the given file.

Static Public Attributes

static int debuglev = 0
 The program's debug level.
static PrintStream debugout = System.err
 The Stream where debug output is sent to.
static Vector classRefs = new Vector()
 Vector used to store references to classes for the saveOurClass mechanism.
static Hashtable progOptions = new Hashtable()
 This hash stores the command line options of the current program.

Static Protected Attributes

static String[] asciifiers

Static Package Attributes

static Hashtable freeNumber = new Hashtable()
static SimpleDateFormat hourMinSecFormat = new SimpleDateFormat( "HH:mm:ss" )


Member Function Documentation

static String sfi.director.util.Tools.applyModifier String  modifier,
String  val,
final ExpandVars  expander
throws DirectorException [static]
 

Apply a variable modifier to a value.

static String sfi.director.util.Tools.asciify String  message  )  [static]
 

translate some international characters in a string into an ASCII representation

static void sfi.director.util.Tools.attachErrorLogger final Process  proc  )  [static]
 

Attach an thread to a process' error stream logging every error message via the default logger.

static void sfi.director.util.Tools.background  )  [static]
 

Put the current thread into the background (= decrease its priority).

static void sfi.director.util.Tools.backupFile File  target,
boolean  onlyIfDifferent
[static]
 

Save a backup copy of the given file.

The copy is made in the backup directory as configured via the option ConfigBackup.Dir in sfidirector.conf. If the boolean argument is true, then backupFile() checks if there is already an identical backup copy (identical MD5 checksum) in which case no new copy is made. Existing old backup files are rotated, thus multiple versions are kept. The ConfigBackup.Keep sfidirector.conf option defines how many versions are kept.

Parameters:
target The file to be backed up
onlyIfDifferent if true, the file is only backed up if there is no existing identical backup copy

static void sfi.director.util.Tools.backupFile File  file  )  [static]
 

Same as backupFile(), but saves file without checking if there is already an identical backup copy.

static void sfi.director.util.Tools.consume final InputStream  stream  )  [static]
 

static void sfi.director.util.Tools.copy InputStream  fin,
OutputStream  fout
throws DirectorException [static]
 

Copy in non-continuous mode.

See also:
copy(InputStream,OutputStream,boolean)

static boolean sfi.director.util.Tools.copy InputStream  fin,
OutputStream  fout,
boolean  continuous
throws DirectorException [static]
 

Copy all the data from an InputStream to an OutputStream.

After copying is complete the streams will be closed.

Parameters:
fin The input stream
fout The output stream
continuous If true copy() will only return after copying all data or after an error occured, if false copy() will return after each block of data.
Returns:
true if more data is waiting to be copied, false if the end of the input stream has been reached (in non-continuous mode copy will always return false)

static long sfi.director.util.Tools.copyData InputStream  fin,
OutputStream  out
throws IOException [static]
 

Copy all data from an InputStream to an OutputStream.

In opposition to copy() this method will not close the streams after copying has finished.

See also:
copy(InputStream,OutputStream)

static long sfi.director.util.Tools.copyObject Object  source,
OutputStream  out,
boolean  closeOnTerm
throws IOException [static]
 

Copy object from into an OutputStream.

The behaviour depends on the type of the source object. For most objects the string value of the source object is emitted.

static String sfi.director.util.Tools.daytimeStamp  )  [static]
 

static String sfi.director.util.Tools.daytimeStamp Date  time  )  [static]
 

Return a string representing the current day time.

static void sfi.director.util.Tools.debug int  level,
String  message
[static]
 

Log a debug message if debug level is high enough for the message to be logged.

static void sfi.director.util.Tools.debug LogEntry  log  )  [static]
 

Log a debug message.

static long sfi.director.util.Tools.digestData InputStream  fin,
MessageDigest  digest
throws IOException [static]
 

Read all data from InputStream and update a digest accordingly.

static void sfi.director.util.Tools.doEvent DBObject  dbo,
final DBConnection  dir,
final Record  data,
final String  type,
boolean  warnIfNotApplicable
[static]
 

Execute an event for a given database entry and the given corresponding object editor data.

static void sfi.director.util.Tools.doEvent DBObject  dbo,
final DBConnection  dir,
final Record  data,
final String  type
[static]
 

static Process sfi.director.util.Tools.exec String  cmd[]  )  throws IOException [static]
 

Execute a command.

static Process sfi.director.util.Tools.exec String  cmd  )  throws IOException [static]
 

Execute a command.

static Enumeration sfi.director.util.Tools.execFilter String  cmd[],
final Object  source
throws DirectorException [static]
 

run a command, pipe the source string in and make the output accessible via the returned Enumeration.

See also: execUtility

static void sfi.director.util.Tools.executeLocalqueue  )  [static]
 

Do something reasonable with the jobs in the local job queue.

Depending on the configuration this means that jobs are executed and stored in the job queue database if they fail retryable, or that jobs are directly stored in the job queue database without first trying to execute them.

See also:
Setup.localjobqueue

static Enumeration sfi.director.util.Tools.execUtility String  cmd[]  )  throws DirectorException [static]
 

run a command and read its output via an Enumeration.

static int sfi.director.util.Tools.execWait String  cmd[],
boolean  logErrors,
long  timeout
[static]
 

Execute a command, optionally attach an error logger, wait for the command's termination and return its exit code to the caller.

Returns after at most timeout msecs.

See also:
attachErrorLogger(Process)

static int sfi.director.util.Tools.execWait String  cmd[],
boolean  logErrors
[static]
 

Execute a command, optionally attach an error logger, wait for the command's termination and return its exit code to the caller.

See also:
attachErrorLogger(Process)

static int sfi.director.util.Tools.execWait String  cmd[]  )  [static]
 

Execute a command, attach an error logger, wait for the command's termination and return its exit code to the caller.

See also:
attachErrorLogger(Process)

static void sfi.director.util.Tools.exit int  exitcode  )  [static]
 

Exit with specified exit code.

Programs should always call Tools.exit() when shutting down. Due to Java's broken JVM shutdown mechanism's the program will not gracefully give up resources otherwise.

static void sfi.director.util.Tools.exit  )  [static]
 

Exit without an error.

Programs should always call Tools.exit() when shutting down. Due to Java's broken JVM shutdown mechanism's the program will not gracefully give up resources otherwise.

static String sfi.director.util.Tools.expand String  str,
final ExpandVars  expander
throws DirectorException [static]
 

Expand variable references in a string using the given ExpandVars class to expand variable names into their values.

See also:
ExpandVars

static String sfi.director.util.Tools.expand String  str,
final DBObject  dbo
throws DirectorException [static]
 

Expand variable references in a string using the attributes of the given database entry as variable/value pairs.

See also:
expand(String,ExpandVars)

static DBObject sfi.director.util.Tools.fieldToDBObject Field  f  )  [static]
 

static String sfi.director.util.Tools.findAuth String  principal  )  [static]
 

Find an authentication database entry for a given principal (login name).

Returns:
the string representation of the DN of the auth database entry or the principal itself if no entry was found

static int sfi.director.util.Tools.findFreeNumber int  start,
int  end,
String  field
throws DirectorException [static]
 

By using the people database find an unused uid or gid number between two given limits.

static int sfi.director.util.Tools.findGidNumber int  start,
int  end
throws DirectorException [static]
 

By using the people database find an unused uid between two given limits.

static int sfi.director.util.Tools.findGidNumber int  start  )  throws DirectorException [static]
 

By using the people database find an unused gid number higher than the specified start limit.

static int sfi.director.util.Tools.findUidNumber int  start,
int  end
throws DirectorException [static]
 

By using the people database find an unused uid between two given limits.

static int sfi.director.util.Tools.findUidNumber int  start  )  throws DirectorException [static]
 

By using the people database find an unused uid number higher than the specified start limit.

static Enumeration sfi.director.util.Tools.getHostnames String  name  )  [static]
 

Get all names of a specific host/alias from the hosts directory.

Also expand "localhost" to the name of the local host, "MasterHost" to the name of the master.

static Hashtable sfi.director.util.Tools.getOpt String  args[],
String  argopts[]
throws ArgumentException [static]
 

Process command line arguments.

Besides returning processed options to the calling procedure this also sets the progOptions variable.

Parameters:
args The command line arguments as passed to the main() method
argopts The acceptable command line arguments
Returns:
a Hashtable where the keys are option names and the elements are vectors of strings containing argument values, resp. a non-null object for 'boolean' arguments
See also:
progOptions

static String sfi.director.util.Tools.getUser  )  [static]
 

static String sfi.director.util.Tools.join Enumeration  list,
String  separator
[static]
 

Join the string representation of an enumeration of strings into one single resulting string.

static String sfi.director.util.Tools.join Vector  list,
String  separator
[static]
 

Join the string representation of a list of objects into one single resulting string.

static void sfi.director.util.Tools.log int  level,
String  message
[static]
 

Log a message at the specified priority level.

static void sfi.director.util.Tools.log LogEntry  log  )  [static]
 

Log a message.

static void sfi.director.util.Tools.main String  args[]  )  [static]
 

static void sfi.director.util.Tools.makeZip File  what,
String  prefix,
ZipOutputStream  out
throws DirectorException [static]
 

See also:
makeZip( File, String, OutputStream )

static void sfi.director.util.Tools.makeZip File  what,
String  prefix,
OutputStream  out
throws DirectorException [static]
 

Zip the given file and send the zip file to the given stream.

If the file to be zipped is a directory it will be zipped recursively. The name of the file in the ZIP archive is passed via the prefix argument.

static MessageDigest sfi.director.util.Tools.md5sum InputStream  in  )  throws DirectorException [static]
 

Compute md5 checksum for a file.

static MessageDigest sfi.director.util.Tools.md5sum File  file  )  throws DirectorException [static]
 

Compute md5 checksum for a file.

static int sfi.director.util.Tools.readEntire InputStream  in,
byte  buffer[],
int  length
throws IOException [static]
 

Read a block of data from an InputStream.

Unlike the original InputStream.read() method, this utility function reads exactly the given number of bytes, unless eof is reached.

Returns:
the number of bytes that were read

static int sfi.director.util.Tools.readEntire InputStream  in,
byte  buffer[],
int  offset,
int  length
throws IOException [static]
 

Read a block of data from an InputStream.

Unlike the original InputStream.read() method, this utility function reads exactly the given number of bytes, unless eof is reached.

Returns:
the number of bytes that were read

static void sfi.director.util.Tools.rememberCleanup CleanUpable  cleanup  )  [static]
 

Mark an object as to be cleaned up by exit().

static void sfi.director.util.Tools.removeDir File  dir  )  throws DirectorException [static]
 

Remove a file/directory recursively.

static Vector sfi.director.util.Tools.runParsePerl String  split,
String  code,
String  args[]
throws DirectorException [static]
 

static Object sfi.director.util.Tools.saveOurClass Object  anInstance  )  [static]
 

Classes of objects registered via this method are protected against the class garbage collection.

Early versions of Java used to love kicking out classes no matter if they contained valuable static information. Director classes which prefer to keep their static information will register via saveOurClass()

static void sfi.director.util.Tools.setThreadSubStatus String  status  )  [static]
 

static String [] sfi.director.util.Tools.ShellCommand String  command  )  [static]
 

Accepts a shell command string, returns a String array containing the same command ready for execution via exec() and the system's command shell.

Typically, e.g. "echo abc" will be translated into { "/bin/sh", "-c", "echo abc" }. This is thought to become platform-independent once we support non-UNIX platforms, so on a windows system this might return something like { "cmd.exe", "/c", "echo abc" }.

static void sfi.director.util.Tools.sort Object  arr[],
MyComparator  c
[static]
 

Sort an array in the order specified by the given comparator.

See also:
MyComparator

static void sfi.director.util.Tools.sort Vector  v,
MyComparator  c
[static]
 

Sort a vector in the order specified by the given comparator.

See also:
MyComparator

static Vector sfi.director.util.Tools.split String  str  )  [static]
 

Split a string into a vector of strings.

Split at whitespace locations where 'whitespace' is one or more spaces or tabs.

static Vector sfi.director.util.Tools.split String  str,
String  separator
[static]
 

Split a string into a vector of strings.

Split at positions where the separator string is located at the same time dropping the separator string. This is similiar but not identical to using StringTokenizers.

static String sfi.director.util.Tools.stacktrace Throwable  e  )  [static]
 

static String sfi.director.util.Tools.timeStamp Date  time  )  [static]
 

Return a string representing the passed time in a (director) standard format.

static String sfi.director.util.Tools.timeStamp  )  [static]
 

Return a string representing the current time in a (director) standard format.

static Record sfi.director.util.Tools.toDBEditRecord DBObject  dbo  )  [static]
 

static DBObject sfi.director.util.Tools.toDBObject Record  rec  )  [static]
 

static void sfi.director.util.Tools.trackJob Workflow  workflow  )  throws DirectorException [static]
 

static String sfi.director.util.Tools.uniqId  )  [static]
 

Returns a (hopefully) system-wide unique ID.

static int sfi.director.util.Tools.workingWaitFor Process  process,
boolean  outConsumed,
boolean  errorConsumed,
final long  timeout
throws InterruptedException [static]
 

do a Process.waitFor() and consume the exec()-ed commands output in order to avoid hangs.

static int sfi.director.util.Tools.workingWaitFor Process  process,
boolean  outConsumed,
boolean  errorConsumed
throws InterruptedException [static]
 


Member Data Documentation

String [] sfi.director.util.Tools.asciifiers [static, protected]
 

Vector sfi.director.util.Tools.classRefs = new Vector() [static]
 

Vector used to store references to classes for the saveOurClass mechanism.

See also:
saveOurClass( Object )

int sfi.director.util.Tools.debuglev = 0 [static]
 

The program's debug level.

Higher debug level means more verbose debug output.

PrintStream sfi.director.util.Tools.debugout = System.err [static]
 

The Stream where debug output is sent to.

Hashtable sfi.director.util.Tools.freeNumber = new Hashtable() [static, package]
 

SimpleDateFormat sfi.director.util.Tools.hourMinSecFormat = new SimpleDateFormat( "HH:mm:ss" ) [static, package]
 

Hashtable sfi.director.util.Tools.progOptions = new Hashtable() [static]
 

This hash stores the command line options of the current program.


The documentation for this class was generated from the following file:
Generated on Sat May 19 01:20:00 2012 for Node Director by  doxygen 1.4.5