本文整理汇总了Java中org.sdnplatform.sync.Versioned.getVersion方法的典型用法代码示例。如果您正苦于以下问题:Java Versioned.getVersion方法的具体用法?Java Versioned.getVersion怎么用?Java Versioned.getVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sdnplatform.sync.Versioned
的用法示例。
在下文中一共展示了Versioned.getVersion方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleSyncOffer
import org.sdnplatform.sync.Versioned; //导入方法依赖的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.Versioned; //导入方法依赖的package包/类
public List<Versioned<T>> resolveConflicts(List<Versioned<T>> items) {
if(items.size() <= 1) {
return items;
} else {
Versioned<T> max = items.get(0);
long maxTime =
((VectorClock) items.get(0).getVersion()).getTimestamp();
VectorClock maxClock = ((VectorClock) items.get(0).getVersion());
for(Versioned<T> versioned: items) {
VectorClock clock = (VectorClock) versioned.getVersion();
if(clock.getTimestamp() > maxTime) {
max = versioned;
maxTime = ((VectorClock) versioned.getVersion()).
getTimestamp();
}
maxClock = maxClock.merge(clock);
}
Versioned<T> maxTimeClockVersioned =
new Versioned<T>(max.getValue(), maxClock);
return Collections.singletonList(maxTimeClockVersioned);
}
}
示例3: handleSyncOffer
import org.sdnplatform.sync.Versioned; //导入方法依赖的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: put
import org.sdnplatform.sync.Versioned; //导入方法依赖的package包/类
@Override
public IVersion put(K key, Versioned<V> versioned)
throws SyncException {
VectorClock vc = (VectorClock)versioned.getVersion();
vc = vc.incremented(syncManager.getLocalNodeId(),
System.currentTimeMillis());
versioned = Versioned.value(versioned.getValue(), vc);
delegate.put(key, versioned);
return versioned.getVersion();
}
示例5: doput
import org.sdnplatform.sync.Versioned; //导入方法依赖的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: testObsoletePutFails
import org.sdnplatform.sync.Versioned; //导入方法依赖的package包/类
private void testObsoletePutFails(String message,
IStore<K, V> store,
K key,
Versioned<V> versioned) throws SyncException {
VectorClock clock = (VectorClock) versioned.getVersion();
clock = clock.clone();
try {
store.put(key, versioned);
fail(message);
} catch(ObsoleteVersionException e) {
// this is good, but check that we didn't fuck with the version
assertEquals(clock, versioned.getVersion());
}
}