本文整理汇总了Java中org.sdnplatform.sync.Versioned类的典型用法代码示例。如果您正苦于以下问题:Java Versioned类的具体用法?Java Versioned怎么用?Java Versioned使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Versioned类属于org.sdnplatform.sync包,在下文中一共展示了Versioned类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
@Override
public boolean execute(String[] tokens, String line) throws Exception {
if (tokens.length < 2) {
err.println("Usage: " + syntaxString());
return false;
}
if (!checkStoreSettings()) return false;
StringReader sr = new StringReader(line);
while (sr.read() != ' ');
JsonParser jp = mjf.createParser(sr);
JsonNode keyNode = validateJson(jp);
if (keyNode == null) return false;
out.println("Getting Key:");
out.println(writer.writeValueAsString(keyNode));
out.println("");
Versioned<JsonNode> value = storeClient.get(keyNode);
display(value);
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: cleanupTask
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
@Override
public void cleanupTask() throws SyncException {
Connection dbConnection = null;
PreparedStatement stmt = null;
try {
dbConnection = getConnection();
dbConnection.setAutoCommit(true);
stmt = dbConnection.prepareStatement(getSql(SELECT_ALL));
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
List<Versioned<byte[]>> items = getVersionedList(rs);
if (StoreUtils.canDelete(items, tombstoneDeletion)) {
doClearTombstone(rs.getString("datakey"));
}
}
} catch (Exception e) {
logger.error("Failed to delete key", e);
} finally {
cleanupSQL(dbConnection, stmt);
}
}
示例4: queueHint
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
/**
* Add a key/value to the hint store for the given store
* @param storeName the name of the store for the keyed value
* @param key the key
* @param value the value
*/
public void queueHint(String storeName,
ByteArray key, Versioned<byte[]> value) {
try {
HintKey hk = new HintKey(storeName,key);
hintLock.lock();
try {
boolean needed = !hints.containsKey(hk);
needed &= hints.doput(hk, value);
if (needed) {
hintQueue.add(hk);
hintsAvailable.signal();
}
} finally {
hintLock.unlock();
}
} catch (SyncException e) {
logger.error("Failed to queue hint for store " + storeName, e);
}
}
示例5: takeHints
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
/**
* Drain up to the given number of hints to the provided collection.
* This method will block until at least one hint is available
* @param c the collection to which the hints should be copied
* @param maxElements the maximum number of hints to drain
* @throws InterruptedException
*/
public void takeHints(Collection<Hint> c, int maxElements)
throws InterruptedException {
int count = 0;
try {
while (count == 0) {
hintLock.lock();
while (hintQueue.isEmpty()) {
hintsAvailable.await();
}
while (count < maxElements && !hintQueue.isEmpty()) {
HintKey hintKey = hintQueue.pollFirst();
if (hintKey != null) {
List<Versioned<byte[]>> values = hints.remove(hintKey);
if (values == null) {
continue;
}
c.add(new Hint(hintKey, values));
count += 1;
}
}
}
} finally {
hintLock.unlock();
}
}
示例6: 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;
}
示例7: resolveConflicts
import org.sdnplatform.sync.Versioned; //导入依赖的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;
}
示例8: updateSeeds
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
private void updateSeeds(ClusterConfig config) throws SyncException {
List<String> hosts = new ArrayList<String>();
for (Node n : config.getNodes()) {
if (!config.getNode().equals(n)) {
HostAndPort h =
HostAndPort.fromParts(n.getHostname(), n.getPort());
hosts.add(h.toString());
}
}
Collections.sort(hosts);
String seeds = Joiner.on(',').join(hosts);
while (true) {
try {
Versioned<String> sv = unsyncStoreClient.get(SEEDS);
if (sv.getValue() == null || !sv.getValue().equals(seeds)) {
if (logger.isDebugEnabled()) {
logger.debug("[{}] Updating seeds to \"{}\" from \"{}\"",
new Object[]{config.getNode().getNodeId(),
seeds, sv.getValue()});
}
unsyncStoreClient.put(SEEDS, seeds);
}
break;
} catch (ObsoleteVersionException e) { }
}
}
示例9: cleanupTask
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
@Override
public void cleanupTask() {
// Remove tombstones that are older than the tombstone deletion
// threshold. If a value is deleted and the tombstone has been
// cleaned up before the cluster is fully synchronized, then there
// is a chance that deleted values could be resurrected
Iterator<Entry<K, List<Versioned<V>>>> iter = map.entrySet().iterator();
while (iter.hasNext()) {
Entry<K, List<Versioned<V>>> e = iter.next();
List<Versioned<V>> items = e.getValue();
synchronized (items) {
if (StoreUtils.canDelete(items, tombstoneDeletion))
iter.remove();
}
}
}
示例10: next
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
@Override
public Pair<ByteArray, List<Versioned<byte[]>>> next() {
if (hasNext()) {
try {
ByteArray key = getStringAsKey(rs.getString("datakey"));
List<Versioned<byte[]>> vlist = getVersionedList(rs);
hasNextSet = false;
return new Pair<ByteArray,
List<Versioned<byte[]>>>(key, vlist);
} catch (Exception e) {
throw new SyncRuntimeException("Error in DB Iterator",
new PersistException(e));
}
} else {
throw new NoSuchElementException();
}
}
示例11: get
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
@Override
public List<Versioned<byte[]>> get(ByteArray key) throws SyncException {
StoreUtils.assertValidKey(key);
Connection dbConnection = null;
PreparedStatement stmt = null;
try {
dbConnection = getConnection();
stmt = dbConnection.prepareStatement(getSql(SELECT_KEY));
return doSelect(stmt, getKeyAsString(key));
} catch (Exception e) {
throw new PersistException("Could not retrieve key" +
" from database",
e);
} finally {
cleanupSQL(dbConnection, stmt);
}
}
示例12: getVersionedList
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
private static List<Versioned<byte[]>> getVersionedList(ResultSet rs)
throws SQLException, JsonParseException,
JsonMappingException, IOException {
InputStream is = rs.getBinaryStream("datavalue");
return mapper.readValue(is,
new TypeReference<List<VCVersioned<byte[]>>>() {});
}
示例13: put
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
@Override
public IVersion put(K key, V value) throws SyncException {
List<IVersion> versions = getVersions(key);
Versioned<V> versioned;
if(versions.isEmpty())
versioned = Versioned.value(value, new VectorClock());
else if(versions.size() == 1)
versioned = Versioned.value(value, versions.get(0));
else {
versioned = get(key, null);
if(versioned == null)
versioned = Versioned.value(value, new VectorClock());
else
versioned.setValue(value);
}
return put(key, versioned);
}
示例14: display
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
protected void display(Versioned<JsonNode> value) throws Exception {
if (value.getValue() == null) {
out.println("Not found");
} else {
out.println("Value:");
out.println(writer.writeValueAsString(value.getValue()));
}
}
示例15: getStoreClient
import org.sdnplatform.sync.Versioned; //导入依赖的package包/类
/**
* The "real" version of getStoreClient that will be called by all
* the others
* @param storeName the store name
* @param keyClass the key class
* @param keyType the key type
* @param valueClass the value class
* @param valueType the value type
* @param resolver the inconsistency resolver
* @return a {@link DefaultStoreClient} using the given parameters.
* @throws UnknownStoreException
*/
public <K, V> IStoreClient<K, V>
getStoreClient(String storeName,
Class<K> keyClass,
TypeReference<K> keyType,
Class<V> valueClass,
TypeReference<V> valueType,
IInconsistencyResolver<Versioned<V>> resolver)
throws UnknownStoreException {
IStore<ByteArray,byte[]> store = getStore(storeName);
IStore<K, V> serializingStore;
if (valueType != null && keyType != null) {
serializingStore =
new JacksonStore<K, V>(store, keyType, valueType);
} else if (valueClass != null && keyClass != null) {
serializingStore =
new JacksonStore<K, V>(store, keyClass, valueClass);
} else {
throw new IllegalArgumentException("Must include type reference" +
" or value class");
}
DefaultStoreClient<K, V> storeClient =
new DefaultStoreClient<K, V>(serializingStore,
resolver,
this,
keyClass,
keyType);
return storeClient;
}