brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geomacy <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #520: Limit parallelism of start/stop steps on ...
Date Wed, 25 Jan 2017 14:52:55 GMT
Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/520#discussion_r97794132
  
    --- 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<Boolean>, ImmediateSupplier<Boolean>
{
    +    /**
    +     * 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<Boolean> 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 {
    +            private int permits;
    +            private transient final Semaphore sem;
    +
    +            public MaxConcurrencyLatch(int permits) {
    +                this.permits = permits;
    +                this.sem = new Semaphore(permits);
    +            }
    +
    +            @Override
    +            public void acquire(Entity caller) {
    --- End diff --
    
    makes sense; I think it probably would be worth adding the comment that the entity MAY
be ignored by implementations, and callers shouldn't assume any specific behaviour based on
entity, i.e. don't assume you have to match `acquire()`/`release()` on the same entity.


---
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