summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/ccb/MonitoredCCBAPI.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-03-20 17:07:26 -0700
committerJesse Morgan <jesse@jesterpm.net>2016-03-20 17:22:38 -0700
commit55cba1e0f3373fa69d3b9a66f455ad36ab4b82cf (patch)
treebed424a7c2989b8bbd5fb874ae23b9ef674ecd8b /src/com/p4square/grow/ccb/MonitoredCCBAPI.java
parentcac52cf3a07fb4c032f352ec48b56640b246f04f (diff)
Adding support for Church Community Builder login.
Beginning with this change all of the Church Management System integration logic is moving into implementations of the new IntegrationDriver interface. The desired IntegrationDriver can be selected by setting the integrationDriver config to the appropriate class name. This commit is only moving login support. Progress reporting will move in a later commit.
Diffstat (limited to 'src/com/p4square/grow/ccb/MonitoredCCBAPI.java')
-rw-r--r--src/com/p4square/grow/ccb/MonitoredCCBAPI.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/com/p4square/grow/ccb/MonitoredCCBAPI.java b/src/com/p4square/grow/ccb/MonitoredCCBAPI.java
new file mode 100644
index 0000000..6903460
--- /dev/null
+++ b/src/com/p4square/grow/ccb/MonitoredCCBAPI.java
@@ -0,0 +1,68 @@
+package com.p4square.grow.ccb;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+import com.p4square.ccbapi.CCBAPI;
+import com.p4square.ccbapi.model.GetCustomFieldLabelsResponse;
+import com.p4square.ccbapi.model.GetIndividualProfilesRequest;
+import com.p4square.ccbapi.model.GetIndividualProfilesResponse;
+
+import java.io.IOException;
+
+/**
+ * MonitoredCCBAPI is a CCBAPI decorator which records metrics for each API call.
+ */
+public class MonitoredCCBAPI implements CCBAPI {
+
+ private final CCBAPI mAPI;
+ private final MetricRegistry mMetricRegistry;
+
+ public MonitoredCCBAPI(final CCBAPI api, final MetricRegistry metricRegistry) {
+ if (api == null) {
+ throw new IllegalArgumentException("api must not be null.");
+ }
+ mAPI = api;
+
+ if (metricRegistry == null) {
+ throw new IllegalArgumentException("metricRegistry must not be null.");
+ }
+ mMetricRegistry = metricRegistry;
+ }
+
+ @Override
+ public GetCustomFieldLabelsResponse getCustomFieldLabels() throws IOException {
+ final Timer.Context timer = mMetricRegistry.timer("CCBAPI.getCustomFieldLabels.time").time();
+ boolean success = false;
+ try {
+ final GetCustomFieldLabelsResponse resp = mAPI.getCustomFieldLabels();
+ success = true;
+ return resp;
+ } finally {
+ timer.stop();
+ mMetricRegistry.counter("CCBAPI.getCustomFieldLabels.success").inc(success ? 1 : 0);
+ mMetricRegistry.counter("CCBAPI.getCustomFieldLabels.failure").inc(!success ? 1 : 0);
+ }
+ }
+
+ @Override
+ public GetIndividualProfilesResponse getIndividualProfiles(GetIndividualProfilesRequest request)
+ throws IOException {
+ final Timer.Context timer = mMetricRegistry.timer("CCBAPI.getIndividualProfiles").time();
+ boolean success = false;
+ try {
+ final GetIndividualProfilesResponse resp = mAPI.getIndividualProfiles(request);
+ mMetricRegistry.counter("CCBAPI.getCustomFieldLabels.count").inc(resp.getIndividuals().size());
+ success = true;
+ return resp;
+ } finally {
+ timer.stop();
+ mMetricRegistry.counter("CCBAPI.getCustomFieldLabels.success").inc(success ? 1 : 0);
+ mMetricRegistry.counter("CCBAPI.getCustomFieldLabels.failure").inc(!success ? 1 : 0);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ mAPI.close();
+ }
+}