当前位置: 首页>>代码示例>>Java>>正文


Java DBIterator.close方法代码示例

本文整理汇总了Java中org.iq80.leveldb.DBIterator.close方法的典型用法代码示例。如果您正苦于以下问题:Java DBIterator.close方法的具体用法?Java DBIterator.close怎么用?Java DBIterator.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.iq80.leveldb.DBIterator的用法示例。


在下文中一共展示了DBIterator.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: replace

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public static <T extends D_Level> void replace(String cluster, Class<T> clazz, List<T> data) throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	WriteBatch write = db.createWriteBatch();
	try {
		iterator.seekToFirst();
		iterator.forEachRemaining(entry ->{
			byte[] key = entry.getKey();
			write.delete(key);
		});
		data.forEach(t->{
			write.put(t.key().getBytes(), t.value());
		});
		db.write(write, new WriteOptions().sync(true));
	} finally {
		iterator.close();
		write.close();
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:21,代码来源:LevelTable.java

示例2: last

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends D_TimeLine> T last(String cluster, Class<T> clazz) throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	try {
		iterator.seekToLast();
		if(!iterator.hasNext()){
			return null;
		}
		Entry<byte[], byte[]> entry = iterator.next();
		byte[] v = entry.getValue();
		return (T)D_Level.deserialize(clazz, v);
	} finally {
		iterator.close();
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:18,代码来源:LevelTable.java

示例3: getAll

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends D_Level> List<T> getAll(String cluster, Class<T> clazz)throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	List<T> list = new ArrayList<T>();
	try {
		iterator.seekToFirst();
		iterator.forEachRemaining(entry ->{
			byte[] v = entry.getValue();
			list.add((T)D_Level.deserialize(clazz, v));
		});
	} finally {
		iterator.close();
	}
	return list;
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:18,代码来源:LevelTable.java

示例4: prevWith

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends D_TimeLine> void prevWith(String cluster, Class<T> clazz, Long start, Consumer<T> action) throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	try {
		iterator.seek((start + "").getBytes());
		while(iterator.hasPrev()){
			Entry<byte[], byte[]> entry = iterator.prev();
			byte[] v = entry.getValue();
			action.accept((T)D_Level.deserialize(clazz, v));
		}
	} finally {
		iterator.close();
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:17,代码来源:LevelTable.java

示例5: deletePrev

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public static <T extends D_TimeLine> void deletePrev(String cluster, Class<T> clazz, Long start) throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	WriteBatch write = db.createWriteBatch();
	try {
		iterator.seek((start + "").getBytes());
		while(iterator.hasPrev()){
			byte[] key = iterator.prev().getKey();
			write.delete(key);
		}
		db.write(write, new WriteOptions().sync(true));
	} finally {
		iterator.close();
		write.close();
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:18,代码来源:LevelTable.java

示例6: getNumChunks

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public static int getNumChunks(long obj_id) {
	int num = 0;
	DBIterator iterator = db.iterator();
	// TODO: chunk for obj_id may not start with 0!
	String key = Long.toString(obj_id) + ",0";
	try {
		for (iterator.seek(bytes(key)); iterator.hasNext(); iterator.next()) {
			if (!(asString(iterator.peekNext().getKey()).startsWith(Long
					.toString(obj_id) + ",")))
				break;
			num++;
		}
		iterator.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return num;
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:19,代码来源:SimbaLevelDB.java

示例7: setObjectDirty

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public static void setObjectDirty(long obj_id) {
	int chunk_num = 0;
	DBIterator iterator = db.iterator();
	String key = Long.toString(obj_id) + "," + Integer.toString(chunk_num);
	try {
		for (iterator.seek(bytes(key)); iterator.hasNext(); iterator.next()) {
			if (!(asString(iterator.peekNext().getKey()).startsWith(Long
					.toString(obj_id) + ",")))
				break;

			SimbaChunkList.addDirtyChunk(obj_id, chunk_num);
			chunk_num++;
		}
		iterator.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:19,代码来源:SimbaLevelDB.java

示例8: deleteObject

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public static void deleteObject(long obj_id, int startChunk) {
	String key = Long.toString(obj_id) + "," + Integer.toString(startChunk);
	DBIterator iterator = db.iterator();

	try {
		for (iterator.seek(bytes(key)); iterator.hasNext(); iterator.next()) {
			if (!(asString(iterator.peekNext().getKey()).startsWith(Long
					.toString(obj_id) + ",")))
				break;
			Log.d(TAG, "DELETE <" + asString(iterator.peekNext().getKey())
					+ ">");
			db.delete(iterator.peekNext().getKey());
		}
		iterator.close();
	} catch (IOException e) {
		e.printStackTrace();
	}

	// delete object from dirtyChunkList
	SimbaChunkList.removeDirtyChunks(obj_id);
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:22,代码来源:SimbaLevelDB.java

示例9: startWith

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends D_TimeLine> void startWith(String cluster, Class<T> clazz, Long start, Consumer<T> action) throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	try {
		iterator.seek((start + "").getBytes());
		iterator.forEachRemaining(entry ->{
			byte[] v = entry.getValue();
			action.accept((T)D_Level.deserialize(clazz, v));
		});
	} finally {
		iterator.close();
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:16,代码来源:LevelTable.java

示例10: loadEventStream

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@Override
public List<Event> loadEventStream(UUID aggregateId) {
    checkNotNull(aggregateId);
    DBIterator iterator = null;

    try {
        iterator = eventDatabase.iterator();
        iterator.seek(new Key(aggregateId).toBytes());

        List<Event> events = new ArrayList<>();

        boolean keepMoving = true;
        while (keepMoving && iterator.hasNext()) {
            Map.Entry<byte[], byte[]> entry = iterator.next();
            Key key = Key.deserialize(entry.getKey());
            if (!aggregateId.equals(key.id)) {
                keepMoving = false;
            }  else {
                events.add(deserializeEvent(entry.getValue(), key.schemaFingerprint));
            }
        }
        return events;
    } finally {
        if (iterator != null) {
            try {
                iterator.close();
            } catch (IOException e) {
                logger.error("Error while closing LevelDB iterator", e);
            }
        }
    }
}
 
开发者ID:alexvictoor,项目名称:ESLab,代码行数:33,代码来源:LdbStoreSupport.java

示例11: range

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@Override
public TableIterator<H, R, V> range(H hashKey) {
	final DBIterator iterator = db.iterator();
	final byte[] keyBytesFrom = Util.combine(hashKeySerde, rangeKeySerde,
			hashKey, null);
	iterator.seek(keyBytesFrom);
	return new AutoClosingTableIterator<H, R, V>(
			new TableIterator<H, R, V>() {
				@Override
				public boolean hasNext() {
					return iterator.hasNext()
							&& Util.compareKeys(hashKeyComparator, null,
									keyBytesFrom, iterator.peekNext()
											.getKey()) == 0;
				}

				@Override
				public TableRow<H, R, V> next() {
					return new RawTableRow<H, R, V>(iterator.next(),
							hashKeySerde, rangeKeySerde, valueSerde);
				}

				@Override
				public void remove() {
					iterator.remove();
				}

				@Override
				public void close() {
					try {
						iterator.close();
					} catch (Exception e) {
						throw new DbException(e);
					}
				}
			});
}
 
开发者ID:criccomini,项目名称:ezdb,代码行数:38,代码来源:EzLevelDbTable.java

示例12: delete

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@Override
public long delete(WriteToken token, Metadata metadata, long start, long end) throws IOException {
  
  //
  // Regen classId/labelsId
  //
  
  // 128BITS
  metadata.setLabelsId(GTSHelper.labelsId(this.keystore.getKey(KeyStore.SIPHASH_LABELS), metadata.getLabels()));
  metadata.setClassId(GTSHelper.classId(this.keystore.getKey(KeyStore.SIPHASH_CLASS), metadata.getName()));

  //
  // Retrieve an iterator
  //
  
  DBIterator iterator = this.db.iterator();
  
  //
  // Seek the most recent key
  //
  
  // 128BITS
  byte[] bend = new byte[Store.HBASE_RAW_DATA_KEY_PREFIX.length + 8 + 8 + 8];
  ByteBuffer bb = ByteBuffer.wrap(bend).order(ByteOrder.BIG_ENDIAN);
  bb.put(Store.HBASE_RAW_DATA_KEY_PREFIX);
  bb.putLong(metadata.getClassId());
  bb.putLong(metadata.getLabelsId());
  bb.putLong(Long.MAX_VALUE - end);

  iterator.seek(bend);
  
  byte[] bstart = new byte[bend.length];
  bb = ByteBuffer.wrap(bstart).order(ByteOrder.BIG_ENDIAN);
  bb.put(Store.HBASE_RAW_DATA_KEY_PREFIX);
  bb.putLong(metadata.getClassId());
  bb.putLong(metadata.getLabelsId());
  bb.putLong(Long.MAX_VALUE - start);
  
  //
  // Scan the iterator, deleteing keys if they are between start and end
  //
  
  long count = 0L;
  
  while (iterator.hasNext()) {
    Entry<byte[],byte[]> entry = iterator.next();
    
    if (Bytes.compareTo(entry.getKey(), bend) >= 0 && Bytes.compareTo(entry.getKey(), bstart) <= 0) {
      this.db.delete(entry.getKey());
      count++;
    } else {
      break;
    }
  }
  
  iterator.close();
  
  return count;
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:60,代码来源:StandaloneStoreClient.java

示例13: truncate

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public static int truncate(long obj_id, int length, boolean makeDirty) {
	int chunk_num = length / CHUNKSIZE;
	int off = length % CHUNKSIZE;
	int index = 0;

	DBIterator iterator = db.iterator();
	String key = Long.toString(obj_id) + ",0";
	try {
		for (iterator.seek(bytes(key)); iterator.hasNext(); iterator.next()) {
			if (!(asString(iterator.peekNext().getKey()).startsWith(Long
					.toString(obj_id) + ",")))
				break;
			if (index == chunk_num) {
				if (makeDirty) {
					// mark last chunk as dirty
					SimbaChunkList.addDirtyChunk(obj_id, index);
				}

				// if part of chunk is deleted, mark this chunk as dirty
				byte[] buf = db.get(iterator.peekNext().getKey());
				if (buf.length > off) {
					Log.d(TAG, "RESIZE <"
							+ asString(iterator.peekNext().getKey())
							+ "> from " + buf.length + " -> " + off);
					byte[] new_buf = new byte[off];
					System.arraycopy(buf, 0, new_buf, 0, off);
					db.put(iterator.peekNext().getKey(), new_buf);
				}
			}
			// delete all chunks beyond the chunk_num
			else if (index > chunk_num) {
				// remove from dirty chunk list if it was set as dirty
				SimbaChunkList.removeDirtyChunk(obj_id, index);

				// delete chunk
				Log.d(TAG, "DELETE <"
						+ asString(iterator.peekNext().getKey()) + ">");
				db.delete(iterator.peekNext().getKey());
			}
			index++;
		}
		iterator.close();
	} catch (IOException e) {
		e.printStackTrace();
	}

	return length;
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:49,代码来源:SimbaLevelDB.java

示例14: read

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public int read(long obj_id, byte[] buffer, int offset) {
	String key = null;
	byte[] buf = new byte[CHUNKSIZE];
	int chunk_num = offset / CHUNKSIZE;
	offset -= chunk_num * CHUNKSIZE;
	int len = 0;
	boolean hasData = false;

	DBIterator iterator = db.iterator();
	key = Long.toString(obj_id) + "," + Integer.toString(chunk_num);
	try {
		for (iterator.seek(bytes(key)); iterator.hasNext(); iterator.next()) {
			if (!(asString(iterator.peekNext().getKey()).startsWith(Long
					.toString(obj_id) + ",")))
				break;

			hasData = true;
			buf = db.get(iterator.peekNext().getKey());

			if (buffer.length - len < buf.length - offset) {
				System.arraycopy(buf, offset, buffer, len, buffer.length
						- len);
				len += buffer.length - len;
			} else {
				System.arraycopy(buf, offset, buffer, len, buf.length
						- offset);
				len += buf.length - offset;
			}
			Log.d(TAG, "GET <" + asString(iterator.peekNext().getKey())
					+ ">, buffer[" + buf.length + "]");
			// Log.d(TAG, "GET <" + asString(iterator.peekNext().getKey())
			// + ">, buffer[" + buf.length + "] = " + asString(buf));
			if (len >= buffer.length || buf.length < CHUNKSIZE)
				break;

			offset = 0;
		}
		iterator.close();
	} catch (IOException e) {
		e.printStackTrace();
	}

	if (hasData) {
		return len;
	} else {
		return -1;
	}
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:49,代码来源:SimbaLevelDB.java

示例15: truncateStrong

import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public static int truncateStrong(long fromObj, long toObj, int length) {
	Log.d(TAG, "truncate for strong consistency from obj: " + fromObj
			+ " to obj: " + toObj + " with length: " + length);
	String key = Long.toString(fromObj) + ",0";
	DBIterator iterator = db.iterator();
	int chunk_num = length / CHUNKSIZE;
	int off = length % CHUNKSIZE;
	int index = 0;

	try {
		for (iterator.seek(bytes(key)); iterator.hasNext(); iterator.next()) {
			// read fromObj's chunk
			byte[] buf = db.get(iterator.peekNext().getKey());
			String toKey = Long.toString(toObj) + ","
					+ Integer.toString(index);
			if (chunk_num == index) {
				if (buf.length > off) {
					Log.d(TAG, "RESIZE <" + toKey + "> from " + buf.length
							+ " -> " + off);
					byte[] new_buf = new byte[off];
					System.arraycopy(buf, 0, new_buf, 0, off);

					// write to toObj's chunk
					Log.d(TAG, "PUT <" + toKey + ">, buffer["
							+ new_buf.length + "]");
					db.put(bytes(toKey), new_buf);
					SimbaChunkList.addDirtyChunk(toObj, index);
				}
				break;
			} else {
				// write to toObj's chunk
				Log.d(TAG, "PUT <" + toKey + ">, buffer[" + buf.length
						+ "]");
				db.put(bytes(toKey), buf);
				SimbaChunkList.addDirtyChunk(toObj, index);

				index++;
			}
		}
		iterator.close();
	} catch (IOException e) {
		e.printStackTrace();
	}

	return length;
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:47,代码来源:SimbaLevelDB.java


注:本文中的org.iq80.leveldb.DBIterator.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。