PC-951 Fix handler message task not being cancelled when closing report

This commit is contained in:
Keir Nellyer 2016-09-12 11:56:21 +01:00
parent 5e5cb3284a
commit a5e5be4329
3 changed files with 14 additions and 10 deletions

View File

@ -37,6 +37,7 @@ public class ReportHandlerTask extends BukkitRunnable
public void start(JavaPlugin plugin) public void start(JavaPlugin plugin)
{ {
runTaskTimer(plugin, 1L, 20L * 10); runTaskTimer(plugin, 1L, 20L * 10);
_report.cancelHandlerTask(); // cancel in case other task running
_report.setHandlerTask(this); _report.setHandlerTask(this);
} }

View File

@ -239,13 +239,12 @@ public class ReportManager
} }
report.setReportResult(reportResult); report.setReportResult(reportResult);
report.cancelHandlerTask();
CompletableFuture<Long> saveCompletableFuture = saveReport(report); CompletableFuture<Long> saveCompletableFuture = saveReport(report);
saveCompletableFuture.thenAccept(reportId -> saveCompletableFuture.thenAccept(reportId ->
{ {
_reportRepository.clearCache(reportId);
if (reportCloser != null) if (reportCloser != null)
{ {
if (reportResult.getType() == ReportResultType.ABUSIVE) if (reportResult.getType() == ReportResultType.ABUSIVE)
@ -296,6 +295,8 @@ public class ReportManager
}); });
}); });
} }
_reportRepository.clearCache(reportId);
}).exceptionally(throwable -> { }).exceptionally(throwable -> {
_plugin.getLogger().log(Level.SEVERE, "Post-report save failed.", throwable); _plugin.getLogger().log(Level.SEVERE, "Post-report save failed.", throwable);
return null; return null;
@ -632,14 +633,7 @@ public class ReportManager
if (reportOptional.isPresent()) if (reportOptional.isPresent())
{ {
Report report = reportOptional.get(); Report report = reportOptional.get();
Optional<ReportHandlerTask> handlerTaskOptional = report.getHandlerTask(); report.cancelHandlerTask();
if (handlerTaskOptional.isPresent())
{
ReportHandlerTask handlerTask = handlerTaskOptional.get();
handlerTask.cancel();
report.setHandlerTask(null);
}
} }
}); });

View File

@ -131,4 +131,13 @@ public class Report
{ {
_handlerTask = handlerTask; _handlerTask = handlerTask;
} }
public void cancelHandlerTask()
{
if (_handlerTask != null)
{
_handlerTask.cancel();
_handlerTask = null;
}
}
} }