import static java.util.Objects.requireNonNull;
-import com.google.common.annotations.Beta;
import com.google.common.base.Stopwatch;
import com.google.common.base.Verify;
import java.util.Collection;
/**
* A behavior, which handles messages sent to a {@link AbstractClientActor}.
- *
- * @author Robert Varga
*/
-@Beta
public abstract class ClientActorBehavior<T extends BackendInfo> extends
RecoveredClientActorBehavior<ClientActorContext> implements Identifiable<ClientIdentifier> {
/**
return ((InternalCommand<T>) command).execute(this);
}
- if (command instanceof SuccessEnvelope) {
- return onRequestSuccess((SuccessEnvelope) command);
+ if (command instanceof SuccessEnvelope successEnvelope) {
+ return onRequestSuccess(successEnvelope);
}
-
- if (command instanceof FailureEnvelope) {
- return internalOnRequestFailure((FailureEnvelope) command);
+ if (command instanceof FailureEnvelope failureEnvelope) {
+ return internalOnRequestFailure(failureEnvelope);
}
if (MessageAssembler.isHandledMessage(command)) {
}
private static long extractCookie(final Identifier id) {
- if (id instanceof TransactionIdentifier) {
- return ((TransactionIdentifier) id).getHistoryId().getCookie();
- } else if (id instanceof LocalHistoryIdentifier) {
- return ((LocalHistoryIdentifier) id).getCookie();
+ if (id instanceof TransactionIdentifier transactionId) {
+ return transactionId.getHistoryId().getCookie();
+ } else if (id instanceof LocalHistoryIdentifier historyId) {
+ return historyId.getCookie();
} else {
throw new IllegalArgumentException("Unhandled identifier " + id);
}
* sessionId and if it does not match our current connection just ignore it.
*/
final Optional<T> optBackend = conn.getBackendInfo();
- if (optBackend.isPresent() && optBackend.get().getSessionId() != command.getSessionId()) {
+ if (optBackend.isPresent() && optBackend.orElseThrow().getSessionId() != command.getSessionId()) {
LOG.debug("{}: Mismatched current connection {} and envelope {}, ignoring response", persistenceId(),
conn, command);
return this;
LOG.error("{}: failed to resolve shard {}", persistenceId(), shard, failure);
final RequestException cause;
- if (failure instanceof RequestException) {
- cause = (RequestException) failure;
+ if (failure instanceof RequestException requestException) {
+ cause = requestException;
} else {
cause = new RuntimeRequestException("Failed to resolve shard " + shard, failure);
}
final Long shard = oldConn.cookie();
LOG.info("{}: refreshing backend for shard {}", persistenceId(), shard);
- resolver().refreshBackendInfo(shard, conn.getBackendInfo().get()).whenComplete(
+ resolver().refreshBackendInfo(shard, conn.getBackendInfo().orElseThrow()).whenComplete(
(backend, failure) -> context().executeInActor(behavior -> {
backendConnectFinished(shard, conn, backend, failure);
return behavior;