Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B58E6200C09 for ; Wed, 25 Jan 2017 15:38:09 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B4267160B50; Wed, 25 Jan 2017 14:38:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 07A20160B4E for ; Wed, 25 Jan 2017 15:38:08 +0100 (CET) Received: (qmail 89411 invoked by uid 500); 25 Jan 2017 14:38:08 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 89395 invoked by uid 99); 25 Jan 2017 14:38:07 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jan 2017 14:38:07 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D13DCDFA69; Wed, 25 Jan 2017 14:38:07 +0000 (UTC) From: neykov To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #520: Limit parallelism of start/stop steps on ... Content-Type: text/plain Message-Id: <20170125143807.D13DCDFA69@git1-us-west.apache.org> Date: Wed, 25 Jan 2017 14:38:07 +0000 (UTC) archived-at: Wed, 25 Jan 2017 14:38:09 -0000 Github user neykov commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/520#discussion_r97790853 --- Diff: core/src/main/java/org/apache/brooklyn/core/sensor/ReleaseableLatch.java --- @@ -0,0 +1,95 @@ +/* + * 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 + * with the License. You may obtain a copy of the License at + * + * 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.brooklyn.core.sensor; + +import java.util.concurrent.Semaphore; + +import org.apache.brooklyn.api.entity.Entity; +import org.apache.brooklyn.util.core.task.DeferredSupplier; +import org.apache.brooklyn.util.core.task.ImmediateSupplier; +import org.apache.brooklyn.util.exceptions.Exceptions; +import org.apache.brooklyn.util.guava.Maybe; + +// DeferredSupplier used as a marker interface to prevent coercion. When resolved it must evaluate to {@code Boolean.TRUE}. +public interface ReleaseableLatch extends DeferredSupplier, ImmediateSupplier { + /** + * Increment usage count for the {@code caller} entity + */ + void acquire(Entity caller); + + /** + * Decrement usage count for the {@code caller} entity + */ + void release(Entity caller); + + static abstract class AbstractReleaseableLatch implements ReleaseableLatch { + // Instances coerce to TRUE as they are non-null. + @Override public Boolean get() {return Boolean.TRUE;} + @Override public Maybe getImmediately() {return Maybe.of(Boolean.TRUE);} + } + + ReleaseableLatch NOP = new Factory.NopLatch(); + + static class Factory { + private static class NopLatch extends AbstractReleaseableLatch { + @Override public void acquire(Entity caller) {} + @Override public void release(Entity caller) {} + } + + private static class MaxConcurrencyLatch extends AbstractReleaseableLatch { --- End diff -- Two reasons: * Personal preference to inline small classes like this. * More importantly to hide the implementation and make it private. --- 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. ---