Search in sources :

Example 6 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project core-java by SpineEventEngine.

the class ProcessManagerRepository method findOrCreate.

/**
     * Loads or creates a process manager by the passed ID.
     *
     * <p>The process manager is created if there was no manager with such an ID stored before.
     *
     * <p>The repository injects {@code CommandBus} from its {@code BoundedContext} into the
     * instance of the process manager so that it can post commands if needed.
     *
     * @param id the ID of the process manager to load
     * @return loaded or created process manager instance
     */
@Override
@CheckReturnValue
protected P findOrCreate(I id) {
    final P result = super.findOrCreate(id);
    final CommandBus commandBus = getBoundedContext().getCommandBus();
    result.setCommandBus(commandBus);
    return result;
}
Also used : CommandBus(io.spine.server.commandbus.CommandBus) CheckReturnValue(javax.annotation.CheckReturnValue)

Example 7 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project core-java by SpineEventEngine.

the class Repository method getEntityStateType.

/**
     * Returns the {@link TypeUrl} for the state objects wrapped by entities
     * managed by this repository
     */
@CheckReturnValue
public TypeUrl getEntityStateType() {
    if (entityStateType == null) {
        final Class<? extends Message> stateClass = getEntityStateClass();
        final ClassName stateClassName = ClassName.of(stateClass);
        entityStateType = KnownTypes.getTypeUrl(stateClassName);
    }
    checkNotNull(entityStateType);
    return entityStateType;
}
Also used : ClassName(io.spine.type.ClassName) CheckReturnValue(javax.annotation.CheckReturnValue)

Example 8 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project core-java by SpineEventEngine.

the class Tests method hasPrivateParameterlessCtor.

/**
     * Verifies if the passed class has private parameter-less constructor and invokes it
     * using Reflection.
     *
     * @return {@code true} if the class has private parameter-less constructor,
     *         {@code false} otherwise
     */
@CheckReturnValue
@VisibleForTesting
static boolean hasPrivateParameterlessCtor(Class<?> targetClass) {
    final Constructor constructor;
    try {
        constructor = targetClass.getDeclaredConstructor();
    } catch (NoSuchMethodException ignored) {
        return false;
    }
    if (!Modifier.isPrivate(constructor.getModifiers())) {
        return false;
    }
    constructor.setAccessible(true);
    //noinspection OverlyBroadCatchBlock
    try {
        // Call the constructor to include it into the coverage.
        // Some of the coding conventions may encourage throwing AssertionError
        // to prevent the instantiation of the target class,
        // if it is designed as a utility class.
        constructor.newInstance();
    } catch (Exception ignored) {
        return true;
    }
    return true;
}
Also used : Constructor(java.lang.reflect.Constructor) CheckReturnValue(javax.annotation.CheckReturnValue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project grpc-java by grpc.

the class DeadlineSubject method isWithin.

/**
   * Prepares for a check that the subject is deadline within the given tolerance of an
   * expected value that will be provided in the next call in the fluent chain.
   */
@CheckReturnValue
public TolerantDeadlineComparison isWithin(final long delta, final TimeUnit timeUnit) {
    return new TolerantDeadlineComparison() {

        @Override
        public void of(Deadline expected) {
            Deadline actual = getSubject();
            checkNotNull(actual, "actual value cannot be null. expected=%s", expected);
            // This is probably overkill, but easier than thinking about overflow.
            BigInteger actualTimeRemaining = BigInteger.valueOf(actual.timeRemaining(NANOSECONDS));
            BigInteger expectedTimeRemaining = BigInteger.valueOf(expected.timeRemaining(NANOSECONDS));
            BigInteger deltaNanos = BigInteger.valueOf(timeUnit.toNanos(delta));
            if (actualTimeRemaining.subtract(expectedTimeRemaining).abs().compareTo(deltaNanos) > 0) {
                failWithRawMessage("%s and <%s> should have been within <%sns> of each other", getDisplaySubject(), expected, deltaNanos);
            }
        }
    };
}
Also used : Deadline(io.grpc.Deadline) BigInteger(java.math.BigInteger) CheckReturnValue(javax.annotation.CheckReturnValue)

Example 10 with CheckReturnValue

use of javax.annotation.CheckReturnValue in project grpc-java by grpc.

the class NettyChannelBuilder method createProtocolNegotiator.

@VisibleForTesting
@CheckReturnValue
static ProtocolNegotiator createProtocolNegotiator(String authority, NegotiationType negotiationType, SslContext sslContext) {
    ProtocolNegotiator negotiator = createProtocolNegotiatorByType(authority, negotiationType, sslContext);
    String proxy = System.getenv("GRPC_PROXY_EXP");
    if (proxy != null) {
        String[] parts = proxy.split(":", 2);
        int port = 80;
        if (parts.length > 1) {
            port = Integer.parseInt(parts[1]);
        }
        InetSocketAddress proxyAddress = new InetSocketAddress(parts[0], port);
        negotiator = ProtocolNegotiators.httpProxy(proxyAddress, null, null, negotiator);
    }
    return negotiator;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CheckReturnValue(javax.annotation.CheckReturnValue)

Aggregations

CheckReturnValue (javax.annotation.CheckReturnValue)13 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 Predicate (com.google.common.base.Predicate)1 Supplier (com.google.common.base.Supplier)1 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 BugCheckerInfo (com.google.errorprone.BugCheckerInfo)1 BugPattern (com.google.errorprone.BugPattern)1 SeverityLevel (com.google.errorprone.BugPattern.SeverityLevel)1 ErrorProneOptions (com.google.errorprone.ErrorProneOptions)1 Severity (com.google.errorprone.ErrorProneOptions.Severity)1 InvalidCommandLineOptionException (com.google.errorprone.InvalidCommandLineOptionException)1 CompatibleWith (com.google.errorprone.annotations.CompatibleWith)1 BugChecker (com.google.errorprone.bugpatterns.BugChecker)1 Any (com.google.protobuf.Any)1