本文整理汇总了Java中org.sdnplatform.sync.IClosableIterator类的典型用法代码示例。如果您正苦于以下问题:Java IClosableIterator类的具体用法?Java IClosableIterator怎么用?Java IClosableIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IClosableIterator类属于org.sdnplatform.sync包,在下文中一共展示了IClosableIterator类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
@Override
public boolean execute(String[] tokens, String line) throws Exception {
if (!checkStoreSettings()) return false;
IClosableIterator<Entry<JsonNode, Versioned<JsonNode>>> iter =
storeClient.entries();
try {
while (iter.hasNext()) {
Entry<JsonNode, Versioned<JsonNode>> e = iter.next();
display(e.getKey(), e.getValue());
}
} finally {
iter.close();
}
return false;
}
示例2: keys
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
public static <K, V> IClosableIterator<K>
keys(final IClosableIterator<Entry<K, V>> values) {
return new IClosableIterator<K>() {
public void close() {
values.close();
}
public boolean hasNext() {
return values.hasNext();
}
public K next() {
Entry<K, V> value = values.next();
if(value == null)
return null;
return value.getKey();
}
public void remove() {
values.remove();
}
};
}
示例3: entries
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
@Override
public IClosableIterator<Entry<ByteArray, List<Versioned<byte[]>>>>
entries() {
PreparedStatement stmt = null;
Connection dbConnection = null;
try {
// we never close this connection unless there's an error;
// it must be closed by the DbIterator
dbConnection = getConnection();
stmt = dbConnection.prepareStatement(getSql(SELECT_ALL));
ResultSet rs = stmt.executeQuery();
return new DbIterator(dbConnection, stmt, rs);
} catch (Exception e) {
logger.error("Could not create iterator on data", e);
try {
cleanupSQL(dbConnection, stmt);
} catch (Exception e2) {
logger.error("Failed to clean up after error", e2);
}
return new EmptyClosableIterator<Entry<ByteArray,List<Versioned<byte[]>>>>();
}
}
示例4: getEntriesFromStore
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
private List<DeviceSyncRepresentation> getEntriesFromStore()
throws Exception {
List<DeviceSyncRepresentation> entries =
new ArrayList<DeviceSyncRepresentation>();
IClosableIterator<Entry<String, Versioned<DeviceSyncRepresentation>>> iter =
storeClient.entries();
try {
while(iter.hasNext()) {
Entry<String, Versioned<DeviceSyncRepresentation>> entry =
iter.next();
DeviceSyncRepresentation dsr = entry.getValue().getValue();
if (dsr != null)
assertEquals(entry.getKey(), dsr.getKey());
entries.add(dsr);
}
} finally {
if (iter != null)
iter.close();
}
return entries;
}
示例5: getEntriesFromStore
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
private List<DeviceSyncRepresentation> getEntriesFromStore()
throws Exception {
List<DeviceSyncRepresentation> entries =
new ArrayList<DeviceSyncRepresentation>();
IClosableIterator<Entry<String, Versioned<DeviceSyncRepresentation>>> iter =
storeClient.entries();
try {
while(iter.hasNext()) {
Entry<String, Versioned<DeviceSyncRepresentation>> entry =
iter.next();
DeviceSyncRepresentation dsr = entry.getValue().getValue();
if (dsr != null)
assertEquals(entry.getKey(), dsr.getKey());
entries.add(dsr);
}
} finally {
if (iter != null)
iter.close();
}
return entries;
}
示例6: execute
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
@Override
public boolean execute(String[] tokens, String line) throws Exception {
if (!checkStoreSettings()) return false;
IClosableIterator<Entry<JsonNode, Versioned<JsonNode>>> iter =
storeClient.entries();
try {
while (iter.hasNext()) {
Entry<JsonNode, Versioned<JsonNode>> e = iter.next();
display(e.getKey(), e.getValue());
}
} finally {
iter.close();
}
return false;
}
示例7: Cursor
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
public Cursor(int cursorId,
IClosableIterator<Entry<ByteArray,
List<Versioned<byte[]>>>> delegate) {
super();
this.cursorId = cursorId;
this.delegate = delegate;
}
示例8: goToMaster
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
/**
* Synchronously transition from SLAVE to MASTER. By iterating through
* the store and learning all devices from the store
*/
private void goToMaster() {
if (logger.isDebugEnabled()) {
logger.debug("Transitioning to MASTER role");
}
cntTransitionToMaster.increment();
IClosableIterator<Map.Entry<String,Versioned<DeviceSyncRepresentation>>>
iter = null;
try {
iter = storeClient.entries();
} catch (SyncException e) {
cntSyncException.increment();
logger.error("Failed to read devices from sync store", e);
return;
}
try {
while(iter.hasNext()) {
Versioned<DeviceSyncRepresentation> versionedDevice =
iter.next().getValue();
DeviceSyncRepresentation storedDevice =
versionedDevice.getValue();
if (storedDevice == null)
continue;
cntDevicesFromStore.increment();
for(SyncEntity se: storedDevice.getEntities()) {
learnDeviceByEntity(se.asEntity());
}
}
} finally {
if (iter != null)
iter.close();
}
storeConsolidateTask.reschedule(initialSyncStoreConsolidateMs,
TimeUnit.MILLISECONDS);
}
示例9: testIterator
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
@Test
public void testIterator() throws Exception {
AbstractSyncManager sync = syncManagers[0];
IStoreClient<Key, TBean> testClient =
sync.getStoreClient("local", Key.class, TBean.class);
HashMap<Key, TBean> testMap = new HashMap<Key, TBean>();
for (int i = 0; i < 100; i++) {
Key k = new Key("com.bigswitch.bigsync.internal", "test" + i);
TBean tb = new TBean("value", i);
testMap.put(k, tb);
testClient.put(k, tb);
}
IClosableIterator<Entry<Key, Versioned<TBean>>> iter =
testClient.entries();
int size = 0;
try {
while (iter.hasNext()) {
Entry<Key, Versioned<TBean>> e = iter.next();
assertEquals(testMap.get(e.getKey()), e.getValue().getValue());
size += 1;
}
} finally {
iter.close();
}
assertEquals(testMap.size(), size);
}
示例10: testGetNoEntries
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
public void testGetNoEntries() {
IClosableIterator<Entry<ByteArray, List<Versioned<byte[]>>>> it = null;
try {
IStorageEngine<ByteArray, byte[]> engine = getStorageEngine();
it = engine.entries();
while(it.hasNext())
fail("There shouldn't be any entries in this store.");
} finally {
if(it != null)
it.close();
}
}
示例11: testGetNoKeys
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
@Test
public void testGetNoKeys() {
IClosableIterator<ByteArray> it = null;
try {
IStorageEngine<ByteArray, byte[]> engine = getStorageEngine();
it = engine.keys();
while(it.hasNext())
fail("There shouldn't be any entries in this store.");
} finally {
if(it != null)
it.close();
}
}
示例12: testTruncate
import org.sdnplatform.sync.IClosableIterator; //导入依赖的package包/类
@Test
public void testTruncate() throws Exception {
IStorageEngine<ByteArray, byte[]> engine = getStorageEngine();
Versioned<byte[]> v1 = new Versioned<byte[]>(new byte[] { 1 });
Versioned<byte[]> v2 = new Versioned<byte[]>(new byte[] { 2 });
Versioned<byte[]> v3 = new Versioned<byte[]>(new byte[] { 3 });
ByteArray key1 = new ByteArray((byte) 3);
ByteArray key2 = new ByteArray((byte) 4);
ByteArray key3 = new ByteArray((byte) 5);
engine.put(key1, v1);
engine.put(key2, v2);
engine.put(key3, v3);
engine.truncate();
IClosableIterator<Entry<ByteArray, List<Versioned<byte[]>>>> it = null;
try {
it = engine.entries();
while(it.hasNext()) {
fail("There shouldn't be any entries in this store.");
}
} finally {
if(it != null) {
it.close();
}
}
}