use of java.util.concurrent.atomic.AtomicIntegerArray in project uavstack by uavorg.
the class AtomicIntegerArrayCodec method deserialze.
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
if (parser.getLexer().token() == JSONToken.NULL) {
parser.getLexer().nextToken(JSONToken.COMMA);
return null;
}
JSONArray array = new JSONArray();
parser.parseArray(array);
AtomicIntegerArray atomicArray = new AtomicIntegerArray(array.size());
for (int i = 0; i < array.size(); ++i) {
atomicArray.set(i, array.getInteger(i));
}
return (T) atomicArray;
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project uavstack by uavorg.
the class AtomicIntegerArrayCodec method write.
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
SerializeWriter out = serializer.getWriter();
if (object == null) {
if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
out.write("[]");
} else {
out.writeNull();
}
return;
}
AtomicIntegerArray array = (AtomicIntegerArray) object;
int len = array.length();
out.append('[');
for (int i = 0; i < len; ++i) {
int val = array.get(i);
if (i != 0) {
out.write(',');
}
out.writeInt(val);
}
out.append(']');
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project CorfuDB by CorfuDB.
the class TXConflictScenariosTest method concurrentAbortTest.
public void concurrentAbortTest(boolean testInterleaved) throws Exception {
final int numThreads = PARAMETERS.CONCURRENCY_SOME;
final int numRecords = PARAMETERS.NUM_ITERATIONS_VERY_LOW;
numTasks = numThreads * numRecords;
long startTime = System.currentTimeMillis();
commitStatus = new AtomicIntegerArray(numTasks);
getAbortTestSM();
// invoke the execution engine
if (testInterleaved)
scheduleInterleaved(numThreads, numTasks);
else
scheduleThreaded(numThreads, numTasks);
int aborts = 0;
for (int i = 0; i < numTasks; i++) if (commitStatus.get(i) != COMMITVALUE)
aborts++;
// print stats..
calculateRequestsPerSecond("TPS", numRecords * numThreads, startTime);
calculateAbortRate(aborts, numRecords * numThreads);
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project CorfuDB by CorfuDB.
the class TXConflictScenariosTest method testNoWriteConflictSimple.
void testNoWriteConflictSimple() throws Exception {
final CorfuSharedCounter sharedCounter1 = instantiateCorfuObject(CorfuSharedCounter.class, "test" + 1);
final CorfuSharedCounter sharedCounter2 = instantiateCorfuObject(CorfuSharedCounter.class, "test" + 2);
commitStatus = new AtomicIntegerArray(2);
t(1, this::TXBegin);
t(2, this::TXBegin);
t(1, () -> {
sharedCounter1.setValue(OVERWRITE_ONCE);
});
t(2, () -> {
sharedCounter2.setValue(OVERWRITE_ONCE);
});
t(1, () -> sharedCounter1.getValue());
t(2, () -> sharedCounter2.getValue());
t(1, () -> sharedCounter2.getValue());
t(2, () -> sharedCounter1.getValue());
t(1, () -> {
sharedCounter1.setValue(OVERWRITE_TWICE);
});
t(2, () -> {
sharedCounter2.setValue(OVERWRITE_TWICE);
});
t(1, () -> sharedCounter1.getValue());
t(1, () -> sharedCounter2.getValue());
t(2, () -> sharedCounter2.getValue());
t(2, () -> sharedCounter1.getValue());
t(1, () -> {
try {
TXEnd();
commitStatus.set(0, COMMITVALUE);
} catch (TransactionAbortedException tae) {
// do nothing
}
});
t(2, () -> {
try {
TXEnd();
commitStatus.set(1, COMMITVALUE);
} catch (TransactionAbortedException tae) {
// do nothing
}
});
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project CorfuDB by CorfuDB.
the class AbstractTransactionContextTest method setupCounters.
/**
* build an array of shared counters for the test
*/
void setupCounters() {
numTasks = PARAMETERS.NUM_ITERATIONS_MODERATE;
sharedCounters = new ArrayList<>();
for (int i = 0; i < numTasks; i++) sharedCounters.add(i, instantiateCorfuObject(CorfuSharedCounter.class, "test" + i));
// initialize all shared counters
for (int i = 0; i < numTasks; i++) sharedCounters.get(i).setValue(INITIAL);
commitStatus = new AtomicIntegerArray(numTasks);
snapStatus = new AtomicIntegerArray(numTasks);
}
Aggregations