本文整理汇总了Java中org.h2.mvstore.MVMap.get方法的典型用法代码示例。如果您正苦于以下问题:Java MVMap.get方法的具体用法?Java MVMap.get怎么用?Java MVMap.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.mvstore.MVMap
的用法示例。
在下文中一共展示了MVMap.get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verify
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void verify() {
MVStore s;
MVMap<Integer, byte[]> m;
FileUtils.delete(fileName);
s = new MVStore.Builder().
fileName(fileName).open();
m = s.openMap("data");
for (int i = 0; i < 100; i++) {
byte[] x = m.get(i);
if (x == null) {
break;
}
assertEquals(i * 100, x.length);
}
s.close();
}
示例2: openSecurely
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
static MVStore openSecurely(MVStore.Builder builder, String userId, String password) {
MVStore store = builder.open();
if (!isNullOrEmpty(password) && !isNullOrEmpty(userId)) {
if (!store.hasMap(USER_MAP)) {
throw new SecurityException(NO_USER_MAP_FOUND);
}
MVMap<String, UserCredential> userMap = store.openMap(USER_MAP);
UserCredential userCredential = userMap.get(userId);
if (userCredential != null) {
byte[] salt = userCredential.getPasswordSalt();
byte[] expectedHash = userCredential.getPasswordHash();
if (!isExpectedPassword(password.toCharArray(), salt, expectedHash)) {
throw new SecurityException(INVALID_USER_PASSWORD);
}
} else {
throw new SecurityException(NULL_USER_CREDENTIAL);
}
} else {
if (store.hasMap(USER_MAP)) {
throw new SecurityException(USER_MAP_SHOULD_NOT_EXISTS);
}
}
return store;
}
示例3: testInterruptReopen
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testInterruptReopen() throws Exception {
String fileName = "retry:nio:" + getBaseDir() + "/testInterruptReopen.h3";
FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder().
fileName(fileName).
cacheSize(0).
open();
final Thread mainThread = Thread.currentThread();
Task task = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
mainThread.interrupt();
Thread.sleep(10);
}
}
};
try {
MVMap<Integer, byte[]> map = s.openMap("data");
task.execute();
for (int i = 0; i < 1000 && !task.isFinished(); i++) {
map.get(i % 1000);
map.put(i % 1000, new byte[1024]);
s.commit();
}
} finally {
task.get();
s.close();
}
}
示例4: testConcurrentChangeAndCompact
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testConcurrentChangeAndCompact() throws InterruptedException {
String fileName = "memFS:testConcurrentChangeAndBackgroundCompact";
FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder().fileName(
fileName).
pageSplitSize(10).
autoCommitDisabled().open();
s.setRetentionTime(10000);
Task task = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
s.compact(100, 1024 * 1024);
}
}
};
task.execute();
Task task2 = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
s.compact(100, 1024 * 1024);
}
}
};
task2.execute();
Thread.sleep(1);
for (int i = 0; !task.isFinished() && !task2.isFinished() && i < 1000; i++) {
MVMap<Integer, Integer> map = s.openMap("d" + (i % 3));
// MVMap<Integer, Integer> map = s.openMap("d" + (i % 3),
// new MVMapConcurrent.Builder<Integer, Integer>());
map.put(0, i);
map.get(0);
s.commit();
}
task.get();
task2.get();
s.close();
}
示例5: testCacheSize
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testCacheSize() {
String fileName = getBaseDir() + "/testCacheSize.h3";
MVStore s;
MVMap<Integer, String> map;
s = new MVStore.Builder().
fileName(fileName).
autoCommitDisabled().
compress().open();
map = s.openMap("test");
// add 10 MB of data
for (int i = 0; i < 1024; i++) {
map.put(i, new String(new char[10240]));
}
s.close();
int[] expectedReadsForCacheSize = {
3407, 2590, 1924, 1440, 1111, 956, 918
};
for (int cacheSize = 0; cacheSize <= 6; cacheSize += 4) {
int cacheMB = 1 + 3 * cacheSize;
s = new MVStore.Builder().
fileName(fileName).
cacheSize(cacheMB).open();
assertEquals(cacheMB, s.getCacheSize());
map = s.openMap("test");
for (int i = 0; i < 1024; i += 128) {
for (int j = 0; j < i; j++) {
String x = map.get(j);
assertEquals(10240, x.length());
}
}
long readCount = s.getFileStore().getReadCount();
int expected = expectedReadsForCacheSize[cacheSize];
assertTrue("reads: " + readCount + " expected: " + expected,
Math.abs(100 - (100 * expected / readCount)) < 5);
s.close();
}
}
示例6: getWcaResults
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
@Override
public OnlineWorkflowWcaResults getWcaResults(String workflowId) {
Objects.requireNonNull(workflowId, "workflow id is null");
LOGGER.info("Getting WCA results of wf {}", workflowId);
if (isWorkflowStored(workflowId)) {
MVStore wfMVStore = getStore(workflowId);
if (wfMVStore.hasMap(STORED_WCA_RESULTS_MAP_NAME)) {
MVMap<String, String> storedRulesResultsMap = wfMVStore.openMap(STORED_WCA_RESULTS_MAP_NAME, mapBuilder);
// create workflow rules results
OnlineWorkflowWcaResultsImpl wfWcaResults = new OnlineWorkflowWcaResultsImpl(
workflowId,
TimeHorizon.valueOf(storedRulesResultsMap.get(STORED_RESULTS_TIMEHORIZON_KEY)));
// add classification of contingencies in clusters
MVMap<String, String> storedClustersMap = wfMVStore.openMap(STORED_WCA_RESULTS_CLUSTERS_MAP_NAME, mapBuilder);
MVMap<String, String> storedCausesMap = wfMVStore.openMap(STORED_WCA_RESULTS_CAUSES_MAP_NAME, mapBuilder);
for (String contingencyId : storedClustersMap.keySet()) {
String cause = storedCausesMap.get(contingencyId);
wfWcaResults.addContingencyWithCluster(contingencyId,
Integer.valueOf(storedClustersMap.get(contingencyId)),
cause != null ? Arrays.asList(cause) : null);
}
return wfWcaResults;
} else {
LOGGER.warn("No WCA results of wf {} stored in online db", workflowId);
return null;
}
} else {
LOGGER.warn("No data about wf {}", workflowId);
return null;
}
}
示例7: commit
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
/**
* Commit a transaction.
*
* @param t the transaction
* @param maxLogId the last log id
*/
void commit(Transaction t, long maxLogId) {
if (store.isClosed()) {
return;
}
// TODO could synchronize on blocks (100 at a time or so)
synchronized (undoLog) {
t.setStatus(Transaction.STATUS_COMMITTING);
for (long logId = 0; logId < maxLogId; logId++) {
Long undoKey = getOperationId(t.getId(), logId);
Object[] op = undoLog.get(undoKey);
if (op == null) {
// partially committed: load next
undoKey = undoLog.ceilingKey(undoKey);
if (undoKey == null ||
getTransactionId(undoKey) != t.getId()) {
break;
}
logId = getLogId(undoKey) - 1;
continue;
}
int mapId = (Integer) op[0];
MVMap<Object, VersionedValue> map = openMap(mapId);
if (map == null) {
// map was later removed
} else {
Object key = op[1];
VersionedValue value = map.get(key);
if (value == null) {
// nothing to do
} else if (value.value == null) {
// remove the value
map.remove(key);
} else {
VersionedValue v2 = new VersionedValue();
v2.value = value.value;
map.put(key, v2);
}
}
undoLog.remove(undoKey);
}
}
endTransaction(t);
}
示例8: testConcurrentMap
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
/**
* Test the concurrent map implementation.
*/
private void testConcurrentMap() throws InterruptedException {
final MVStore s = openStore(null);
final MVMap<Integer, Integer> m = s.openMap("data");
final int size = 20;
final Random rand = new Random(1);
Task task = new Task() {
@Override
public void call() throws Exception {
try {
while (!stop) {
if (rand.nextBoolean()) {
m.put(rand.nextInt(size), 1);
} else {
m.remove(rand.nextInt(size));
}
m.get(rand.nextInt(size));
m.firstKey();
m.lastKey();
m.ceilingKey(5);
m.floorKey(5);
m.higherKey(5);
m.lowerKey(5);
for (Iterator<Integer> it = m.keyIterator(null);
it.hasNext();) {
it.next();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
task.execute();
Thread.sleep(1);
for (int j = 0; j < 100; j++) {
for (int i = 0; i < 100; i++) {
if (rand.nextBoolean()) {
m.put(rand.nextInt(size), 2);
} else {
m.remove(rand.nextInt(size));
}
m.get(rand.nextInt(size));
}
s.commit();
Thread.sleep(1);
}
task.get();
s.close();
}
示例9: testConcurrentOnlineBackup
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testConcurrentOnlineBackup() throws Exception {
String fileName = getBaseDir() + "/onlineBackup.h3";
String fileNameRestore = getBaseDir() + "/onlineRestore.h3";
final MVStore s = openStore(fileName);
final MVMap<Integer, byte[]> map = s.openMap("test");
final Random r = new Random();
Task t = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
for (int i = 0; i < 10; i++) {
map.put(i, new byte[100 * r.nextInt(100)]);
}
s.commit();
map.clear();
s.commit();
long len = s.getFileStore().size();
if (len > 1024 * 1024) {
// slow down writing a lot
Thread.sleep(200);
} else if (len > 20 * 1024) {
// slow down writing
Thread.sleep(20);
}
}
}
};
t.execute();
for (int i = 0; i < 10; i++) {
// System.out.println("test " + i);
s.setReuseSpace(false);
byte[] buff = readFileSlowly(s.getFileStore().getFile(),
s.getFileStore().size());
s.setReuseSpace(true);
FileOutputStream out = new FileOutputStream(fileNameRestore);
out.write(buff);
out.close();
MVStore s2 = openStore(fileNameRestore);
MVMap<Integer, byte[]> test = s2.openMap("test");
for (Integer k : test.keySet()) {
test.get(k);
}
s2.close();
// let it compact
Thread.sleep(10);
}
t.get();
s.close();
}
示例10: testRandom
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testRandom() {
String fileName = getBaseDir() + "/testRandom.h3";
FileUtils.delete(fileName);
MVStore s = openStore(fileName);
MVMap<Integer, Integer> m = s.openMap("data");
TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
Random r = new Random(1);
int operationCount = 1000;
int maxValue = 30;
Integer expected, got;
for (int i = 0; i < operationCount; i++) {
int k = r.nextInt(maxValue);
int v = r.nextInt();
boolean compareAll;
switch (r.nextInt(3)) {
case 0:
log(i + ": put " + k + " = " + v);
expected = map.put(k, v);
got = m.put(k, v);
if (expected == null) {
assertNull(got);
} else {
assertEquals(expected, got);
}
compareAll = true;
break;
case 1:
log(i + ": remove " + k);
expected = map.remove(k);
got = m.remove(k);
if (expected == null) {
assertNull(got);
} else {
assertEquals(expected, got);
}
compareAll = true;
break;
default:
Integer a = map.get(k);
Integer b = m.get(k);
if (a == null || b == null) {
assertTrue(a == b);
} else {
assertEquals(a.intValue(), b.intValue());
}
compareAll = false;
break;
}
if (compareAll) {
Iterator<Integer> it = m.keyIterator(null);
Iterator<Integer> itExpected = map.keySet().iterator();
while (itExpected.hasNext()) {
assertTrue(it.hasNext());
expected = itExpected.next();
got = it.next();
assertEquals(expected, got);
}
assertFalse(it.hasNext());
}
}
s.close();
}
示例11: getWorkflowParameters
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
@Override
public OnlineWorkflowParameters getWorkflowParameters(String workflowId) {
Objects.requireNonNull(workflowId, "workflow id is null");
LOGGER.info("Getting configuration parameters of wf {}", workflowId);
if (isWorkflowStored(workflowId)) {
MVStore wfMVStore = null;
try {
wfMVStore = isStoreOpen(workflowId) ? getStore(workflowId) : openStore(workflowId);
if (wfMVStore.hasMap(STORED_PARAMETERS_MAP_NAME)) {
MVMap<String, String> storedParametersMap = wfMVStore.openMap(STORED_PARAMETERS_MAP_NAME, mapBuilder);
DateTime baseCaseDate = DateTime.parse(storedParametersMap.get(STORED_PARAMETERS_BASECASE_KEY));
int states = Integer.parseInt(storedParametersMap.get(STORED_PARAMETERS_STATE_NUMBER_KEY));
String offlineWorkflowId = storedParametersMap.get(STORED_PARAMETERS_OFFLINE_WF_ID_KEY);
TimeHorizon timeHorizon = TimeHorizon.fromName(storedParametersMap.get(STORED_RESULTS_TIMEHORIZON_KEY));
Interval histoInterval = Interval.parse(storedParametersMap.get(STORED_PARAMETERS_HISTO_INTERVAL_KEY));
String feAnalysisId = storedParametersMap.get(STORED_PARAMETERS_FEA_ID_KEY);
double rulesPurityThreshold = Double.parseDouble((storedParametersMap.get(STORED_PARAMETERS_RULES_PURITY_KEY) == null) ? "1" : storedParametersMap.get(STORED_PARAMETERS_RULES_PURITY_KEY));
boolean storeStates = Boolean.parseBoolean(storedParametersMap.get(STORED_PARAMETERS_STORE_STATES_KEY));
boolean analyseBasecase = Boolean.parseBoolean(storedParametersMap.get(STORED_PARAMETERS_ANALYSE_BASECASE_KEY));
boolean validation = Boolean.parseBoolean(storedParametersMap.get(STORED_PARAMETERS_VALIDATION_KEY));
Set<SecurityIndexType> securityIndexes = null;
if (storedParametersMap.containsKey(STORED_PARAMETERS_SECURITY_INDEXES_KEY)) {
securityIndexes = OnlineDbMVStoreUtils.jsonToIndexesTypes(storedParametersMap.get(STORED_PARAMETERS_SECURITY_INDEXES_KEY));
}
CaseType caseType = CaseType.valueOf(storedParametersMap.get(STORED_PARAMETERS_CASE_TYPE_KEY));
Set<Country> countries = OnlineDbMVStoreUtils.jsonToCountries(storedParametersMap.get(STORED_PARAMETERS_COUNTRIES_KEY));
boolean mergeOptimized = OnlineWorkflowParameters.DEFAULT_MERGE_OPTIMIZED;
if (storedParametersMap.containsKey(STORED_PARAMETERS_MERGE_OPTIMIZED_KEY)) {
mergeOptimized = Boolean.parseBoolean(storedParametersMap.get(STORED_PARAMETERS_MERGE_OPTIMIZED_KEY));
}
float limitReduction = OnlineWorkflowParameters.DEFAULT_LIMIT_REDUCTION;
if (storedParametersMap.containsKey(STORED_PARAMETERS_LIMIT_REDUCTION_KEY)) {
limitReduction = Float.parseFloat(storedParametersMap.get(STORED_PARAMETERS_LIMIT_REDUCTION_KEY));
}
boolean handleViolations = OnlineWorkflowParameters.DEFAULT_HANDLE_VIOLATIONS_IN_N;
if (storedParametersMap.containsKey(STORED_PARAMETERS_HANDLE_VIOLATIONS_KEY)) {
handleViolations = Boolean.parseBoolean(storedParametersMap.get(STORED_PARAMETERS_HANDLE_VIOLATIONS_KEY));
}
float constraintMargin = OnlineWorkflowParameters.DEFAULT_CONSTRAINT_MARGIN;
if (storedParametersMap.containsKey(STORED_PARAMETERS_CONSTRAINT_MARGIN_KEY)) {
constraintMargin = Float.parseFloat(storedParametersMap.get(STORED_PARAMETERS_CONSTRAINT_MARGIN_KEY));
}
OnlineWorkflowParameters onlineWfPars = new OnlineWorkflowParameters(baseCaseDate,
states,
histoInterval,
offlineWorkflowId,
timeHorizon,
feAnalysisId,
rulesPurityThreshold,
storeStates,
analyseBasecase,
validation,
securityIndexes,
caseType,
countries,
mergeOptimized,
limitReduction,
handleViolations,
constraintMargin);
if (storedParametersMap.containsKey(STORED_PARAMETERS_CASE_FILE_KEY)) {
onlineWfPars.setCaseFile(storedParametersMap.get(STORED_PARAMETERS_CASE_FILE_KEY));
}
return onlineWfPars;
} else {
LOGGER.warn("No configuration parameters of wf {} stored in online db", workflowId);
return null;
}
} finally {
if (wfMVStore != null && !isStoreOpen(workflowId)) {
wfMVStore.close();
}
}
} else {
LOGGER.warn("No data about wf {}", workflowId);
return null;
}
}