org.apache.zookeeper.server.persistence
Class FileSnap

java.lang.Object
  extended by org.apache.zookeeper.server.persistence.FileSnap
All Implemented Interfaces:
SnapShot

public class FileSnap
extends Object
implements SnapShot

This class implements the snapshot interface. it is responsible for storing, serializing and deserializing the right snapshot. and provides access to the snapshots.


Field Summary
static int SNAP_MAGIC
           
 
Constructor Summary
FileSnap(File snapDir)
           
 
Method Summary
 void close()
          synchronized close just so that if serialize is in place the close operation will block and will wait till serialize is done and will set the close flag
 long deserialize(DataTree dt, Map<Long,Integer> sessions)
          deserialize a data tree from the most recent snapshot
 void deserialize(DataTree dt, Map<Long,Integer> sessions, org.apache.jute.InputArchive ia)
          deserialize the datatree from an inputarchive
 File findMostRecentSnapshot()
          find the most recent snapshot in the database.
 List<File> findNRecentSnapshots(int n)
          find the last n snapshots.
 void serialize(DataTree dt, Map<Long,Integer> sessions, File snapShot)
          serialize the datatree and session into the file snapshot
protected  void serialize(DataTree dt, Map<Long,Integer> sessions, org.apache.jute.OutputArchive oa, FileHeader header)
          serialize the datatree and sessions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SNAP_MAGIC

public static final int SNAP_MAGIC
Constructor Detail

FileSnap

public FileSnap(File snapDir)
Method Detail

deserialize

public long deserialize(DataTree dt,
                        Map<Long,Integer> sessions)
                 throws IOException
deserialize a data tree from the most recent snapshot

Specified by:
deserialize in interface SnapShot
Parameters:
dt - the datatree to be deserialized into
sessions - the sessions to be deserialized into
Returns:
the zxid of the snapshot
Throws:
IOException

deserialize

public void deserialize(DataTree dt,
                        Map<Long,Integer> sessions,
                        org.apache.jute.InputArchive ia)
                 throws IOException
deserialize the datatree from an inputarchive

Parameters:
dt - the datatree to be serialized into
sessions - the sessions to be filled up
ia - the input archive to restore from
Throws:
IOException

findMostRecentSnapshot

public File findMostRecentSnapshot()
                            throws IOException
find the most recent snapshot in the database.

Specified by:
findMostRecentSnapshot in interface SnapShot
Returns:
the file containing the most recent snapshot
Throws:
IOException

findNRecentSnapshots

public List<File> findNRecentSnapshots(int n)
                                throws IOException
find the last n snapshots. this does not have any checks if the snapshot might be valid or not

Parameters:
the - number of most recent snapshots
Returns:
the last n snapshots
Throws:
IOException

serialize

protected void serialize(DataTree dt,
                         Map<Long,Integer> sessions,
                         org.apache.jute.OutputArchive oa,
                         FileHeader header)
                  throws IOException
serialize the datatree and sessions

Parameters:
dt - the datatree to be serialized
sessions - the sessions to be serialized
oa - the output archive to serialize into
header - the header of this snapshot
Throws:
IOException

serialize

public void serialize(DataTree dt,
                      Map<Long,Integer> sessions,
                      File snapShot)
               throws IOException
serialize the datatree and session into the file snapshot

Specified by:
serialize in interface SnapShot
Parameters:
dt - the datatree to be serialized
sessions - the sessions to be serialized
snapShot - the file to store snapshot into
Throws:
IOException

close

public void close()
           throws IOException
synchronized close just so that if serialize is in place the close operation will block and will wait till serialize is done and will set the close flag

Specified by:
close in interface SnapShot
Throws:
IOException


Copyright © 2011 The Apache Software Foundation