本文整理汇总了Java中org.sdnplatform.sync.internal.store.IStorageEngine.put方法的典型用法代码示例。如果您正苦于以下问题:Java IStorageEngine.put方法的具体用法?Java IStorageEngine.put怎么用?Java IStorageEngine.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sdnplatform.sync.internal.store.IStorageEngine
的用法示例。
在下文中一共展示了IStorageEngine.put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPruneOnWrite
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Test
public void testPruneOnWrite() throws SyncException {
IStorageEngine<ByteArray, byte[]> engine = getStorageEngine();
Versioned<byte[]> v1 = new Versioned<byte[]>(new byte[] { 1 }, TUtils.getClock(1));
Versioned<byte[]> v2 = new Versioned<byte[]>(new byte[] { 2 }, TUtils.getClock(2));
Versioned<byte[]> v3 = new Versioned<byte[]>(new byte[] { 3 }, TUtils.getClock(1, 2));
ByteArray key = new ByteArray((byte) 3);
engine.put(key, v1);
engine.put(key, v2);
assertEquals(2, engine.get(key).size());
engine.put(key, v3);
assertEquals(1, engine.get(key).size());
}
示例2: testTruncate
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Test
public void testTruncate() throws Exception {
IStorageEngine<ByteArray, byte[]> engine = getStorageEngine();
Versioned<byte[]> v1 = new Versioned<byte[]>(new byte[] { 1 });
Versioned<byte[]> v2 = new Versioned<byte[]>(new byte[] { 2 });
Versioned<byte[]> v3 = new Versioned<byte[]>(new byte[] { 3 });
ByteArray key1 = new ByteArray((byte) 3);
ByteArray key2 = new ByteArray((byte) 4);
ByteArray key3 = new ByteArray((byte) 5);
engine.put(key1, v1);
engine.put(key2, v2);
engine.put(key3, v3);
engine.truncate();
IClosableIterator<Entry<ByteArray, List<Versioned<byte[]>>>> it = null;
try {
it = engine.entries();
while(it.hasNext()) {
fail("There shouldn't be any entries in this store.");
}
} finally {
if(it != null) {
it.close();
}
}
}
示例3: handleDeleteRequest
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Override
protected void handleDeleteRequest(DeleteRequestMessage request,
Channel channel) {
try {
String storeName = request.getStoreName();
IStorageEngine<ByteArray, byte[]> store =
syncManager.getRawStore(storeName);
ByteArray key = new ByteArray(request.getKey());
VectorClock newclock;
if (request.isSetVersion()) {
newclock = TProtocolUtil.getVersion(request.getVersion());
} else {
newclock = new VectorClock();
List<IVersion> versions = store.getVersions(key);
for (IVersion v : versions) {
newclock = newclock.merge((VectorClock)v);
}
}
newclock =
newclock.incremented(rpcService.syncManager.getLocalNodeId(),
System.currentTimeMillis());
Versioned<byte[]> value = Versioned.value(null, newclock);
store.put(key, value);
DeleteResponseMessage m = new DeleteResponseMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(request.getHeader().getTransactionId());
m.setHeader(header);
SyncMessage bsm =
new SyncMessage(MessageType.DELETE_RESPONSE);
bsm.setDeleteResponse(m);
channel.write(bsm);
} catch (Exception e) {
channel.write(getError(request.getHeader().getTransactionId(), e,
MessageType.DELETE_REQUEST));
}
}
示例4: handlePutRequest
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Override
protected void handlePutRequest(PutRequestMessage request,
Channel channel) {
String storeName = request.getStoreName();
try {
IStorageEngine<ByteArray, byte[]> store =
syncManager.getRawStore(storeName);
ByteArray key = new ByteArray(request.getKey());
Versioned<byte[]> value = null;
if (request.isSetVersionedValue()) {
value = TProtocolUtil.
getVersionedValued(request.getVersionedValue());
value.increment(syncManager.getLocalNodeId(),
System.currentTimeMillis());
} else if (request.isSetValue()) {
byte[] rvalue = request.getValue();
List<IVersion> versions = store.getVersions(key);
VectorClock newclock = new VectorClock();
for (IVersion v : versions) {
newclock = newclock.merge((VectorClock)v);
}
newclock = newclock.incremented(syncManager.getLocalNodeId(),
System.currentTimeMillis());
value = Versioned.value(rvalue, newclock);
} else {
throw new SyncException("No value specified for put");
}
store.put(key, value);
PutResponseMessage m = new PutResponseMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(request.getHeader().getTransactionId());
m.setHeader(header);
SyncMessage bsm = new SyncMessage(MessageType.PUT_RESPONSE);
bsm.setPutResponse(m);
channel.writeAndFlush(bsm);
} catch (Exception e) {
channel.writeAndFlush(getError(request.getHeader().getTransactionId(), e,
MessageType.PUT_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());
}
示例6: handlePutRequest
import org.sdnplatform.sync.internal.store.IStorageEngine; //导入方法依赖的package包/类
@Override
protected void handlePutRequest(PutRequestMessage request,
Channel channel) {
String storeName = request.getStoreName();
try {
IStorageEngine<ByteArray, byte[]> store =
syncManager.getRawStore(storeName);
ByteArray key = new ByteArray(request.getKey());
Versioned<byte[]> value = null;
if (request.isSetVersionedValue()) {
value = TProtocolUtil.
getVersionedValued(request.getVersionedValue());
value.increment(syncManager.getLocalNodeId(),
System.currentTimeMillis());
} else if (request.isSetValue()) {
byte[] rvalue = request.getValue();
List<IVersion> versions = store.getVersions(key);
VectorClock newclock = new VectorClock();
for (IVersion v : versions) {
newclock = newclock.merge((VectorClock)v);
}
newclock = newclock.incremented(syncManager.getLocalNodeId(),
System.currentTimeMillis());
value = Versioned.value(rvalue, newclock);
} else {
throw new SyncException("No value specified for put");
}
store.put(key, value);
PutResponseMessage m = new PutResponseMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(request.getHeader().getTransactionId());
m.setHeader(header);
SyncMessage bsm = new SyncMessage(MessageType.PUT_RESPONSE);
bsm.setPutResponse(m);
channel.write(bsm);
} catch (Exception e) {
channel.write(getError(request.getHeader().getTransactionId(), e,
MessageType.PUT_REQUEST));
}
}