mitreid-connect
公開メンバ関数 | 限定公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.mitre.data.AbstractPageOperationTemplate< T > クラステンプレートabstract
org.mitre.data.AbstractPageOperationTemplate< T > 連携図
Collaboration graph

公開メンバ関数

 AbstractPageOperationTemplate (String operationName)
 
 AbstractPageOperationTemplate (int maxPages, long maxTime, String operationName)
 
void execute ()
 
abstract Collection< T > fetchPage ()
 
int getMaxPages ()
 
void setMaxPages (int maxPages)
 
long getMaxTime ()
 
void setMaxTime (long maxTime)
 
boolean isSwallowExceptions ()
 
void setSwallowExceptions (boolean swallowExceptions)
 
String getOperationName ()
 
void setOperationName (String operationName)
 

限定公開メンバ関数

abstract void doOperation (T item)
 
void finalReport (int operationsCompleted, int exceptionsSwallowedCount, Set< String > exceptionsSwallowedClasses)
 

非公開変数類

int maxPages
 
long maxTime
 
boolean swallowExceptions = true
 
String operationName = ""
 

静的非公開変数類

static final Logger logger = LoggerFactory.getLogger(AbstractPageOperationTemplate.class)
 
static int DEFAULT_MAX_PAGES = 1000
 
static long DEFAULT_MAX_TIME_MILLIS = 600000L
 

詳解

Abstract class for performing an operation on a potentially large number of items by paging through the items in discreet chunks.

引数
<T>the type parameter
著者
Colm Smyth.

構築子と解体子

◆ AbstractPageOperationTemplate() [1/2]

default constructor which sets the value of maxPages and maxTime to DEFAULT_MAX_PAGES and DEFAULT_MAX_TIME_MILLIS respectively

70  {
72  }
String operationName
Definition: AbstractPageOperationTemplate.java:62
static long DEFAULT_MAX_TIME_MILLIS
Definition: AbstractPageOperationTemplate.java:37
static int DEFAULT_MAX_PAGES
Definition: AbstractPageOperationTemplate.java:36

◆ AbstractPageOperationTemplate() [2/2]

org.mitre.data.AbstractPageOperationTemplate< T >.AbstractPageOperationTemplate ( int  maxPages,
long  maxTime,
String  operationName 
)
inline

Instantiates a new AbstractPageOperationTemplate with the given maxPages and maxTime

引数
maxPagesthe maximum number of pages to fetch.
maxTimethe maximum execution time.
81  {
82  this.maxPages = maxPages;
83  this.maxTime = maxTime;
85  }
long maxTime
Definition: AbstractPageOperationTemplate.java:50
int maxPages
Definition: AbstractPageOperationTemplate.java:44
String operationName
Definition: AbstractPageOperationTemplate.java:62

関数詳解

◆ doOperation()

abstract void org.mitre.data.AbstractPageOperationTemplate< T >.doOperation ( item)
abstractprotected

method responsible for performing desired operation on a fetched page item.

引数
itemthe item

◆ execute()

void org.mitre.data.AbstractPageOperationTemplate< T >.execute ( )
inline

Execute the operation on each member of a page of results retrieved through the fetch method. the method will execute until either the maxPages or maxTime limit is reached or until the fetch method returns no more results. Exceptions thrown performing the operation on the item will be swallowed if the swallowException (default true) field is set true.

95  {
96  logger.debug("[" + getOperationName() + "] Starting execution of paged operation. maximum time: " + maxTime + ", maximum pages: " + maxPages);
97 
98  long startTime = System.currentTimeMillis();
99  long executionTime = 0;
100  int i = 0;
101 
102  int exceptionsSwallowedCount = 0;
103  int operationsCompleted = 0;
104  Set<String> exceptionsSwallowedClasses = new HashSet<String>();
105 
106 
107  while (i< maxPages && executionTime < maxTime){
108  Collection<T> page = fetchPage();
109  if(page == null || page.size() == 0){
110  break;
111  }
112 
113  for (T item : page) {
114  try {
115  doOperation(item);
116  operationsCompleted++;
117  } catch (Exception e){
118  if(swallowExceptions){
119  exceptionsSwallowedCount++;
120  exceptionsSwallowedClasses.add(e.getClass().getName());
121  logger.debug("Swallowing exception " + e.getMessage(), e);
122  } else {
123  logger.debug("Rethrowing exception " + e.getMessage());
124  throw e;
125  }
126  }
127  }
128 
129  i++;
130  executionTime = System.currentTimeMillis() - startTime;
131  }
132 
133  finalReport(operationsCompleted, exceptionsSwallowedCount, exceptionsSwallowedClasses);
134  }
abstract Collection< T > fetchPage()
long maxTime
Definition: AbstractPageOperationTemplate.java:50
boolean swallowExceptions
Definition: AbstractPageOperationTemplate.java:57
int maxPages
Definition: AbstractPageOperationTemplate.java:44
String getOperationName()
Definition: AbstractPageOperationTemplate.java:195
void finalReport(int operationsCompleted, int exceptionsSwallowedCount, Set< String > exceptionsSwallowedClasses)
Definition: AbstractPageOperationTemplate.java:158
static final Logger logger
Definition: AbstractPageOperationTemplate.java:34

◆ fetchPage()

abstract Collection<T> org.mitre.data.AbstractPageOperationTemplate< T >.fetchPage ( )
abstract

method responsible for fetching a page of items.

戻り値
the collection of items

◆ finalReport()

void org.mitre.data.AbstractPageOperationTemplate< T >.finalReport ( int  operationsCompleted,
int  exceptionsSwallowedCount,
Set< String >  exceptionsSwallowedClasses 
)
inlineprotected

Method responsible for final report of progress.

戻り値
158  {
159  if (operationsCompleted > 0 || exceptionsSwallowedCount > 0) {
160  logger.info("[" + getOperationName() + "] Paged operation run: completed " + operationsCompleted + "; swallowed " + exceptionsSwallowedCount + " exceptions");
161  }
162  for(String className: exceptionsSwallowedClasses) {
163  logger.warn("[" + getOperationName() + "] Paged operation swallowed at least one exception of type " + className);
164  }
165  }
String getOperationName()
Definition: AbstractPageOperationTemplate.java:195
static final Logger logger
Definition: AbstractPageOperationTemplate.java:34

◆ getMaxPages()

int org.mitre.data.AbstractPageOperationTemplate< T >.getMaxPages ( )
inline
167  {
168  return maxPages;
169  }
int maxPages
Definition: AbstractPageOperationTemplate.java:44

◆ getMaxTime()

long org.mitre.data.AbstractPageOperationTemplate< T >.getMaxTime ( )
inline
175  {
176  return maxTime;
177  }
long maxTime
Definition: AbstractPageOperationTemplate.java:50

◆ getOperationName()

String org.mitre.data.AbstractPageOperationTemplate< T >.getOperationName ( )
inline
戻り値
the operationName
195  {
196  return operationName;
197  }
String operationName
Definition: AbstractPageOperationTemplate.java:62

◆ isSwallowExceptions()

boolean org.mitre.data.AbstractPageOperationTemplate< T >.isSwallowExceptions ( )
inline
183  {
184  return swallowExceptions;
185  }
boolean swallowExceptions
Definition: AbstractPageOperationTemplate.java:57

◆ setMaxPages()

void org.mitre.data.AbstractPageOperationTemplate< T >.setMaxPages ( int  maxPages)
inline
171  {
172  this.maxPages = maxPages;
173  }
int maxPages
Definition: AbstractPageOperationTemplate.java:44

◆ setMaxTime()

void org.mitre.data.AbstractPageOperationTemplate< T >.setMaxTime ( long  maxTime)
inline
179  {
180  this.maxTime = maxTime;
181  }
long maxTime
Definition: AbstractPageOperationTemplate.java:50

◆ setOperationName()

void org.mitre.data.AbstractPageOperationTemplate< T >.setOperationName ( String  operationName)
inline
引数
operationNamethe operationName to set
203  {
205  }
String operationName
Definition: AbstractPageOperationTemplate.java:62

◆ setSwallowExceptions()

void org.mitre.data.AbstractPageOperationTemplate< T >.setSwallowExceptions ( boolean  swallowExceptions)
inline
187  {
189  }
boolean swallowExceptions
Definition: AbstractPageOperationTemplate.java:57

メンバ詳解

◆ DEFAULT_MAX_PAGES

int org.mitre.data.AbstractPageOperationTemplate< T >.DEFAULT_MAX_PAGES = 1000
staticprivate

◆ DEFAULT_MAX_TIME_MILLIS

long org.mitre.data.AbstractPageOperationTemplate< T >.DEFAULT_MAX_TIME_MILLIS = 600000L
staticprivate

◆ logger

final Logger org.mitre.data.AbstractPageOperationTemplate< T >.logger = LoggerFactory.getLogger(AbstractPageOperationTemplate.class)
staticprivate

◆ maxPages

int specifying the maximum number of pages which should be fetched before execution should terminate

◆ maxTime

long specifying the maximum execution time in milliseconds

◆ operationName

String org.mitre.data.AbstractPageOperationTemplate< T >.operationName = ""
private

String that is used for logging in final tallies.

◆ swallowExceptions

boolean org.mitre.data.AbstractPageOperationTemplate< T >.swallowExceptions = true
private

boolean specifying whether or not Exceptions incurred performing the operation should be swallowed during execution default true.


このクラス詳解は次のファイルから抽出されました: