Package org.jcoredb.fs

Examples of org.jcoredb.fs.BlockId


  public void create() {

   
    IFileSystem fs = FileSystemRegistry.get(new FileSystemRegKey(Constants.HOST, Configs.getFSConfig().getRootDir()));
   
    BlockId blockId = new BlockId(containerId, segmentId, id);
   
    try
    {
      Block block = fs.read(blockId);
     
      JSONNode root = JSONHelper.createSuccessNode();
      JSONAttribute containerId = new JSONAttribute("containerId", ""+blockId.getContainerId(), AttrType.Number);
      JSONAttribute segmentId = new JSONAttribute("segmentId", ""+blockId.getSegmentId(), AttrType.Number);
      JSONAttribute id = new JSONAttribute("blockId", ""+blockId.getId(), AttrType.Number);
      JSONAttribute data = new JSONAttribute("data", Base64.encodeBase64String(block.getBytes()),AttrType.String);
      root.add(containerId);
      root.add(segmentId);
      root.add(id);
      root.add(data);
View Full Code Here


    String testStr = "<test> <content> Hello world! </content> </test>";
    byte[] content = testStr.getBytes();
   
    for (int i = 0; i < NUM_OF_BLOCKS_TO_APPEND; i++) {

      Block b = new Block(new BlockId(0));
      b.setBytes(content);     
      blocks[i] = b;
    }

    long startMs = System.currentTimeMillis();
View Full Code Here

    String testStr = "<test> <content> Hello world! </content> </test>";
    byte[] content = testStr.getBytes();
   
    for (int i = 0; i < NUM_OF_BLOCKS_TO_APPEND; i++) {

      Block b = new Block(new BlockId(0));
      b.setBytes(content);     
      blocks[i] = b;
    }

    long startMs = System.currentTimeMillis();
View Full Code Here

          numOfBlocksLeft = cntBlocks.length;
        }
        else
        {
          //Get the last segment
          BlockId idOfLastFreeBlock = cnt.findLastFreeBlock();
          DataSegment lastSegOfCnt = cnt.getSegment(idOfLastFreeBlock.getSegmentId());
          int freeInLastSeg = SEGSIZE - idOfLastFreeBlock.getId();
         
          for (int i=idOfLastFreeBlock.getContainerId(); i < SEGSIZE; i++)
          {
            BlockId currFullBlockId = new BlockId(cntId, lastSegOfCnt.getId(), i);
            blockIds.add(currFullBlockId);
            cntBlocks[i].setId(currFullBlockId);
          }
         
          numOfBlocksLeft = cntBlocks.length - freeInLastSeg;
         
        }
       
        //Reserve somme Id-s for the blocks
        int currBlockId = 0;
        DataSegment currSeg = null;
   
        int startIdx = (cntBlocks.length - numOfBlocksLeft);
       
        for (int i = startIdx ; i < cntBlocks.length; i++)
        {
          if (i == startIdx || i % SEGSIZE == 0)
          {
            //Extend
            currBlockId = 0;
            currSeg = cnt.extend();
            currSeg.open();
          }
         
          BlockId currFullBlockId = new BlockId(cntId, currSeg.getId(), currBlockId);
          blockIds.add(currFullBlockId);
          cntBlocks[i].setId(currFullBlockId);

          currBlockId++;
        }
View Full Code Here

   * @param block
   */
  public void put(Block block)
  {
    //Get the segment id from the block id
    BlockId blockId = block.getId();
    SegmentId segId = new SegmentId(blockId.getContainerId(), blockId.getSegmentId());

    //Get or init the values list
    List<Block> values;
   
    if (containsKey(segId))
View Full Code Here

   * @see org.jcoredb.fs.IFileSystem#write(org.jcoredb.fs.Block)
   */
  @Override
  public void write(Block block) throws BlockWriteErr, SegmentGetErr
  {
    BlockId id = block.getId();
   
    IContainer c = containers.get(id.getContainerId());
    DataSegment seg = (DataSegment) c.getSegment(id.getSegmentId());
   
    seg.writeBlock(block);
  }
View Full Code Here

   * @see org.jcoredb.fs.IFileSystem#append(org.jcoredb.fs.Block, boolean)
   */
  @Override
  public BlockId append(Block block, boolean only) throws BlockAppendErr
  {
    BlockId blockId = block.getId();
   
    IContainer c = containers.get(block.getId().getContainerId());
   
    blockId = c.append(block, only);
   
View Full Code Here

  @Override
  public void run() {
   
    try
    {
      BlockId id = block.getId();
   
      IContainer c = fs.getContainer(id.getContainerId());
      DataSegment seg = (DataSegment) c.getSegment(id.getSegmentId());
     
      seg.writeBlock(block);
    }
    catch (Exception e)
    {
View Full Code Here

   * @param block
   */
  public void put(Block block)
  {
    //Get the segment id from the block id
    BlockId blockId = block.getId();
    int cntId = blockId.getContainerId();

    //Get or init the values list
    List<Block> values;
   
    if (containsKey(cntId))
View Full Code Here

   * @see org.jcoredb.fs.IContainer#append(org.jcoredb.fs.Block, boolean)
   */
  @Override
  public BlockId append(Block block, boolean only) throws BlockAppendErr
  {
    BlockId blockId = null;
    DataSegment seg = null;

    try {

      if (!only) {
        blockId = findNextFreeBlock();
      } else {
        blockId = findLastFreeBlock();
      }

      if (blockId != null) {
        seg = segments.get(blockId.getSegmentId());
      } else {
        seg = extend();
        blockId = new BlockId(id, seg.getId(), 0);
      }

      block.setId(blockId);

      // System.out.println(blockId);
View Full Code Here

TOP

Related Classes of org.jcoredb.fs.BlockId

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.