Shift remaining storage access call off of server thread

This commit is contained in:
Mike Primm 2020-05-26 22:34:00 -05:00
parent 366d3e5a5d
commit a67f50350a
3 changed files with 154 additions and 132 deletions

View File

@ -265,6 +265,8 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
sb.append("'\n }\n};\n");
byte[] outputBytes = sb.toString().getBytes(cs_utf8);
MapManager.scheduleDelayedJob(new Runnable() {
public void run() {
File f = new File(baseStandaloneDir, "config.js");
FileOutputStream fos = null;
try {
@ -281,6 +283,8 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
}
}
}
}, 0);
}
protected void writeConfiguration() {
JSONObject clientConfiguration = new JSONObject();
@ -369,30 +373,7 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
}
}
protected void handleWebChat() {
BufferInputStream bis = storage.getStandaloneFile("dynmap_webchat.json");
if (bis != null && lastTimestamp != 0) {
JSONArray jsonMsgs = null;
Reader inputFileReader = null;
try {
inputFileReader = new InputStreamReader(bis, cs_utf8);
jsonMsgs = (JSONArray) parser.parse(inputFileReader);
} catch (IOException ex) {
Log.severe("Exception while reading JSON-file.", ex);
} catch (ParseException ex) {
Log.severe("Exception while parsing JSON-file.", ex);
} finally {
if(inputFileReader != null) {
try {
inputFileReader.close();
} catch (IOException iox) {
}
inputFileReader = null;
}
}
if (jsonMsgs != null) {
private void processWebChat(JSONArray jsonMsgs) {
Iterator<?> iter = jsonMsgs.iterator();
boolean init_skip = (lastChatTimestamp == 0);
while (iter.hasNext()) {
@ -478,7 +459,44 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
}
}
}
protected void handleWebChat() {
MapManager.scheduleDelayedJob(new Runnable() {
public void run() {
BufferInputStream bis = storage.getStandaloneFile("dynmap_webchat.json");
if (bis != null && lastTimestamp != 0) {
JSONArray jsonMsgs = null;
Reader inputFileReader = null;
try {
inputFileReader = new InputStreamReader(bis, cs_utf8);
jsonMsgs = (JSONArray) parser.parse(inputFileReader);
} catch (IOException ex) {
Log.severe("Exception while reading JSON-file.", ex);
} catch (ParseException ex) {
Log.severe("Exception while parsing JSON-file.", ex);
} finally {
if(inputFileReader != null) {
try {
inputFileReader.close();
} catch (IOException iox) {
}
inputFileReader = null;
}
}
if (jsonMsgs != null) {
final JSONArray json = jsonMsgs;
// Process content on server thread
core.getServer().scheduleServerTask(new Runnable() {
@Override
public void run() {
processWebChat(json);
}
}, 0);
}
}
}
}, 0);
}
protected void handleRegister() {
if(core.pendingRegisters() == false)

View File

@ -395,6 +395,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
Log.severe("Error creating markers directory - " + api.markerdir.getPath());
}
}
MapManager.scheduleDelayedJob(new Runnable() {
public void run() {
/* Now publish marker files to the tiles directory */
for(MarkerIcon ico : api.getMarkerIcons()) {
api.publishMarkerIcon(ico);
@ -405,6 +407,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
core.events.addListener("worldactivated", api);
api.scheduleWriteJob(); /* Start write job */
}
}, 0);
return api;
}

View File

@ -2,7 +2,7 @@ arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
connection.project.dir=
connection.project.dir=..
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home