Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/480#discussion_r101853047
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/util/core/task/InterruptingImmediateSupplier.java
 ---
    @@ -0,0 +1,103 @@
    +/*
    + * 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.util.core.task;
    +
    +import java.util.concurrent.Callable;
    +import java.util.concurrent.Semaphore;
    +
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +import org.apache.brooklyn.util.exceptions.RuntimeInterruptedException;
    +import org.apache.brooklyn.util.guava.Maybe;
    +
    +import com.google.common.annotations.Beta;
    +import com.google.common.base.Supplier;
    +
    +/**
    + * Wraps a {@link Supplier} as an {@link ImmediateSupplier} by 
interrupting the thread before calling {@link Supplier#get()}.
    + * If the call succeeds, the result is returned.
    + * If the call throws any trace including an {@link InterruptedException} 
or {@link RuntimeInterruptedException} 
    + * (ie the call failed due to the interruption, typically because it tried 
to wait) 
    + * then this class concludes that there is no value available immediately 
and returns {@link Maybe#absent()}.
    + * If the call throws any other error, that is returned.
    + * The interruption is cleared afterwards (unless the thread was 
interrupted when the method was entered).
    + * <p>
    + * Note that some "immediate" methods, such as {@link Semaphore#acquire()} 
when a semaphore is available,
    + * will throw if the thread is interrupted.  Typically there are 
workarounds, for instance:
    + * <code>if (semaphore.tryAcquire()) semaphore.acquire();</code>. 
    + */
    +@Beta
    +public class InterruptingImmediateSupplier<T> implements 
ImmediateSupplier<T>, DeferredSupplier<T> {
    +
    +    final Supplier<T> nestedSupplier;
    --- End diff --
    
    I'd make this private (so it's clear to others that it's not being accessed 
directly from elsewhere - if such a use-case arises, we can change it or add a 
getter or whatever). Or if you thinking about users sub-classing it, then make 
it protected.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to