SOLR-8476: Refactor and cleanup CoreAdminHandler

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1722788 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2016-01-04 05:41:31 +00:00
parent c54ef96f20
commit c9b7af0450
2 changed files with 14 additions and 21 deletions

View File

@ -289,41 +289,34 @@ public class CoreAdminHandler extends RequestHandlerBase {
} }
/** /**
* Helper method to add a task to a tracking map. * Helper method to add a task to a tracking type.
*/ */
void addTask(String map, TaskObject o, boolean limit) { void addTask(String type, TaskObject o, boolean limit) {
synchronized (getRequestStatusMap(map)) { synchronized (getRequestStatusMap(type)) {
if(limit && getRequestStatusMap(map).size() == MAX_TRACKED_REQUESTS) { if(limit && getRequestStatusMap(type).size() == MAX_TRACKED_REQUESTS) {
String key = getRequestStatusMap(map).entrySet().iterator().next().getKey(); String key = getRequestStatusMap(type).entrySet().iterator().next().getKey();
getRequestStatusMap(map).remove(key); getRequestStatusMap(type).remove(key);
} }
addTask(map, o); addTask(type, o);
} }
} }
void addTask(String map, TaskObject o) { private void addTask(String type, TaskObject o) {
synchronized (getRequestStatusMap(map)) { synchronized (getRequestStatusMap(type)) {
getRequestStatusMap(map).put(o.taskId, o); getRequestStatusMap(type).put(o.taskId, o);
} }
} }
/** /**
* Helper method to remove a task from a tracking map. * Helper method to remove a task from a tracking map.
*/ */
void removeTask(String map, String taskId) { private void removeTask(String map, String taskId) {
synchronized (getRequestStatusMap(map)) { synchronized (getRequestStatusMap(map)) {
getRequestStatusMap(map).remove(taskId); getRequestStatusMap(map).remove(taskId);
} }
} }
/**
* Helper method to check if a map contains a taskObject with the given taskId.
*/
boolean mapContainsTask(String map, String taskId) {
return getRequestStatusMap(map).containsKey(taskId);
}
/** /**
* Helper method to get a request status map given the name. * Helper method to get a request status map given the name.
*/ */

View File

@ -734,12 +734,12 @@ enum CoreAdminOperation {
String requestId = params.get(CoreAdminParams.REQUESTID); String requestId = params.get(CoreAdminParams.REQUESTID);
log.info("Checking request status for : " + requestId); log.info("Checking request status for : " + requestId);
if (callInfo.handler.mapContainsTask(RUNNING, requestId)) { if (callInfo.handler.getRequestStatusMap(RUNNING).containsKey(requestId)) {
callInfo.rsp.add(RESPONSE_STATUS, RUNNING); callInfo.rsp.add(RESPONSE_STATUS, RUNNING);
} else if (callInfo.handler.mapContainsTask(COMPLETED, requestId)) { } else if (callInfo.handler.getRequestStatusMap(COMPLETED).containsKey(requestId)) {
callInfo.rsp.add(RESPONSE_STATUS, COMPLETED); callInfo.rsp.add(RESPONSE_STATUS, COMPLETED);
callInfo.rsp.add(RESPONSE, callInfo.handler.getRequestStatusMap(COMPLETED).get(requestId).getRspObject()); callInfo.rsp.add(RESPONSE, callInfo.handler.getRequestStatusMap(COMPLETED).get(requestId).getRspObject());
} else if (callInfo.handler.mapContainsTask(FAILED, requestId)) { } else if (callInfo.handler.getRequestStatusMap(FAILED).containsKey(requestId)) {
callInfo.rsp.add(RESPONSE_STATUS, FAILED); callInfo.rsp.add(RESPONSE_STATUS, FAILED);
callInfo.rsp.add(RESPONSE, callInfo.handler.getRequestStatusMap(FAILED).get(requestId).getRspObject()); callInfo.rsp.add(RESPONSE, callInfo.handler.getRequestStatusMap(FAILED).get(requestId).getRspObject());
} else { } else {