本文整理汇总了Java中org.sdnplatform.sync.internal.store.IStorageEngine.get方法的典型用法代码示例。如果您正苦于以下问题:Java IStorageEngine.get方法的具体用法?Java IStorageEngine.get怎么用?Java IStorageEngine.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sdnplatform.sync.internal.store.IStorageEngine
的用法示例。
在下文中一共展示了IStorageEngine.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleGetRequest
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Override
protected void handleGetRequest(GetRequestMessage request,
Channel channel) {
String storeName = request.getStoreName();
try {
IStorageEngine<ByteArray, byte[]> store =
syncManager.getRawStore(storeName);
GetResponseMessage m = new GetResponseMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(request.getHeader().getTransactionId());
m.setHeader(header);
List<Versioned<byte[]>> values =
store.get(new ByteArray(request.getKey()));
for (Versioned<byte[]> value : values) {
m.addToValues(TProtocolUtil.getTVersionedValue(value));
}
SyncMessage bsm = new SyncMessage(MessageType.GET_RESPONSE);
bsm.setGetResponse(m);
channel.writeAndFlush(bsm);
} catch (Exception e) {
channel.writeAndFlush(getError(request.getHeader().getTransactionId(), e,
MessageType.GET_REQUEST));
}
}
示例2: handleSyncRequest
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Override
protected void handleSyncRequest(SyncRequestMessage request,
Channel channel) {
rpcService.messageAcked(MessageType.SYNC_OFFER, getRemoteNodeId());
if (!request.isSetKeys()) return;
String storeName = request.getStore().getStoreName();
try {
IStorageEngine<ByteArray, byte[]> store =
syncManager.getRawStore(storeName);
SyncMessage bsm =
TProtocolUtil.getTSyncValueMessage(request.getStore());
SyncValueMessage svm = bsm.getSyncValue();
svm.setResponseTo(request.getHeader().getTransactionId());
svm.getHeader().setTransactionId(rpcService.getTransactionId());
for (ByteBuffer key : request.getKeys()) {
ByteArray keyArray = new ByteArray(key.array());
List<Versioned<byte[]>> values =
store.get(keyArray);
if (values == null || values.size() == 0) continue;
KeyedValues kv =
TProtocolUtil.getTKeyedValues(keyArray, values);
svm.addToValues(kv);
}
if (svm.isSetValues()) {
updateCounter(SyncManager.counterSentValues,
svm.getValuesSize());
rpcService.syncQueue.add(new NodeMessage(getRemoteNodeId(),
bsm));
}
} catch (Exception e) {
channel.writeAndFlush(getError(request.getHeader().getTransactionId(), e,
MessageType.SYNC_REQUEST));
}
}
示例3: handleGetRequest
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Override
protected void handleGetRequest(GetRequestMessage request,
Channel channel) {
String storeName = request.getStoreName();
try {
IStorageEngine<ByteArray, byte[]> store =
syncManager.getRawStore(storeName);
GetResponseMessage m = new GetResponseMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(request.getHeader().getTransactionId());
m.setHeader(header);
List<Versioned<byte[]>> values =
store.get(new ByteArray(request.getKey()));
for (Versioned<byte[]> value : values) {
m.addToValues(TProtocolUtil.getTVersionedValue(value));
}
SyncMessage bsm = new SyncMessage(MessageType.GET_RESPONSE);
bsm.setGetResponse(m);
channel.write(bsm);
} catch (Exception e) {
channel.write(getError(request.getHeader().getTransactionId(), e,
MessageType.GET_REQUEST));
}
}
示例4: handleSyncRequest
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Override
protected void handleSyncRequest(SyncRequestMessage request,
Channel channel) {
rpcService.messageAcked(MessageType.SYNC_OFFER, getRemoteNodeId());
if (!request.isSetKeys()) return;
String storeName = request.getStore().getStoreName();
try {
IStorageEngine<ByteArray, byte[]> store =
syncManager.getRawStore(storeName);
SyncMessage bsm =
TProtocolUtil.getTSyncValueMessage(request.getStore());
SyncValueMessage svm = bsm.getSyncValue();
svm.setResponseTo(request.getHeader().getTransactionId());
svm.getHeader().setTransactionId(rpcService.getTransactionId());
for (ByteBuffer key : request.getKeys()) {
ByteArray keyArray = new ByteArray(key.array());
List<Versioned<byte[]>> values =
store.get(keyArray);
if (values == null || values.size() == 0) continue;
KeyedValues kv =
TProtocolUtil.getTKeyedValues(keyArray, values);
svm.addToValues(kv);
}
if (svm.isSetValues()) {
updateCounter(SyncManager.counterSentValues,
svm.getValuesSize());
rpcService.syncQueue.add(new NodeMessage(getRemoteNodeId(),
bsm));
}
} catch (Exception e) {
channel.write(getError(request.getHeader().getTransactionId(), e,
MessageType.SYNC_REQUEST));
}
}
示例5: testCleanupTask
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Test
public void testCleanupTask() throws Exception {
IStorageEngine<ByteArray, byte[]> engine = getStorageEngine();
engine.setTombstoneInterval(500);
Versioned<byte[]> v1_1 = new Versioned<byte[]>(new byte[] { 1 }, TUtils.getClock(1));
Versioned<byte[]> v1_2 = new Versioned<byte[]>(null, TUtils.getClock(1, 1));
// add, update, delete
Versioned<byte[]> v2_1 = new Versioned<byte[]>(new byte[] { 1 }, TUtils.getClock(1));
Versioned<byte[]> v2_2 = new Versioned<byte[]>(new byte[] { 2 }, TUtils.getClock(1, 2));
Versioned<byte[]> v2_3 = new Versioned<byte[]>(null, TUtils.getClock(1, 2, 1));
// delete then add again
Versioned<byte[]> v3_1 = new Versioned<byte[]>(new byte[] { 1 }, TUtils.getClock(1));
Versioned<byte[]> v3_2 = new Versioned<byte[]>(null, TUtils.getClock(1, 2));
Versioned<byte[]> v3_3 = new Versioned<byte[]>(new byte[] { 2 }, TUtils.getClock(1, 2, 1));
// delete concurrent to update
Versioned<byte[]> v4_1 = new Versioned<byte[]>(new byte[] { 1 }, TUtils.getClock(1));
Versioned<byte[]> v4_2 = new Versioned<byte[]>(new byte[] { 2 }, TUtils.getClock(1, 2));
Versioned<byte[]> v4_3 = new Versioned<byte[]>(null, TUtils.getClock(1, 1));
ByteArray key1 = new ByteArray((byte) 3);
ByteArray key2 = new ByteArray((byte) 4);
ByteArray key3 = new ByteArray((byte) 5);
ByteArray key4 = new ByteArray((byte) 6);
engine.put(key1, v1_1);
assertEquals(1, engine.get(key1).size());
engine.put(key1, v1_2);
List<Versioned<byte[]>> r = engine.get(key1);
assertEquals(1, r.size());
assertNull(r.get(0).getValue());
engine.put(key2, v2_1);
engine.put(key2, v2_2);
engine.put(key2, v2_3);
engine.put(key3, v3_1);
engine.put(key3, v3_2);
engine.put(key4, v4_1);
engine.put(key4, v4_2);
engine.put(key4, v4_3);
engine.cleanupTask();
r = engine.get(key1);
assertEquals(1, r.size());
assertNull(r.get(0).getValue());
engine.put(key3, v3_3);
Thread.sleep(501);
engine.cleanupTask();
r = engine.get(key1);
assertEquals(0, r.size());
r = engine.get(key2);
assertEquals(0, r.size());
r = engine.get(key3);
assertEquals(1, r.size());
r = engine.get(key4);
assertEquals(2, r.size());
}