Fix error from flushing on different thread

This commit is contained in:
Jesse Boyd 2016-09-24 14:41:33 +10:00
parent d4fd374caa
commit d61c21f60e
2 changed files with 78 additions and 70 deletions

View File

@ -134,33 +134,35 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
@Override @Override
public boolean flush() { public boolean flush() {
super.flush(); synchronized (this) {
boolean flushed = osBD != null || osNBTF != null || osNBTT != null && osENTCF != null || osENTCT != null; super.flush();
try { boolean flushed = osBD != null || osNBTF != null || osNBTT != null && osENTCF != null || osENTCT != null;
if (osBD != null) { try {
osBD.close(); if (osBD != null) {
osBD = null; osBD.close();
osBD = null;
}
if (osNBTF != null) {
osNBTF.close();
osNBTF = null;
}
if (osNBTT != null) {
osNBTT.close();
osNBTT = null;
}
if (osENTCF != null) {
osENTCF.close();
osENTCF = null;
}
if (osENTCT != null) {
osENTCT.close();
osENTCT = null;
}
} catch (Exception e) {
MainUtil.handleError(e);
} }
if (osNBTF != null) { return flushed;
osNBTF.close();
osNBTF = null;
}
if (osNBTT != null) {
osNBTT.close();
osNBTT = null;
}
if (osENTCF != null) {
osENTCF.close();
osENTCF = null;
}
if (osENTCT != null) {
osENTCT.close();
osENTCT = null;
}
} catch (Exception e) {
MainUtil.handleError(e);
} }
return flushed;
} }
@Override @Override
@ -199,11 +201,13 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
if (osBD != null) { if (osBD != null) {
return osBD; return osBD;
} }
bdFile.getParentFile().mkdirs(); synchronized (this) {
bdFile.createNewFile(); bdFile.getParentFile().mkdirs();
osBD = getCompressedOS(new FileOutputStream(bdFile)); bdFile.createNewFile();
writeHeader(osBD, x, y, z); osBD = getCompressedOS(new FileOutputStream(bdFile));
return osBD; writeHeader(osBD, x, y, z);
return osBD;
}
} }
@Override @Override

View File

@ -48,42 +48,44 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
@Override @Override
public boolean flush() { public boolean flush() {
super.flush(); synchronized (this) {
try { super.flush();
if (idsStream != null) { try {
idsStreamZip.close(); if (idsStream != null) {
size = idsStream.getSize(); idsStreamZip.close();
ids = idsStream.toByteArrays(); size = idsStream.getSize();
idsStream = null; ids = idsStream.toByteArrays();
idsStreamZip = null; idsStream = null;
idsStreamZip = null;
}
if (entCStream != null) {
entCStreamZip.close();
entC = entCStream.toByteArrays();
entCStream = null;
entCStreamZip = null;
}
if (entRStream != null) {
entRStreamZip.close();
entR = entRStream.toByteArrays();
entRStream = null;
entRStreamZip = null;
}
if (tileCStream != null) {
tileCStreamZip.close();
tileC = tileCStream.toByteArrays();
tileCStream = null;
tileCStreamZip = null;
}
if (tileRStream != null) {
tileRStreamZip.close();
tileR = tileRStream.toByteArrays();
tileRStream = null;
tileRStreamZip = null;
}
return true;
} catch (IOException e) {
MainUtil.handleError(e);
} }
if (entCStream != null) {
entCStreamZip.close();
entC = entCStream.toByteArrays();
entCStream = null;
entCStreamZip = null;
}
if (entRStream != null) {
entRStreamZip.close();
entR = entRStream.toByteArrays();
entRStream = null;
entRStreamZip = null;
}
if (tileCStream != null) {
tileCStreamZip.close();
tileC = tileCStream.toByteArrays();
tileCStream = null;
tileCStreamZip = null;
}
if (tileRStream != null) {
tileRStreamZip.close();
tileR = tileRStream.toByteArrays();
tileRStream = null;
tileRStreamZip = null;
}
return true;
} catch (IOException e) {
MainUtil.handleError(e);
} }
return false; return false;
} }
@ -110,11 +112,13 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
if (idsStreamZip != null) { if (idsStreamZip != null) {
return idsStreamZip; return idsStreamZip;
} }
setOrigin(x, z); synchronized (this) {
idsStream = new FastByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE); setOrigin(x, z);
idsStreamZip = getCompressedOS(idsStream); idsStream = new FastByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE);
writeHeader(idsStreamZip, x, y, z); idsStreamZip = getCompressedOS(idsStream);
return idsStreamZip; writeHeader(idsStreamZip, x, y, z);
return idsStreamZip;
}
} }
@Override @Override