Exemple #1
0
  public synchronized <K> NavigableSet<K> createTreeSet(BTreeSetMaker m) {
    checkNameNotExists(m.name);
    m.serializer = fillNulls(m.serializer);
    m.serializer =
        catPut(
            m.name + ".keySerializer",
            m.serializer,
            new BTreeKeySerializer.BasicKeySerializer(getDefaultSerializer()));
    m.comparator = catPut(m.name + ".comparator", m.comparator, Utils.COMPARABLE_COMPARATOR);

    if (m.pumpPresortBatchSize != -1) {
      m.pumpSource =
          Pump.sort(
              m.pumpSource,
              m.pumpPresortBatchSize,
              Collections.reverseOrder(m.comparator),
              getDefaultSerializer());
    }

    long counterRecid = !m.keepCounter ? 0L : engine.put(0L, Serializer.LONG);
    long rootRecidRef;

    if (m.pumpSource == null) {
      rootRecidRef = BTreeMap.createRootRef(engine, m.serializer, null, m.comparator);
    } else {
      rootRecidRef =
          Pump.buildTreeMap(
              m.pumpSource,
              engine,
              Fun.noTransformExtractor(),
              null,
              m.nodeSize,
              false,
              counterRecid,
              m.serializer,
              null,
              m.comparator);
    }

    NavigableSet<K> ret =
        new BTreeMap<K, Object>(
                engine,
                catPut(m.name + ".rootRecidRef", rootRecidRef),
                catPut(m.name + ".maxNodeSize", m.nodeSize),
                false,
                catPut(m.name + ".counterRecid", counterRecid),
                m.serializer,
                null,
                m.comparator)
            .keySet();
    catalog.put(m.name + ".type", "TreeSet");
    collections.put(m.name, new WeakReference<Object>(ret));
    return ret;
  }
  public static void main(String[] args) throws Exception {
    // Read and output 3 lines
    ProcessBuilder builder = new ProcessBuilder("head", "-n", "3");
    final Process process = builder.start();
    //    Pump pump = new Pump(process.getInputStream(), System.out);
    //    pump.start();
    //    System.out.println("Started to pipe System.in.");
    Pump pump = new Pump(System.in, process.getOutputStream());
    pump.start();
    IOUtils.copy(process.getInputStream(), System.out);

    //    new Pump(System.in, process.getOutputStream()).run();
    //    IOUtils.copy(System.in, process.getOutputStream());
    process.waitFor();
    // System.in.close();
    System.out.println("Process finished.");
  }
Exemple #3
0
  @Override
  public boolean isLoggable(LogRecord record) {
    Object o = record.getParameters()[0];

    if (o instanceof Car) {
      Car tmpCar = (Car) o;
      if (className == "Car" && tmpCar.getId() == id) return true;
    } else if (o instanceof Pump) {
      Pump tmpPump = (Pump) o;
      if (className == "Pump" && tmpPump.getId() == id) return true;
    } else if (o instanceof Cashier) {
      Cashier tmpCashier = (Cashier) o;
      if (className == "Cashier" && tmpCashier.getId() == id) return true;
    } else if (o instanceof CoffeeHouse) {
      if (className == "CoffeeHouse" && id == 1) return true;
    } else if (o == null) {
      return true;
    }

    return false;
  }
Exemple #4
0
  protected synchronized <K, V> BTreeMap<K, V> createTreeMap(BTreeMapMaker m) {
    String name = m.name;
    checkNameNotExists(name);
    m.keySerializer = fillNulls(m.keySerializer);
    m.keySerializer =
        catPut(
            name + ".keySerializer",
            m.keySerializer,
            new BTreeKeySerializer.BasicKeySerializer(getDefaultSerializer()));
    m.valueSerializer =
        catPut(name + ".valueSerializer", m.valueSerializer, getDefaultSerializer());
    m.comparator = catPut(name + ".comparator", m.comparator, Utils.COMPARABLE_COMPARATOR);

    long counterRecid = !m.keepCounter ? 0L : engine.put(0L, Serializer.LONG);

    long rootRecidRef;
    if (m.pumpSource == null) {
      rootRecidRef =
          BTreeMap.createRootRef(engine, m.keySerializer, m.valueSerializer, m.comparator);
    } else {
      rootRecidRef =
          Pump.buildTreeMap(
              m.pumpSource,
              engine,
              m.pumpKeyExtractor,
              m.pumpValueExtractor,
              m.nodeSize,
              m.valuesStoredOutsideNodes,
              counterRecid,
              m.keySerializer,
              m.valueSerializer,
              m.comparator);
    }

    BTreeMap<K, V> ret =
        new BTreeMap<K, V>(
            engine,
            catPut(name + ".rootRecidRef", rootRecidRef),
            catPut(name + ".maxNodeSize", m.nodeSize),
            catPut(name + ".valuesOutsideNodes", m.valuesStoredOutsideNodes),
            catPut(name + ".counterRecid", counterRecid),
            m.keySerializer,
            m.valueSerializer,
            m.comparator);
    catalog.put(name + ".type", "TreeMap");
    collections.put(name, new WeakReference<Object>(ret));
    return ret;
  }
  public static void main(String[] args) {
    if (1 == 1) return;

    // create inMemory store which does not use serialization,
    // and has speed comparable to `java.util` collections
    DB inMemory = new DB(new StoreHeap());
    Map m = inMemory.getTreeMap("test");

    Random r = new Random();
    // insert random stuff, keep on mind it needs to fit into memory
    for (int i = 0; i < 10000; i++) {
      m.put(r.nextInt(), "dwqas" + i);
    }

    // now create on-disk store, it needs to be completely empty
    File targetFile = UtilsTest.tempDbFile();
    DB target = DBMaker.newFileDB(targetFile).make();

    Pump.copy(inMemory, target);

    inMemory.close();
    target.close();
  }
Exemple #6
0
 public void brew() {
   heater.get().on();
   pump.pump();
   System.out.println(" [_]P coffee! [_]P ");
   heater.get().off();
 }
Exemple #7
0
  public static void main(String[] args) throws IOException {

    /** max number of elements to import */
    final long max = (int) 1e6;

    /** Open database in temporary directory */
    File dbFile = File.createTempFile("mapdb", "temp");
    DB db =
        DBMaker.newFileDB(dbFile)
            /** disabling Write Ahead Log makes import much faster */
            .transactionDisable()
            .make();

    long time = System.currentTimeMillis();

    /**
     * Source of data which randomly generates strings. In real world this would return data from
     * file.
     */
    Iterator<String> source =
        new Iterator<String>() {

          long counter = 0;

          @Override
          public boolean hasNext() {
            return counter < max;
          }

          @Override
          public String next() {
            counter++;
            return randomString(10);
          }

          @Override
          public void remove() {}
        };

    /**
     * BTreeMap Data Pump requires data source to be presorted in reverse order (highest to lowest).
     * There is method in Data Pump we can use to sort data. It uses temporarly files and can handle
     * fairly large data sets.
     */
    source =
        Pump.sort(
            source,
            true,
            100000,
            Collections.reverseOrder(BTreeMap.COMPARABLE_COMPARATOR), // reverse  order comparator
            db.getDefaultSerializer());

    /**
     * Disk space used by serialized keys should be minimised. Keys are sorted, so only difference
     * between consequential keys is stored. This method is called delta-packing and typically saves
     * 60% of disk space.
     */
    BTreeKeySerializer<String> keySerializer = BTreeKeySerializer.STRING;

    /** Translates Map Key into Map Value. */
    Fun.Function1<Integer, String> valueExtractor =
        new Fun.Function1<Integer, String>() {
          @Override
          public Integer run(String s) {
            return s.hashCode();
          }
        };

    /** Create BTreeMap and fill it with data */
    Map<String, Integer> map =
        db.createTreeMap("map")
            .pumpSource(source, valueExtractor)
            // .pumpPresort(100000) // for presorting data we could also use this method
            .keySerializer(keySerializer)
            .make();

    System.out.println(
        "Finished; total time: "
            + (System.currentTimeMillis() - time) / 1000
            + "s; there are "
            + map.size()
            + " items in map");
    db.close();
  }
Exemple #8
0
 public void brew() {
   heater.get().on();
   pump.pump();
   Window.alert(" [_]P coffee! [_]P ");
   heater.get().off();
 }