Commit 69df5429 authored by Vincent van Beveren's avatar Vincent van Beveren

Added retries when reading in datasource, and more delays

parent 19e2a50f
......@@ -28,6 +28,8 @@ import org.luaj.vm2.LuaValue;
public abstract class DataSource {
private final static int MAX_RETRIES = 3;
private String _condition;
private static final Logger LOG = Logger.getLogger(DataSource.class.getSimpleName());
public final int start;
......@@ -88,11 +90,23 @@ public abstract class DataSource {
public synchronized byte[] read(DDMIContext ctx, int off, int len) {
byte[] b;
byte[] b = null;
if (!ctx.scratch.containsKey(key))
{
b = readMedia(ctx, start, end - start + 1);
//if (b == null) return new byte[len];
for (int retry = 0; retry < MAX_RETRIES; retry++)
{
try {
b = readMedia(ctx, start, end - start + 1);
break;
} catch (RuntimeException re) {
if (retry == MAX_RETRIES - 1) throw re;
try {
Thread.sleep(5);
} catch (InterruptedException ie) {
// ignore
}
}
}
if (b == null) return null;
ctx.scratch.put(key, b);
} else {
......@@ -130,10 +144,19 @@ public abstract class DataSource {
// With EEPROM, write in increments
for (int i = 0; i < data.length; i += 8)
{
writeMedia(ctx, off + i, Arrays.copyOfRange(data, i, i + 8));
try {
Thread.sleep(30);
} catch (InterruptedException e) {
for (int retry = 0; retry < MAX_RETRIES; retry++)
{
try {
writeMedia(ctx, off + i, Arrays.copyOfRange(data, i, i + 8));
break;
} catch (RuntimeException re) {
if (retry == MAX_RETRIES - 1) throw re;
try {
Thread.sleep(10);
} catch (InterruptedException ie) {
// ignore
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment