本文整理汇总了Java中org.sdnplatform.sync.IVersion.Occurred类的典型用法代码示例。如果您正苦于以下问题:Java Occurred类的具体用法?Java Occurred怎么用?Java Occurred使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Occurred类属于org.sdnplatform.sync.IVersion包,在下文中一共展示了Occurred类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleSyncOffer
import org.sdnplatform.sync.IVersion.Occurred; //导入依赖的package包/类
/**
* Check whether any of the specified versions for the key are not older
* than the versions we already have
* @param storeName the store to check
* @param key the key to check
* @param versions an iterable over the versions
* @return true if we'd like a copy of the data indicated
* @throws SyncException
*/
public boolean handleSyncOffer(String storeName,
byte[] key,
Iterable<VectorClock> versions)
throws SyncException {
SynchronizingStorageEngine store = storeRegistry.get(storeName);
if (store == null) return true;
List<Versioned<byte[]>> values = store.get(new ByteArray(key));
if (values == null || values.size() == 0) return true;
// check whether any of the versions are not older than what we have
for (VectorClock vc : versions) {
for (Versioned<byte[]> value : values) {
VectorClock existingVc = (VectorClock)value.getVersion();
if (!vc.compare(existingVc).equals(Occurred.BEFORE))
return true;
}
}
return false;
}
示例2: resolveConflicts
import org.sdnplatform.sync.IVersion.Occurred; //导入依赖的package包/类
public List<Versioned<T>> resolveConflicts(List<Versioned<T>> items) {
int size = items.size();
if(size <= 1)
return items;
List<Versioned<T>> newItems = Lists.newArrayList();
for(Versioned<T> v1: items) {
boolean found = false;
for(ListIterator<Versioned<T>> it2 =
newItems.listIterator(); it2.hasNext();) {
Versioned<T> v2 = it2.next();
Occurred compare = v1.getVersion().compare(v2.getVersion());
if(compare == Occurred.AFTER) {
if(found)
it2.remove();
else
it2.set(v1);
}
if(compare != Occurred.CONCURRENTLY)
found = true;
}
if(!found)
newItems.add(v1);
}
return newItems;
}
示例3: handleSyncOffer
import org.sdnplatform.sync.IVersion.Occurred; //导入依赖的package包/类
/**
* Check whether any of the specified versions for the key are not older
* than the versions we already have
* @param storeName the store to check
* @param key the key to check
* @param versions an iterable over the versions
* @return true if we'd like a copy of the data indicated
* @throws SyncException
*/
public boolean handleSyncOffer(String storeName,
byte[] key,
Iterable<VectorClock> versions)
throws SyncException {
SynchronizingStorageEngine store = storeRegistry.get(storeName);
if (store == null) return true;
List<Versioned<byte[]>> values = store.get(new ByteArray(key));
if (values == null || values.size() == 0) return true;
// check whether any of the versions are not older than what we have
for (VectorClock vc : versions) {
for (Versioned<byte[]> value : values) {
VectorClock existingVc = (VectorClock)value.getVersion();
if (!vc.compare(existingVc).equals(Occurred.BEFORE))
return true;
}
}
return false;
}
示例4: compare
import org.sdnplatform.sync.IVersion.Occurred; //导入依赖的package包/类
public int compare(Versioned<S> v1, Versioned<S> v2) {
Occurred occurred = v1.getVersion().compare(v2.getVersion());
if(occurred == Occurred.BEFORE)
return -1;
else if(occurred == Occurred.AFTER)
return 1;
else
return 0;
}
示例5: doput
import org.sdnplatform.sync.IVersion.Occurred; //导入依赖的package包/类
public boolean doput(K key, Versioned<V> value) throws SyncException {
StoreUtils.assertValidKey(key);
IVersion version = value.getVersion();
while(true) {
List<Versioned<V>> items = map.get(key);
// If we have no value, optimistically try to add one
if(items == null) {
items = new ArrayList<Versioned<V>>();
items.add(new Versioned<V>(value.getValue(), version));
if (map.putIfAbsent(key, items) != null)
continue;
return true;
} else {
synchronized(items) {
// if this check fails, items has been removed from the map
// by delete, so we try again.
if(map.get(key) != items)
continue;
// Check for existing versions - remember which items to
// remove in case of success
List<Versioned<V>> itemsToRemove = new ArrayList<Versioned<V>>(items.size());
for(Versioned<V> versioned: items) {
Occurred occurred = value.getVersion().compare(versioned.getVersion());
if(occurred == Occurred.BEFORE) {
return false;
} else if(occurred == Occurred.AFTER) {
itemsToRemove.add(versioned);
}
}
items.removeAll(itemsToRemove);
items.add(value);
}
return true;
}
}
}
示例6: testComparisons
import org.sdnplatform.sync.IVersion.Occurred; //导入依赖的package包/类
@Test
public void testComparisons() {
assertTrue("The empty clock should not happen before itself.",
getClock().compare(getClock()) != Occurred.CONCURRENTLY);
assertTrue("A clock should not happen before an identical clock.",
getClock(1, 1, 2).compare(getClock(1, 1, 2)) != Occurred.CONCURRENTLY);
assertTrue(" A clock should happen before an identical clock with a single additional event.",
getClock(1, 1, 2).compare(getClock(1, 1, 2, 3)) == Occurred.BEFORE);
assertTrue("Clocks with different events should be concurrent.",
getClock(1).compare(getClock(2)) == Occurred.CONCURRENTLY);
assertTrue("Clocks with different events should be concurrent.",
getClock(1, 1, 2).compare(getClock(1, 1, 3)) == Occurred.CONCURRENTLY);
assertTrue(getClock(2, 2).compare(getClock(1, 2, 2, 3)) == Occurred.BEFORE
&& getClock(1, 2, 2, 3).compare(getClock(2, 2)) == Occurred.AFTER);
}