All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.odell.glazedlists.impl.pmap.AddChunk Maven / Gradle / Ivy

The newest version!
/* Glazed Lists                                                 (c) 2003-2006 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package ca.odell.glazedlists.impl.pmap;

// NIO is used for CTP
import java.io.IOException;
import java.util.logging.Logger;

/**
 * Adds a chunk to the persistent map.
 *
 * @author Jesse Wilson
 */
class AddChunk implements Runnable {
     
    /** logging */
    private static Logger logger = Logger.getLogger(AddChunk.class.toString());
    
    /** the host map */
    private final PersistentMap persistentMap;

    /** the value to write out */
    private final Chunk newValue;
    
    /** the value to erase */
    private final Chunk oldValue;
    
    /**
     * Create a new AddChunk.
     */
    public AddChunk(PersistentMap persistentMap, Chunk newValue, Chunk oldValue) {
        this.persistentMap = persistentMap;
        this.newValue = newValue;
        this.oldValue = oldValue;
    }
    
    /**
     * Write the chunk to disk.
     *
     * 

This is a multiple stage procedure: *

    *
  1. Figure out how many bytes are needed for this chunk: *
  2. Allocate that many bytes in the file for the new section *
  3. Clean up the new section: mark it as empty and of the new size (flush 1) *
  4. Fill the new section (flush 2) *
  5. Mark the new section as not empty any more (flush 3) *
*/ public void run() { try { // allocate persistentMap.allocate(newValue); // get a sequence id newValue.setSequenceId(persistentMap.nextSequenceId()); // write out the data newValue.writeData(); // clear the old value if(oldValue != null) { oldValue.delete(); } logger.info("Successfully wrote value for key \"" + newValue.getKey() + "\""); } catch(IOException e) { persistentMap.fail(e, "Failed to write to file " + persistentMap.getFile().getPath()); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy