Return-Path: X-Original-To: apmail-streams-dev-archive@minotaur.apache.org Delivered-To: apmail-streams-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BEB5617E3A for ; Thu, 9 Oct 2014 20:40:47 +0000 (UTC) Received: (qmail 72861 invoked by uid 500); 9 Oct 2014 20:40:46 -0000 Delivered-To: apmail-streams-dev-archive@streams.apache.org Received: (qmail 72818 invoked by uid 500); 9 Oct 2014 20:40:46 -0000 Mailing-List: contact dev-help@streams.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@streams.incubator.apache.org Delivered-To: mailing list dev@streams.incubator.apache.org Received: (qmail 72807 invoked by uid 99); 9 Oct 2014 20:40:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Oct 2014 20:40:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 09 Oct 2014 20:40:45 +0000 Received: (qmail 70261 invoked by uid 99); 9 Oct 2014 20:40:24 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Oct 2014 20:40:24 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4D077D648; Thu, 9 Oct 2014 20:40:24 +0000 (UTC) From: rbnks To: dev@streams.incubator.apache.org Reply-To: dev@streams.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-streams pull request: Streams 190 Content-Type: text/plain Message-Id: <20141009204024.4D077D648@tyr.zones.apache.org> Date: Thu, 9 Oct 2014 20:40:24 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Github user rbnks commented on a diff in the pull request: https://github.com/apache/incubator-streams/pull/99#discussion_r18672624 --- Diff: streams-runtimes/streams-runtime-local/src/main/java/org/apache/streams/local/queues/ThroughputQueue.java --- @@ -0,0 +1,377 @@ +/* + * 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.queues; + +import net.jcip.annotations.GuardedBy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import javax.management.*; +import java.lang.management.ManagementFactory; +import java.util.Collection; +import java.util.Iterator; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * A {@link java.util.concurrent.BlockingQueue} implementation that allows the measure measurement of how + * data flows through the queue. Is also a {@code MBean} so the flow statistics can be viewed through + * JMX. Registration of the bean happens whenever a constructor receives a non-null id. + * + * !!! Warning !!! + * Only the necessary methods for the local streams runtime are implemented. All other methods throw a + * {@link sun.reflect.generics.reflectiveObjects.NotImplementedException}. + */ +public class ThroughputQueue implements BlockingQueue, ThroughputQueueMXBean { + + public static final String NAME_TEMPLATE = "org.apache.streams.local:type=ThroughputQueue,name=%s"; + + private static final Logger LOGGER = LoggerFactory.getLogger(ThroughputQueue.class); + + private BlockingQueue> underlyingQueue; + private ReadWriteLock takeCountsLock; + private AtomicLong elementsAdded; + @GuardedBy("takeCountsLock") + private long elementsRemoved; --- End diff -- Yes, but they get accessed at the same time a lot of the time, so instead of acquiring three locks, I tried to simplify it under on lock. I can change this if the have Atomics is preferred. --- 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. ---