public class FreeMemoryProcessor extends RequestChainProcessor {
private static transient Logger log = LoggerFactory.getLogger(FreeMemoryProcessor.class.getName());
protected boolean processRequest() throws Exception {
MemoryProfiler memoryProfiler = MemoryProfiler.lookup();
if (memoryProfiler.isLowMemory()) {
log.warn("Memory is running low ...");
memoryProfiler.freeMemory();
if (memoryProfiler.isLowMemory()) {
getControllerStatus().setResponse(new SendErrorResponse(503));
getControllerStatus().consumeURIPart(getControllerStatus().getURIToBeConsumed());
log.error("Memory is so low that the request had to be canceled - 503 sent. Consider increasing the JVM memory.");
return false;
}