Move classes in algos which need map into maps, closes https://github.com/OpenHFT/Chronicle-Algorithms/issues/10

This commit is contained in:
Peter Lawrey
2020-09-18 17:03:09 +01:00
parent a78378343c
commit e4d7a50eee
17 changed files with 2480 additions and 0 deletions
@@ -0,0 +1,114 @@
package net.openhft.chronicle.map.locks;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.map.ChronicleMap;
import static net.openhft.chronicle.values.Values.newNativeReference;
class ReaderToo implements Runnable {
@Override
public void run() {
try {
String isoLevel = "READER_TOO";
long sleepMock = Long.parseLong("0");
long holdTime = Long.parseLong("20");
/**
* ben.cotton@rutgers.edu START
*/
ChronicleMap<String, BondVOInterface> chm =
DirtyReadTolerance.offHeap(
OS.TARGET + "/shm-OPERAND_CHRONICLE_MAP"
);
Double coupon = 0.00;
BondVOInterface bond = newNativeReference(BondVOInterface.class);
//BondVOInterface cslMock = newNativeReference(BondVOInterface.class); //mock'd
long stamp = 0;
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant ENTERING offHeapLock.readLock()"
);
ChronicleStampedLock offHeapLock =
new ChronicleStampedLock(
OS.TARGET + "/shm-"
+ "OPERAND_ChronicleStampedLock"
);
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant sleeping " + sleepMock + " seconds"
);
Thread.sleep(sleepMock * 1_000);
while ((stamp = offHeapLock.tryReadLock()) < 0) {
//Assert.assertEquals(Boolean.TRUE, false); // we failed!;
}
//Assert.assertEquals(Boolean.TRUE, true); // we passed
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant ENTERED offHeapLock.readLock() " +
" stamp=[" +
stamp +
"]"
);
try {
chm.acquireUsing("369604101", bond);
//chm.acquireUsing("Offender ", cslMock); //mock'd
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant calling chm.get('369604101').getCoupon()"
);
bond = chm.get("369604101");
coupon = bond.getCoupon();
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant coupon=[" + coupon + "] read."
);
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant sleeping " + holdTime + " seconds"
);
Thread.sleep(holdTime * 1_000);
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant awakening"
);
} finally {
offHeapLock.unlockRead(stamp);
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant offHeapLock.unlockRead(" +
stamp + ") completed."
);
}
/**
* ben.cotton@rutgers.edu END
*/
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant got() coupon=" +
coupon + " "
);
System.out.println(
"READER_TOO " +
" ,,@t=" + System.currentTimeMillis() +
" DirtyReadIntolerant COMMITTED"
);
chm.close();
offHeapLock.closeChronicle();
} catch (Exception throwables) {
throwables.printStackTrace();
}
}
}