[
https://issues.apache.org/jira/browse/STREAMS-197?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14178865#comment-14178865
]
ASF GitHub Bot commented on STREAMS-197:
----------------------------------------
Github user robdouglas commented on a diff in the pull request:
https://github.com/apache/incubator-streams/pull/107#discussion_r19171438
--- Diff:
streams-runtimes/streams-runtime-local/src/main/java/org/apache/streams/local/counters/DatumStatusCounter.java
---
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.streams.local.counters;
+
+import net.jcip.annotations.ThreadSafe;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ *
+ */
+@ThreadSafe
+public class DatumStatusCounter implements DatumStatusCounterMXBean{
+
+ public static final String NAME_TEMPLATE =
"org.apache.streams.local:type=DatumCounter,name=%s";
+ private static final Logger LOGGER =
LoggerFactory.getLogger(DatumStatusCounter.class);
+
+ private AtomicLong failed;
+ private AtomicLong passed;
+
+ public DatumStatusCounter(String id) {
+ this.failed = new AtomicLong(0);
+ this.passed = new AtomicLong(0);
+ try {
+ ObjectName name = new ObjectName(String.format(NAME_TEMPLATE,
id));
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ mbs.registerMBean(this, name);
+ } catch (MalformedObjectNameException |
InstanceAlreadyExistsException | MBeanRegistrationException |
NotCompliantMBeanException e) {
+ LOGGER.error("Failed to register MXBean : {}", e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void incrementFailedCount() {
+ this.incrementFailedCount(1);
+ }
+
+ public void incrementFailedCount(long delta) {
+ this.failed.addAndGet(delta);
+ }
+
+ public void incrementPassedCount() {
+ this.incrementPassedCount(1);
+ }
+
+ public void incrementPassedCount(long delta) {
+ this.passed.addAndGet(delta);
+ }
+
+
+ @Override
+ public double getFailRate() {
+ double failed = this.failed.get();
--- End diff --
can you declare `double passed = this.passed.get()` here so you don't have
to call it twice?
> Implement New Counting Classes
> ------------------------------
>
> Key: STREAMS-197
> URL: https://issues.apache.org/jira/browse/STREAMS-197
> Project: Streams
> Issue Type: Sub-task
> Reporter: Ryan Ebanks
>
> Need to implement threadsafe classes that will count datums at the task level
> and process (prov/proc/writer) level.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)