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

View File

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

View File

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