com.ibm.streams.operator.state

Interface Checkpoint



  • public interface Checkpoint
    Represents a checkpoint.

    An instance of this interface will be created and passed to the operator's registered StateHandler through its checkpoint or reset methods.
    The same interface will be used at checkpoint or restore time. The following example shows how an operator can save state information (in this case, an int and a string) to a back end store using this interface:

     
     public void checkpoint(Checkpoint checkpoint) throws Exception {
                    // get an outputstream to write data to
                    ObjectOutputStream stream = checkpoint.getOutputStream();
                    
                    // write an integer
                    stream.writeInt(42);
     
                    // write a string
                    stream.writeUTF("string");
     }
     
     

    The following example shows how the corresponding reset method would be used to restore the values stored above:
     
     public void reset(Checkpoint checkpoint) throws Exception {
                    // get an inputstream to read data from.
                    ObjectInputStream stream = checkpoint.getInputStream();
     
                    // read an int (this would be 42 if the checkpoint method above is used)
                    int intValue = stream.readInt();
     
                    // read the string as a UTF-8 value
                    String stringValue = stream.readUTF();
     
                    //...
     }
     
     

    Since:
    InfoSphere® Streams Version 4.0
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      java.io.ObjectInputStream getInputStream()
      Provides an ObjectInputStream object that can be used to read data stored in the checkpoint.
      java.io.ObjectOutputStream getOutputStream()
      Provides an ObjectOutputStream object that can be used to put data into the checkpoint.
      long getSequenceId()
      Sequence identifier of this checkpoint.
      long getTimestamp()
      Return the time (in millisecs) at which the checkpoint was created.
    • Method Detail

      • getSequenceId

        long getSequenceId()
        Sequence identifier of this checkpoint.
        Returns:
        identifier for the checkpoint
      • getTimestamp

        long getTimestamp()
                          throws java.lang.IllegalStateException,
                                 java.io.IOException
        Return the time (in millisecs) at which the checkpoint was created. Only valid at restore time.
        Returns:
        Timestamp as long value since Jan 1, 1970.
        Throws:
        java.lang.IllegalStateException - if the method is called at checkpoint time.
        java.io.IOException - if there is an error retrieving the checkpoint timestamp.
      • getInputStream

        java.io.ObjectInputStream getInputStream()
                                                 throws java.lang.IllegalStateException,
                                                        java.io.IOException
        Provides an ObjectInputStream object that can be used to read data stored in the checkpoint. The data should be read in the same order that it was put in during checkpointing. Note that the runtime will automatically call the close() method on the stream.
        Returns:
        Input Stream for reading data out of the checkpoint.
        Throws:
        java.lang.IllegalStateException - if this method is called at checkpoint time.
        java.io.IOException - if a input stream could not be created.
      • getOutputStream

        java.io.ObjectOutputStream getOutputStream()
                                                   throws java.lang.IllegalStateException,
                                                          java.io.IOException
        Provides an ObjectOutputStream object that can be used to put data into the checkpoint. Note that the runtime will automatically call the flush() and close() methods on the stream.
        Returns:
        Output Stream for writing data to the checkpoint.
        Throws:
        java.lang.IllegalStateException - if this method is called at restore time.
        java.io.IOException - if an output stream could not be created.