changed task operations to print out name of operation on run

pull/1161/merge
Justin Richer 2017-03-14 17:39:44 -04:00
parent 72fd3c2b99
commit c42fe57367
4 changed files with 47 additions and 16 deletions

View File

@ -40,6 +40,11 @@ public abstract class AbstractPageOperationTemplate<T> {
* swallowed during execution default true.
*/
private boolean swallowExceptions = true;
/**
* String that is used for logging in final tallies.
*/
private String operationName = "";
/**
@ -47,11 +52,10 @@ public abstract class AbstractPageOperationTemplate<T> {
* maxPages and maxTime to DEFAULT_MAX_PAGES and
* DEFAULT_MAX_TIME_MILLIS respectively
*/
public AbstractPageOperationTemplate(){
this(DEFAULT_MAX_PAGES, DEFAULT_MAX_TIME_MILLIS);
public AbstractPageOperationTemplate(String operationName){
this(DEFAULT_MAX_PAGES, DEFAULT_MAX_TIME_MILLIS, operationName);
}
/**
* Instantiates a new AbstractPageOperationTemplate with the
* given maxPages and maxTime
@ -59,12 +63,12 @@ public abstract class AbstractPageOperationTemplate<T> {
* @param maxPages the maximum number of pages to fetch.
* @param maxTime the maximum execution time.
*/
public AbstractPageOperationTemplate(int maxPages, long maxTime){
public AbstractPageOperationTemplate(int maxPages, long maxTime, String operationName){
this.maxPages = maxPages;
this.maxTime = maxTime;
this.operationName = operationName;
}
/**
* Execute the operation on each member of a page of results
* retrieved through the fetch method. the method will execute
@ -74,8 +78,7 @@ public abstract class AbstractPageOperationTemplate<T> {
* swallowException (default true) field is set true.
*/
public void execute(){
logger.info("Starting execution of paged operation. maximum time: " + maxTime
+ " maximum pages: " + maxPages);
logger.debug("[" + getOperationName() + "] Starting execution of paged operation. maximum time: " + maxTime + ", maximum pages: " + maxPages);
long startTime = System.currentTimeMillis();
long executionTime = 0;
@ -112,12 +115,11 @@ public abstract class AbstractPageOperationTemplate<T> {
executionTime = System.currentTimeMillis() - startTime;
}
logger.info("Paged operation run completed " + operationsCompleted + " swallowed " + exceptionsSwallowedCount + " exceptions");
for(String className: exceptionsSwallowedClasses) {
logger.warn("Paged operation swallowed at least one exception of type " + className);
}
finalReport(operationsCompleted, exceptionsSwallowedCount, exceptionsSwallowedClasses);
}
/**
* method responsible for fetching
* a page of items.
@ -133,6 +135,19 @@ public abstract class AbstractPageOperationTemplate<T> {
* @param item the item
*/
protected abstract void doOperation(T item);
/**
* Method responsible for final report of progress.
* @return
*/
protected void finalReport(int operationsCompleted, int exceptionsSwallowedCount, Set<String> exceptionsSwallowedClasses) {
if (operationsCompleted > 0 || exceptionsSwallowedCount > 0) {
logger.info("[" + getOperationName() + "] Paged operation run: completed " + operationsCompleted + "; swallowed " + exceptionsSwallowedCount + " exceptions");
}
for(String className: exceptionsSwallowedClasses) {
logger.warn("[" + getOperationName() + "] Paged operation swallowed at least one exception of type " + className);
}
}
public int getMaxPages() {
return maxPages;
@ -157,4 +172,20 @@ public abstract class AbstractPageOperationTemplate<T> {
public void setSwallowExceptions(boolean swallowExceptions) {
this.swallowExceptions = swallowExceptions;
}
/**
* @return the operationName
*/
public String getOperationName() {
return operationName;
}
/**
* @param operationName the operationName to set
*/
public void setOperationName(String operationName) {
this.operationName = operationName;
}
}

View File

@ -138,7 +138,7 @@ public class AbstractPageOperationTemplateTest {
private long timeToPreviousFetch;
private CountingPageOperation(int maxPages, long maxTime) {
super(maxPages, maxTime);
super(maxPages, maxTime, "CountingPageOperation");
startTime = System.currentTimeMillis();
}

View File

@ -117,7 +117,7 @@ public class DefaultOAuth2AuthorizationCodeService implements AuthorizationCodeS
@Transactional(value="defaultTransactionManager")
public void clearExpiredAuthorizationCodes() {
new AbstractPageOperationTemplate<AuthorizationCodeEntity>(){
new AbstractPageOperationTemplate<AuthorizationCodeEntity>("clearExpiredAuthorizationCodes"){
@Override
public Collection<AuthorizationCodeEntity> fetchPage() {
return repository.getExpiredCodes();

View File

@ -492,7 +492,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
public void clearExpiredTokens() {
logger.debug("Cleaning out all expired tokens");
new AbstractPageOperationTemplate<OAuth2AccessTokenEntity>() {
new AbstractPageOperationTemplate<OAuth2AccessTokenEntity>("clearExpiredAccessTokens") {
@Override
public Collection<OAuth2AccessTokenEntity> fetchPage() {
return tokenRepository.getAllExpiredAccessTokens(new DefaultPageCriteria());
@ -504,7 +504,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
}
}.execute();
new AbstractPageOperationTemplate<OAuth2RefreshTokenEntity>() {
new AbstractPageOperationTemplate<OAuth2RefreshTokenEntity>("clearExpiredRefreshTokens") {
@Override
public Collection<OAuth2RefreshTokenEntity> fetchPage() {
return tokenRepository.getAllExpiredRefreshTokens(new DefaultPageCriteria());
@ -516,7 +516,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
}
}.execute();
new AbstractPageOperationTemplate<AuthenticationHolderEntity>() {
new AbstractPageOperationTemplate<AuthenticationHolderEntity>("clearExpiredAuthenticationHolders") {
@Override
public Collection<AuthenticationHolderEntity> fetchPage() {
return authenticationHolderRepository.getOrphanedAuthenticationHolders(new DefaultPageCriteria());