streams-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robdouglas <...@git.apache.org>
Subject [GitHub] incubator-streams pull request: STREAMS-197 | New counting/tacking...
Date Tue, 21 Oct 2014 19:09:18 GMT
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?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message