condor.classad
Class ClassAdReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--condor.classad.ClassAdReader

public class ClassAdReader
extends Reader

Convert a serialized classified advertisement into a stream of characters. The current Condor C++ classad library uses a rather peculiar representation for transmitting classads (see read() for details). ClassAdReader may be used to wrap a CedarInputStream and turn it into a Reader (a stream of input characters). A sequence of classads appears to be a stream of ASCII characters containing the ASCII representations of the classads, each followed by a semicolon and a newline. For example:

         [myType="job";name="ad1";targetType="machine"];
         [myType="job";name="ad2";targetType="machine"];
 
There are plans to simplify the format used for transporting classads in a future release of Condor. When that happens, this class can be replaced by java.io.InputStreamReader.

The inverse transformation, from a classified advertisement to the "old" serialized form, is performed by RecordExpr.transmit.

Version:
6.1
Author:
Marvin Solomon

Fields inherited from class java.io.Reader
lock
 
Constructor Summary
ClassAdReader(condor.cedar.CedarInputStream in)
          Create a new ClassAdReader.
 
Method Summary
 void close()
          Throw away all remaining input and close the underlying input stream.
 int getByteCount()
          Return the number of "raw" bytes read from the original input stream, including Cedar overhead.
 int read()
          Returns one character from the translated input stream.
 int read(char[] buf, int offset, int len)
           
 
Methods inherited from class java.io.Reader
mark, markSupported, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassAdReader

public ClassAdReader(condor.cedar.CedarInputStream in)
Create a new ClassAdReader.
Parameters:
in - the underlying input stream.
Method Detail

read

public int read()
         throws IOException
Returns one character from the translated input stream. Input consists of zero or more ads, each preceded by two Cedar integers. The first integer is non-zero and indicates that an ad follows. The second is an attrtibute count n. The body of the ad consists of n+2 null-terminated strings. The input stream ends with a zero Cedar integer (meaning "no more ads").

Each character of input generates one or more characters of output, the first character of which is returned immediately, with the remaining characters (if any) stored in pushBack. The field attrCount indicates the number of strings remaining in the current ad, not including the current string. In particular, when the attribute count n is read, attrCount is set to n+1, attrCount==0 while the last string is being processed, and attrCount is -1 between ads.

Here is an example. In the input, the notation "{n}" represents the number n encoded as a Cedar integer (8 bytes binary, most significant byte first).

     input   {1}{2}a=b\0foo=bar\0xxx\0yyy\0{1}{0}uuu\0vvv\0{0}
     output  [a=b;
             foo=bar;
             MyType="xxx";
             TargetType="yyy"];
             [MyType="uuu";
             TargetType"vvv"];
             EOF
 

Here is a trace of the finite-state machine that does the translation. The state consists of the values of attrCount and pushBack.

     input   output  attrCont  pushBack
     -----   ------  --------  --------
                        -1
     {1}{2}  [           3
     a=b     a=b         3
     \0      ;           2     \n
     foo=bar foo=bar     2
     \0      ;           1     \nMyType="
     xxx     xxx         1
     \0      "           0     ;\nTargetType="
     yyy     yyy         0
     \0      "          -1     ];\n
     {1}{0}  [           1     MyType="
     uuu     uuu         1    
     \0      "           0     ;\nTargetType="
     vvv     vvv         0   
     \0      "          -1     ];\n
     {0}     EOF
 
Note that "special actions" only occur when attrCount == -1 at the start of this method, or when the input stream returns a null. Otherwise, this method simply returns the next character from pushBack, or the next character from the input stream if pushBack is empty.

Characters are retrieved from the input stream using readUTFchar, which has the same contract as Reader.read(): A return value of 0 means an encoded null was found. A return value of -1 means and "end-of-file" condition was encountered--in this case, a naked null byte indicating "end-of-string".

Overrides:
read in class Reader
Returns:
the next character of the transformed input stream, or -1 for an end-of-file indication.
Throws:
IOException - if an I/O error occurs on the underlying input stream.

read

public int read(char[] buf,
                int offset,
                int len)
         throws IOException
Overrides:
read in class Reader

close

public void close()
           throws IOException
Throw away all remaining input and close the underlying input stream.
Overrides:
close in class Reader
Throws:
IOException - if an I/O error occurs on the underlying input stream.

getByteCount

public int getByteCount()
Return the number of "raw" bytes read from the original input stream, including Cedar overhead.
Returns:
the number of bytes read.