Processes transactions, reading them from the transaction feed and inserting them into the configured Oracle database. This function blocks indefinitely. Errors are logged to log4j2. TODO(jackson): Support propagating persistent errors?
()
| 197 | * TODO(jackson): Support propagating persistent errors? |
| 198 | */ |
| 199 | public void process() { |
| 200 | ThreadContext.put("feed_id", mFeed.id); |
| 201 | ThreadContext.put("feed_filter", mFeed.filter); |
| 202 | |
| 203 | while (true) { |
| 204 | try { |
| 205 | ThreadContext.put("feed_after", mFeed.after); |
| 206 | |
| 207 | // Retrieve another page of transactions matching the feed. |
| 208 | final Transaction.Items page = |
| 209 | new QueryBuilder() |
| 210 | .setFilter(mFeed.filter) |
| 211 | .setAfter(mFeed.after) |
| 212 | .setTimeout(DEFAULT_TIMEOUT_MILLIS) |
| 213 | .setAscendingWithLongPoll() |
| 214 | .execute(mChain); |
| 215 | |
| 216 | // Commit the batch of transactions to the database. |
| 217 | try { |
| 218 | processBatch(page.list); |
| 219 | } catch (SQLException ex) { |
| 220 | logger.catching(ex); |
| 221 | // Skip the ack so we re-fetch this page and try again. |
| 222 | // TODO(jackson): Do we need any backoff? Don't want to |
| 223 | // hammer Chain Core or the Oracle database if there's |
| 224 | // an issue. |
| 225 | // TODO(jackson): Add retry logic in processBatch so that |
| 226 | // we don't re-query Chain Core if we don't need to? |
| 227 | continue; |
| 228 | } |
| 229 | |
| 230 | // Acknowledge that we've processed the entire page. |
| 231 | Map<String, Object> requestBody = new TreeMap<>(); |
| 232 | requestBody.put("id", mFeed.id); |
| 233 | requestBody.put("previous_after", mFeed.after); |
| 234 | requestBody.put("after", page.next.after); |
| 235 | mFeed = mChain.request("update-transaction-feed", requestBody, Transaction.Feed.class); |
| 236 | } catch (APIException ex) { |
| 237 | // If there was an issue retrieving the transactions, |
| 238 | // log it. If the request just timed out, no matching |
| 239 | // transactions were committed so just silently ignore it. |
| 240 | if (!"CH001".equals(ex.code)) { |
| 241 | logger.catching(ex); |
| 242 | } |
| 243 | } catch (ChainException ex) { |
| 244 | logger.catching(ex); |
| 245 | } finally { |
| 246 | ThreadContext.remove("feed_after"); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // processBatch inserts a batch of transactions into the Oracle |
| 252 | // database. |
no test coverage detected