Example #1
0
 public void serialize(SerializerOutput out, HashNode obj) throws IOException {
   if (obj.getClass() == HashBucket.class) {
     out.write(Serialization.HTREE_BUCKET);
     HashBucket b = (HashBucket) obj;
     b.writeExternal(out);
   } else {
     out.write(Serialization.HTREE_DIRECTORY);
     HashDirectory n = (HashDirectory) obj;
     n.writeExternal(out);
   }
 }
Example #2
0
  /**
   * Remove the value which is associated with the given key. If the key does not exist, this method
   * simply ignores the operation.
   *
   * @param key key whose associated value is to be removed
   */
  public synchronized void remove(K key) throws IOException {
    V val = null;
    if (!recordListeners.isEmpty()) val = find(key);

    _root.remove(key);
    if (val != null) for (RecordListener<K, V> r : recordListeners) r.recordRemoved(key, val);
  }
Example #3
0
  /**
   * Associates the specified value with the specified key.
   *
   * @param key key with which the specified value is to be assocated.
   * @param value value to be associated with the specified key.
   */
  public synchronized void put(K key, V value) throws IOException {
    V oldVal = null;
    if (!recordListeners.isEmpty()) oldVal = find(key);

    _root.put(key, value);

    if (oldVal == null) {
      for (RecordListener<K, V> r : recordListeners) r.recordInserted(key, value);
    } else {
      for (RecordListener<K, V> r : recordListeners) r.recordUpdated(key, oldVal, value);
    }
  }
Example #4
0
 public HashNode deserialize(SerializerInput ds) throws IOException {
   try {
     int i = ds.read();
     if (i == Serialization.HTREE_BUCKET) { // is HashBucket?
       HashBucket ret = new HashBucket(HTree.this);
       ret.readExternal(ds);
       if (ds.available() != 0
           && ds.read() != -1) // -1 is fix for compression, not sure what is happening
       throw new InternalError("bytes left: " + ds.available());
       return ret;
     } else if (i == Serialization.HTREE_DIRECTORY) {
       HashDirectory ret = new HashDirectory(HTree.this);
       ret.readExternal(ds);
       if (ds.available() != 0
           && ds.read() != -1) // -1 is fix for compression, not sure what is happening
       throw new InternalError("bytes left: " + ds.available());
       return ret;
     } else {
       throw new InternalError("Wrong HTree header: " + i);
     }
   } catch (ClassNotFoundException e) {
     throw new IOException(e);
   }
 }
Example #5
0
 public RecordManager getRecordManager() {
   return _root.getRecordManager();
 }
Example #6
0
 /** Get the record identifier used to load this hashtable. */
 public long getRecid() {
   return _root.getRecid();
 }
Example #7
0
 /** Returns an enumeration of the values contained in this */
 public synchronized Iterator<V> values() throws IOException {
   return _root.values();
 }
Example #8
0
 /** Returns an enumeration of the keys contained in this */
 public synchronized Iterator<K> keys() throws IOException {
   return _root.keys();
 }
Example #9
0
 /**
  * Returns the value which is associated with the given key. Returns <code>null</code> if there is
  * not association for this key.
  *
  * @param key key whose associated value is to be returned
  */
 public synchronized V find(K key) throws IOException {
   return _root.get(key);
 }