本文整理汇总了Java中org.sdnplatform.sync.IStoreClient类的典型用法代码示例。如果您正苦于以下问题:Java IStoreClient类的具体用法?Java IStoreClient怎么用?Java IStoreClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IStoreClient类属于org.sdnplatform.sync包,在下文中一共展示了IStoreClient类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startUp
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
@Override
public void startUp(FloodlightModuleContext context)
throws FloodlightModuleException {
try {
final IStoreClient<String, TortureValue> storeClient =
syncService.getStoreClient(SYNC_STORE_NAME,
String.class,
TortureValue.class);
for (int i = 0; i < numWorkers; i++) {
Thread thread = new Thread(new TortureWorker(storeClient, i),
"Torture-" + i);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
} catch (Exception e) {
throw new FloodlightModuleException(e);
}
}
示例2: testBasicGlobalSync
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
@Test
public void testBasicGlobalSync() throws Exception {
waitForFullMesh(2000);
ArrayList<IStoreClient<String, String>> clients =
new ArrayList<IStoreClient<String, String>>(syncManagers.length);
// write one value to each node's local interface
for (int i = 0; i < syncManagers.length; i++) {
IStoreClient<String, String> client =
syncManagers[i].getStoreClient("global",
String.class, String.class);
clients.add(client);
client.put("key" + i, ""+i);
}
// verify that we see all the values everywhere
for (int j = 0; j < clients.size(); j++) {
for (int i = 0; i < syncManagers.length; i++) {
waitForValue(clients.get(j), "key" + i, ""+i, 2000, "client"+j);
}
}
}
示例3: startUp
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
@Override
public void startUp(FloodlightModuleContext context)
throws FloodlightModuleException {
try {
final IStoreClient<String, TortureValue> storeClient =
syncService.getStoreClient(SYNC_STORE_NAME,
String.class,
TortureValue.class);
for (int i = 0; i < numWorkers; i++) {
Thread thread = new Thread(new TortureWorker(storeClient, i),
"Torture-" + i);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
} catch (Exception e) {
throw new FloodlightModuleException(e);
}
}
示例4: waitForValue
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
private String waitForValue(IStoreClient<String, String> uStoreClient,
String key,
long maxWait) throws Exception {
long start = System.nanoTime();
while (start + maxWait > System.nanoTime()) {
String v = uStoreClient.getValue(key);
if (v != null) {
return v;
}
Thread.sleep(100);
}
return null;
}
示例5: TortureWorker
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
public TortureWorker(IStoreClient<String, TortureValue> storeClient,
int workerId) {
super();
this.storeClient = storeClient;
this.workerId = workerId;
values = new ArrayList<TortureValue>();
for (int i = 0; i < keysPerWorker; i++) {
values.add(new TortureValue(workerId+":"+i, 0, true));
}
}
示例6: getStoreClient
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
@Override
public <K, V> IStoreClient<K, V>
getStoreClient(String storeName,
Class<K> keyClass,
Class<V> valueClass)
throws UnknownStoreException {
return getStoreClient(storeName, keyClass, null,
valueClass, null, null);
}
示例7: testBasicOneNode
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
@Test
public void testBasicOneNode() throws Exception {
AbstractSyncManager sync = syncManagers[0];
IStoreClient<Key, TBean> testClient =
sync.getStoreClient("global", Key.class, TBean.class);
Key k = new Key("com.bigswitch.bigsync.internal", "test");
TBean tb = new TBean("hello", 42);
TBean tb2 = new TBean("hello", 84);
TBean tb3 = new TBean("hello", 126);
assertNotNull(testClient.get(k));
assertNull(testClient.get(k).getValue());
testClient.put(k, tb);
Versioned<TBean> result = testClient.get(k);
assertEquals(result.getValue(), tb);
result.setValue(tb2);
testClient.put(k, result);
try {
result.setValue(tb3);
testClient.put(k, result);
fail("Should get ObsoleteVersionException");
} catch (ObsoleteVersionException e) {
// happy town
}
result = testClient.get(k);
assertEquals(tb2, result.getValue());
}
示例8: testIterator
import org.sdnplatform.sync.IStoreClient; //导入依赖的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);
}
示例9: waitForValue
import org.sdnplatform.sync.IStoreClient; //导入依赖的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;
}
示例10: testRemoveNode
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
@Test
public void testRemoveNode() throws Exception {
waitForFullMesh(2000);
IStoreClient<String, String> client0 =
syncManagers[0].getStoreClient("global",
String.class, String.class);
IStoreClient<String, String> client1 =
syncManagers[1].getStoreClient("global",
String.class, String.class);
IStoreClient<String, String> client2 =
syncManagers[2].getStoreClient("global",
String.class, String.class);
client0.put("key", "value");
waitForValue(client1, "key", "value", 2000, "client1");
nodes.remove(0);
nodeString = mapper.writeValueAsString(nodes);
SyncManager oldNode = syncManagers[0];
syncManagers = Arrays.copyOfRange(syncManagers, 1, 4);
moduleContexts = Arrays.copyOfRange(moduleContexts, 1, 4);
try {
for(int i = 0; i < syncManagers.length; i++) {
moduleContexts[i].addConfigParam(syncManagers[i],
"nodes", nodeString);
syncManagers[i].doUpdateConfiguration();
waitForConnection(syncManagers[i], (short)1, false, 2000);
}
} finally {
oldNode.shutdown();
}
waitForFullMesh(2000);
client1.put("newkey", "newvalue");
waitForValue(client2, "key", "value", 2000, "client4");
waitForValue(client2, "newkey", "newvalue", 2000, "client0");
}
示例11: testChangeNode
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
@Test
public void testChangeNode() throws Exception {
waitForFullMesh(2000);
IStoreClient<String, String> client0 =
syncManagers[0].getStoreClient("global",
String.class, String.class);
IStoreClient<String, String> client2 =
syncManagers[2].getStoreClient("global",
String.class, String.class);
client0.put("key", "value");
waitForValue(client2, "key", "value", 2000, "client2");
nodes.set(2, new Node("localhost", 50103, (short)3, (short)1));
nodeString = mapper.writeValueAsString(nodes);
for(int i = 0; i < syncManagers.length; i++) {
moduleContexts[i].addConfigParam(syncManagers[i],
"nodes", nodeString);
syncManagers[i].doUpdateConfiguration();
}
waitForFullMesh(2000);
waitForValue(client2, "key", "value", 2000, "client2");
client2 = syncManagers[2].getStoreClient("global",
String.class, String.class);
client0.put("key", "newvalue");
waitForValue(client2, "key", "newvalue", 2000, "client2");
}
示例12: testSimpleWritePerformance
import org.sdnplatform.sync.IStoreClient; //导入依赖的package包/类
/**
* Do a brain-dead performance test with one thread writing and waiting
* for the values on the other node. The result get printed to the log
*/
public void testSimpleWritePerformance(String store) throws Exception {
waitForFullMesh(5000);
final int count = 1000000;
IStoreClient<String, String> client0 =
syncManagers[0].getStoreClient(store,
String.class, String.class);
IStoreClient<String, String> client2 =
syncManagers[2].getStoreClient(store,
String.class, String.class);
long then = System.currentTimeMillis();
for (int i = 1; i <= count; i++) {
client0.put(""+i, ""+i);
}
long donewriting = System.currentTimeMillis();
waitForValue(client2, ""+count, null, count, "client2");
long now = System.currentTimeMillis();
logger.info("Simple write ({}): {} values in {}+/-100 " +
"millis ({} synced writes/s) ({} local writes/s)",
new Object[]{store, count, (now-then),
1000.0*count/(now-then),
1000.0*count/(donewriting-then)});
}