+ private static final Logger LOG = LoggerFactory.getLogger(LeaderFrontendState.class);
+
+ private final ShardDataTree tree;
+ private final ClientIdentifier clientId;
+ private final String persistenceId;
+
+ private long lastConnectTicks;
+ private long lastSeenTicks;
+
+ // TODO: explicit failover notification
+ // Record the ActorRef for the originating actor and when we switch to being a leader send a notification
+ // to the frontend client -- that way it can immediately start sending requests
+
+ // TODO: add statistics:
+ // - number of requests processed
+ // - number of histories processed
+ // - per-RequestException throw counters
+
+ LeaderFrontendState(final String persistenceId, final ClientIdentifier clientId, final ShardDataTree tree) {
+ this.persistenceId = requireNonNull(persistenceId);
+ this.clientId = requireNonNull(clientId);
+ this.tree = requireNonNull(tree);
+ this.lastSeenTicks = tree.readTime();
+ }
+
+ @Override
+ public final ClientIdentifier getIdentifier() {
+ return clientId;
+ }
+
+ final String persistenceId() {
+ return persistenceId;
+ }
+
+ final long getLastConnectTicks() {
+ return lastConnectTicks;
+ }
+
+ final long getLastSeenTicks() {
+ return lastSeenTicks;
+ }
+
+ final ShardDataTree tree() {
+ return tree;
+ }
+
+ final void touch() {
+ this.lastSeenTicks = tree.readTime();
+ }
+
+ abstract @Nullable LocalHistorySuccess handleLocalHistoryRequest(LocalHistoryRequest<?> request,
+ RequestEnvelope envelope, long now) throws RequestException;
+
+ abstract @Nullable TransactionSuccess<?> handleTransactionRequest(TransactionRequest<?> request,
+ RequestEnvelope envelope, long now) throws RequestException;
+