本文整理汇总了Java中org.sdnplatform.sync.Versioned.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Versioned.getValue方法的具体用法?Java Versioned.getValue怎么用?Java Versioned.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sdnplatform.sync.Versioned
的用法示例。
在下文中一共展示了Versioned.getValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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) { }
}
}
示例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: 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()));
}
}
示例4: waitForValue
import org.sdnplatform.sync.Versioned; //导入方法依赖的package包/类
protected static <K, V> Versioned<V> waitForValue(IStoreClient<K, V> client,
K key, V value,
int maxTime,
String clientName)
throws Exception {
Versioned<V> v = null;
long then = System.currentTimeMillis();
while (true) {
v = client.get(key);
if (value != null) {
if (v.getValue() != null && v.getValue().equals(value)) break;
} else {
if (v.getValue() != null) break;
}
if (v.getValue() != null)
logger.info("{}: Value for key {} not yet right: " +
"expected: {}; actual: {}",
new Object[]{clientName, key, value, v.getValue()});
else
logger.info("{}: Value for key {} is null: expected {}",
new Object[]{clientName, key, value});
Thread.sleep(100);
assertTrue(then + maxTime > System.currentTimeMillis());
}
return v;
}
示例5: put
import org.sdnplatform.sync.Versioned; //导入方法依赖的package包/类
@Override
public void put(K key, Versioned<V> value)
throws SyncException {
ByteArray keybytes = getKeyBytes(key);
byte[] valuebytes = value.getValue() != null
? getValueBytes(value.getValue())
: null;
delegate.put(keybytes,
new Versioned<byte[]>(valuebytes, value.getVersion()));
}
示例6: goToMaster
import org.sdnplatform.sync.Versioned; //导入方法依赖的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);
}
示例7: keysModified
import org.sdnplatform.sync.Versioned; //导入方法依赖的package包/类
@Override
public void keysModified(Iterator<DatapathId> keys, UpdateType type) {
if (type == UpdateType.LOCAL) {
// We only care for remote updates
return;
}
while(keys.hasNext()) {
DatapathId key = keys.next();
Versioned<SwitchSyncRepresentation> versionedSwitch = null;
try {
versionedSwitch = storeClient.get(key);
} catch (SyncException e) {
log.error("Exception while retrieving switch " + key.toString() +
" from sync store. Skipping", e);
continue;
}
if (log.isTraceEnabled()) {
log.trace("Reveiced switch store notification: key={}, " +
"entry={}", key, versionedSwitch.getValue());
}
// versionedSwtich won't be null. storeClient.get() always
// returns a non-null or throws an exception
if (versionedSwitch.getValue() == null) {
switchRemovedFromStore(key);
continue;
}
SwitchSyncRepresentation storedSwitch = versionedSwitch.getValue();
IOFSwitch sw = getSwitch(storedSwitch.getDpid());
//TODO @Ryan need to get IOFSwitchBackend setFeaturesReply(storedSwitch.getFeaturesReply(sw.getOFFactory()));
if (!key.equals(storedSwitch.getFeaturesReply(sw.getOFFactory()).getDatapathId())) {
log.error("Inconsistent DPIDs from switch sync store: " +
"key is {} but sw.getId() says {}. Ignoring",
key.toString(), sw.getId());
continue;
}
switchAddedToStore(sw);
}
}
示例8: getValue
import org.sdnplatform.sync.Versioned; //导入方法依赖的package包/类
@Override
public V getValue(K key, V defaultValue) throws SyncException {
Versioned<V> val = get(key);
if (val == null || val.getValue() == null) return defaultValue;
return val.getValue();
}
示例9: testConsolitateStore
import org.sdnplatform.sync.Versioned; //导入方法依赖的package包/类
@Test
public void testConsolitateStore() throws Exception {
int syncStoreInternalMs = 0;
ITopologyService mockTopology = makeMockTopologyAllPortsAp();
replay(mockTopology);
deviceManager.topology = mockTopology;
// We want an EntityClassifier that has switch/port as key fields
deviceManager.entityClassifier = new MockEntityClassifier();
deviceManager.setSyncStoreWriteInterval(syncStoreInternalMs);
// Add Device1 with two entities to store and let device manager
// learn
Entity e1a = new Entity(MacAddress.of(1L), null, null, DatapathId.of(4L), OFPort.of(5), new Date(1000));
Entity e1b = new Entity(MacAddress.of(1L), null, IPv4Address.of(3), DatapathId.of(4L), OFPort.of(5), new Date(2000));
Device d1 = deviceManager.learnDeviceByEntity(e1a);
deviceManager.learnDeviceByEntity(e1b);
String dev1Key = DeviceSyncRepresentation.computeKey(d1);
// Add a second device to the store but do NOT add to device manager
Entity e2 = new Entity(MacAddress.of(2L), null, null, DatapathId.of(5L), OFPort.of(5), new Date());
Device d2 = deviceManager.allocateDevice(42L, e2,
DefaultEntityClassifier.entityClass);
DeviceSyncRepresentation dsr = new DeviceSyncRepresentation(d2);
storeClient.put(dsr.getKey(), dsr);
String dev2Key = DeviceSyncRepresentation.computeKey(d2);
// Make sure we have two devices in the store
List<DeviceSyncRepresentation> entries = getEntriesFromStore();
assertEquals(2, entries.size());
deviceManager.scheduleConsolidateStoreNow();
Thread.sleep(25); // give the scheduler time to run the task
// We should still have two entries, however one of them will be a
// tombstone
entries = getEntriesFromStore();
assertEquals(2, entries.size());
// Device 1 should still be in store
Versioned<DeviceSyncRepresentation> versioned =
storeClient.get(dev1Key);
dsr = versioned.getValue();
assertNotNull(dsr);
assertEquals(2, dsr.getEntities().size());
assertEntityEquals(e1a, dsr.getEntities().get(0));
assertEntityEquals(e1b, dsr.getEntities().get(1));
// Device2 should be gone
versioned = storeClient.get(dev2Key);
assertNull(versioned.getValue());
// Run consolitate again. This time we check that tombstones in
// the store are handled correctly
deviceManager.scheduleConsolidateStoreNow();
Thread.sleep(25); // give the scheduler time to run the task
// Now write a device to the store that doesn't have any switch-port
// it should be removed
Entity e3 = new Entity(MacAddress.of(3L), null, null, null, null, null);
dsr.setKey("Device3");
dsr.setEntities(Collections.singletonList(new SyncEntity(e3)));
storeClient.put(dsr.getKey(), dsr);
// Run consolitate again. This time we check that tombstones in
// the store are handled correctly
deviceManager.scheduleConsolidateStoreNow();
Thread.sleep(25); // give the scheduler time to run the task
versioned = storeClient.get("Device3");
assertNull(versioned.getValue());
}
示例10: testConsolitateStore
import org.sdnplatform.sync.Versioned; //导入方法依赖的package包/类
@Test
public void testConsolitateStore() throws Exception {
int syncStoreInternalMs = 0;
ITopologyService mockTopology = makeMockTopologyAllPortsAp();
replay(mockTopology);
deviceManager.topology = mockTopology;
// We want an EntityClassifier that has switch/port as key fields
deviceManager.entityClassifier = new MockEntityClassifier();
deviceManager.setSyncStoreWriteInterval(syncStoreInternalMs);
// Add Device1 with two entities to store and let device manager
// learn
Entity e1a = new Entity(MacAddress.of(1L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(4L), OFPort.of(5), new Date(1000));
Entity e1b = new Entity(MacAddress.of(1L), VlanVid.ZERO, IPv4Address.of(3), IPv6Address.NONE, DatapathId.of(4L), OFPort.of(5), new Date(2000));
Device d1 = deviceManager.learnDeviceByEntity(e1a);
deviceManager.learnDeviceByEntity(e1b);
String dev1Key = DeviceSyncRepresentation.computeKey(d1);
// Add a second device to the store but do NOT add to device manager
Entity e2 = new Entity(MacAddress.of(2L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(5L), OFPort.of(5), new Date());
Device d2 = deviceManager.allocateDevice(42L, e2,
DefaultEntityClassifier.entityClass);
DeviceSyncRepresentation dsr = new DeviceSyncRepresentation(d2);
storeClient.put(dsr.getKey(), dsr);
String dev2Key = DeviceSyncRepresentation.computeKey(d2);
// Make sure we have two devices in the store
List<DeviceSyncRepresentation> entries = getEntriesFromStore();
assertEquals(2, entries.size());
deviceManager.scheduleConsolidateStoreNow();
Thread.sleep(25); // give the scheduler time to run the task
// We should still have two entries, however one of them will be a
// tombstone
entries = getEntriesFromStore();
assertEquals(2, entries.size());
// Device 1 should still be in store
Versioned<DeviceSyncRepresentation> versioned =
storeClient.get(dev1Key);
dsr = versioned.getValue();
assertNotNull(dsr);
assertEquals(2, dsr.getEntities().size());
assertEntityEquals(e1a, dsr.getEntities().get(0));
assertEntityEquals(e1b, dsr.getEntities().get(1));
// Device2 should be gone
versioned = storeClient.get(dev2Key);
assertNull(versioned.getValue());
// Run consolitate again. This time we check that tombstones in
// the store are handled correctly
deviceManager.scheduleConsolidateStoreNow();
Thread.sleep(25); // give the scheduler time to run the task
// Now write a device to the store that doesn't have any switch-port
// it should be removed
Entity e3 = new Entity(MacAddress.of(3L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
dsr.setKey("Device3");
dsr.setEntities(Collections.singletonList(new SyncEntity(e3)));
storeClient.put(dsr.getKey(), dsr);
// Run consolitate again. This time we check that tombstones in
// the store are handled correctly
deviceManager.scheduleConsolidateStoreNow();
Thread.sleep(25); // give the scheduler time to run the task
versioned = storeClient.get("Device3");
assertNull(versioned.getValue());
}