1 8 package org.ozoneDB.core.storage.gammaStore; 9 10 import java.io.BufferedOutputStream ; 11 import java.io.FileOutputStream ; 12 import java.io.ObjectOutputStream ; 13 14 18 public class ContainerLocationLoc extends Loc { 19 20 protected int[] dataFileIds; 21 protected int[] positions; 22 23 29 public ContainerLocationLoc(int capacity, float bufferFactor) { 30 super(capacity, bufferFactor); 31 init(); 32 } 33 34 public ContainerLocationLoc(int capacity, int slack) { 35 super(capacity, slack); 36 init(); 37 } 38 39 private void init() { 40 dataFileIds = new int[keys.length]; 42 positions = new int[keys.length]; 43 } 45 46 51 public void putContainerLocation(int pos, ContainerLocation containerLocation) { 52 dataFileIds[pos] = containerLocation.getDataFileId(); 54 positions[pos] = containerLocation.getPosition(); 55 } 57 58 protected void move(int from, int to) { 59 super.move(from, to); 60 dataFileIds[to] = dataFileIds[from]; 62 positions[to] = positions[from]; 63 65 } 66 67 78 public ContainerLocation getContainerLocation(int pos) { 79 ContainerLocation result = new ContainerLocation(dataFileIds[pos], positions[pos]); 80 return result; 81 } 82 83 94 public String toString() { 95 StringBuffer result = new StringBuffer (super.toString()); 96 result.append(" nodes ["); 97 98 for (int i = 0; i < dataFileIds.length; i++) { 100 result.append(dataFileIds[i]); 101 if (!isInUse(i)) { 102 result.append("D"); 103 } 104 if (i < dataFileIds.length - 1) { 105 result.append(", "); 106 } else { 107 result.append("]"); 108 } 109 } 110 111 return result.toString(); 112 } 113 114 116 public static void main(String [] args) throws Exception { 117 long start = System.currentTimeMillis(); 118 for (int test = 0; test < 1000; test++) { 119 int SIZE = 100; 120 ContainerLocationLoc containerLocationLoc = new ContainerLocationLoc(SIZE, 0.1F); 121 for(int i = 0; i < SIZE; i++) { 122 ContainerLocation loc = new ContainerLocation((int) (Math.random() * Integer.MAX_VALUE), (int) (Math.random() * Integer.MAX_VALUE)); 123 int pos = containerLocationLoc.putKey(i); 124 containerLocationLoc.putContainerLocation(pos, loc); 125 } 126 ObjectOutputStream out = new ObjectOutputStream (new BufferedOutputStream (new FileOutputStream ("/home/leo/delme." + test), 8192)); 127 out.writeObject(containerLocationLoc); 128 out.close(); 129 } 130 System.out.println("that took " + (System.currentTimeMillis() - start) + " msec."); 131 } 132 133 } 134 | Popular Tags |