Skip to content

Commit

Permalink
Read backup output async
Browse files Browse the repository at this point in the history
  • Loading branch information
snowleo committed Jan 25, 2014
1 parent 32b118d commit 52c3169
Showing 1 changed file with 57 additions and 45 deletions.
102 changes: 57 additions & 45 deletions Essentials/src/com/earth2me/essentials/Backup.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,65 +91,77 @@ public void run()
server.dispatchCommand(cs, "save-all");
server.dispatchCommand(cs, "save-off");

ess.runTaskAsynchronously(
new Runnable()
ess.runTaskAsynchronously(new Runnable()
{
@Override
public void run()
{
try
{
@Override
public void run()
final ProcessBuilder childBuilder = new ProcessBuilder(command);
childBuilder.redirectErrorStream(true);
childBuilder.directory(ess.getDataFolder().getParentFile().getParentFile());
final Process child = childBuilder.start();
ess.runTaskAsynchronously(new Runnable()
{
try
@Override
public void run()
{
final ProcessBuilder childBuilder = new ProcessBuilder(command);
childBuilder.redirectErrorStream(true);
childBuilder.directory(ess.getDataFolder().getParentFile().getParentFile());
final Process child = childBuilder.start();
final BufferedReader reader = new BufferedReader(new InputStreamReader(child.getInputStream()));
try
{
child.waitFor();
String line;
do
final BufferedReader reader = new BufferedReader(new InputStreamReader(child.getInputStream()));
try
{
line = reader.readLine();
if (line != null)
String line;
do
{
LOGGER.log(Level.INFO, line);
line = reader.readLine();
if (line != null)
{
LOGGER.log(Level.INFO, line);
}
}
while (line != null);
}
finally
{
reader.close();
}
while (line != null);
}
finally
catch (IOException ex)
{
reader.close();
LOGGER.log(Level.SEVERE, null, ex);
}
}
catch (InterruptedException ex)
{
LOGGER.log(Level.SEVERE, null, ex);
}
catch (IOException ex)
{
LOGGER.log(Level.SEVERE, null, ex);
}
finally
});
child.waitFor();
}
catch (InterruptedException ex)
{
LOGGER.log(Level.SEVERE, null, ex);
}
catch (IOException ex)
{
LOGGER.log(Level.SEVERE, null, ex);
}
finally
{
ess.scheduleSyncDelayedTask(new Runnable()
{
@Override
public void run()
{
ess.scheduleSyncDelayedTask(
new Runnable()
{
@Override
public void run()
{
server.dispatchCommand(cs, "save-on");
if (server.getOnlinePlayers().length == 0)
{
stopTask();
}
active = false;
LOGGER.log(Level.INFO, _("backupFinished"));
}
});
server.dispatchCommand(cs, "save-on");
if (server.getOnlinePlayers().length == 0)
{
stopTask();
}
active = false;
LOGGER.log(Level.INFO, _("backupFinished"));
}
}
});
});
}
}
});
}
}

0 comments on commit 52c3169

Please sign in to comment.