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;
}
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;
}
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;
}
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);
}
}
};
}
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;
}
Aggregations