@Override public T fromSnapshotStore(final SnapshotOffer snapshotOffer) { return convertSnapshotToJsonifiable(snapshotOffer.snapshot()); }
/** * Recovers the passed in {@link SnapshotOffer} to a {@link Thing}. * * @param snapshotOffer the snapshot offer * @return the Thing restored from the snapshot offer or {@code null}. * @throws NullPointerException if {@code snapshotOffer} is {@code null}. */ @Nullable public Thing recoverThingFromSnapshotOffer(@Nonnull final SnapshotOffer snapshotOffer) { checkNotNull(snapshotOffer, "snapshot offer"); final ThingWithSnapshotTag result = snapshotAdapter.fromSnapshotStore(snapshotOffer); final SnapshotMetadata metadata = snapshotOffer.metadata(); final SnapshotTag snapshotTag = Optional.ofNullable(result) .map(ThingWithSnapshotTag::getSnapshotTag) .orElse(SnapshotTag.UNPROTECTED); snapshotterState = new SnapshotterState(false, metadata.sequenceNr(), snapshotTag, null, null); return result; }
/** * Recovers the passed in {@link SnapshotOffer} to a {@link Thing}. * * @param snapshotOffer the snapshot offer * @return the Thing restored from the snapshot offer or {@code null}. * @throws NullPointerException if {@code snapshotOffer} is {@code null}. */ @Nullable public Thing recoverThingFromSnapshotOffer(@Nonnull final SnapshotOffer snapshotOffer) { checkNotNull(snapshotOffer, "snapshot offer"); final ThingWithSnapshotTag result = snapshotAdapter.fromSnapshotStore(snapshotOffer); final SnapshotMetadata metadata = snapshotOffer.metadata(); final SnapshotTag snapshotTag = Optional.ofNullable(result) .map(ThingWithSnapshotTag::getSnapshotTag) .orElse(SnapshotTag.UNPROTECTED); snapshotterState = new SnapshotterState(false, metadata.sequenceNr(), snapshotTag, null, null); return result; }
@Override public T fromSnapshotStore(final SnapshotOffer snapshotOffer) { return convertSnapshotToJsonifiable(snapshotOffer.snapshot()); }
@Override public Receive createReceiveRecover() { return ReceiveBuilder.create() // # Snapshot handling .match(SnapshotOffer.class, ss -> { final Set<String> fromSnapshotStore = snapshotAdapter.fromSnapshotStore(ss); log.info("Received SnapshotOffer containing connectionIds: <{}>", fromSnapshotStore); if (fromSnapshotStore != null) { connectionIds.clear(); connectionIds.addAll(fromSnapshotStore); } lastSnapshotSequenceNr = ss.metadata().sequenceNr(); }) .match(ConnectionCreated.class, event -> connectionIds.add(event.getConnectionId())) .match(ConnectionOpened.class, event -> connectionIds.add(event.getConnectionId())) .match(ConnectionClosed.class, event -> connectionIds.remove(event.getConnectionId())) .match(ConnectionDeleted.class, event -> connectionIds.remove(event.getConnectionId())) .match(RecoveryCompleted.class, rc -> connectionIds.forEach(this::reconnect)) .matchAny(m -> log.warning("Unknown recover message: {}", m)) .build(); }
@Override protected void handleRecover(Object message) throws Exception { if (message instanceof RecoveryCompleted) { onRecoveryCompleted(); } else if (message instanceof SnapshotOffer) { applyShardManagerSnapshot((ShardManagerSnapshot)((SnapshotOffer) message).snapshot()); } }
@Override public Receive createReceiveRecover() { return ReceiveBuilder.create() .match(SnapshotOffer.class, ss -> { batchIds = snapshotAdapter.fromSnapshotStore(ss); snapshotSequenceNr = ss.metadata().sequenceNr(); }) .match(BatchExecutionStarted.class, event -> batchIds.add(event.getBatchId())) .match(BatchExecutionFinished.class, event -> batchIds.remove(event.getBatchId())) .match(RecoveryCompleted.class, rc -> { log.debug("Recovery completed"); batchIds.forEach(this::lookupBatchCoordinatorActor); }) .matchAny(m -> log.warning("Unknown recover message: {}", m)) .build(); }
@Override public Set<String> fromSnapshotStore(final SnapshotOffer snapshotOffer) { final Object snapshotEntityFromDb = snapshotOffer.snapshot(); final JsonArray jsonValues; if (snapshotEntityFromDb instanceof BsonValue) { jsonValues = JsonFactory.newArray(DittoBsonJson.getInstance().serialize((BsonValue) snapshotEntityFromDb) .toString()); } else { throw new IllegalArgumentException( "Unable to fromSnapshotStore a non-'BsonValue' object! Was: " + snapshotEntityFromDb.getClass()); } return jsonValues.stream() .map(JsonValue::asString) .collect(Collectors.toSet()); }
@Override public Receive createReceiveRecover() { // defines how state is updated during recovery return handlePolicyEvents.orElse(ReceiveBuilder.create() // # Snapshot handling .match(SnapshotOffer.class, ss -> { policy = snapshotAdapter.fromSnapshotStore(ss); lastSnapshotSequenceNr = ss.metadata().sequenceNr(); }) // # Recovery handling .match(RecoveryCompleted.class, rc -> { if (policy != null) { log.debug("Policy <{}> was recovered.", policyId); if (isPolicyActive()) { becomePolicyCreatedHandler(); } else if (isPolicyDeleted()) { becomePolicyDeletedHandler(); } else { log.error("Unknown lifecycle state <{}> for Policy <{}>.", policy.getLifecycle(), policyId); } } }) // # Handle unknown .matchAny(m -> log.warning("Unknown recover message: {}", m)) .build()); }
@Override protected final void handleRecover(final Object message) { if (message instanceof RecoveryCompleted) { if (incarnation != null) { incarnation = incarnation + 1; } else { incarnation = 0; } this.localBucket = new LocalBucket<>(incarnation.intValue(), initialData); initialData = null; LOG.debug("{}: persisting new incarnation {}", persistenceId(), incarnation); persisting = true; saveSnapshot(incarnation); } else if (message instanceof SnapshotOffer) { incarnation = (Integer) ((SnapshotOffer)message).snapshot(); LOG.debug("{}: recovered incarnation {}", persistenceId(), incarnation); } else { LOG.warn("{}: ignoring recovery message {}", persistenceId(), message); } }
@Override public Receive createReceiveRecover() { // defines how state is updated during recovery return handlePolicyEvents.orElse(ReceiveBuilder.create() // # Snapshot handling .match(SnapshotOffer.class, ss -> { policy = snapshotAdapter.fromSnapshotStore(ss); lastSnapshotSequenceNr = ss.metadata().sequenceNr(); }) // # Recovery handling .match(RecoveryCompleted.class, rc -> { if (policy != null) { log.debug("Policy <{}> was recovered.", policyId); if (isPolicyActive()) { becomePolicyCreatedHandler(); } else if (isPolicyDeleted()) { becomePolicyDeletedHandler(); } else { log.error("Unknown lifecycle state <{}> for Policy <{}>.", policy.getLifecycle(), policyId); } } }) // # Handle unknown .matchAny(m -> log.warning("Unknown recover message: {}", m)) .build()); }
@Override public Receive createReceiveRecover() { return receiveBuilder() .match(String.class, evt -> state.update(evt)) .match(SnapshotOffer.class, ss -> { System.out.println("offered state = " + ss); state = (ExampleState) ss.snapshot(); }) .build(); } }
connectionStatus = fromSnapshotStore.getConnectionStatus(); lastSnapshotSequenceNr = ss.metadata().sequenceNr(); }) .match(ConnectionCreated.class, event -> {
@Override AbstractClientActorBehavior<?> onReceiveRecover(final Object recover) { if (recover instanceof RecoveryCompleted) { final ClientIdentifier nextId; if (lastId != null) { if (!currentFrontend.equals(lastId.getFrontendId())) { LOG.error("Mismatched frontend identifier, shutting down. Current: {} Saved: {}", currentFrontend, lastId.getFrontendId()); return null; } nextId = ClientIdentifier.create(currentFrontend, lastId.getGeneration() + 1); } else { nextId = ClientIdentifier.create(currentFrontend, 0); } LOG.debug("{}: persisting new identifier {}", persistenceId(), nextId); context().saveSnapshot(nextId); return new SavingClientActorBehavior(context(), nextId); } else if (recover instanceof SnapshotOffer) { lastId = (ClientIdentifier) ((SnapshotOffer)recover).snapshot(); LOG.debug("{}: recovered identifier {}", lastId); } else { LOG.warn("{}: ignoring recovery message {}", recover); } return this; } }
restoreConnection(fromSnapshotStore); lastSnapshotSequenceNr = ss.metadata().sequenceNr(); }) .match(ConnectionCreated.class, event -> restoreConnection(event.getConnection()))
@Override AbstractClientActorBehavior<?> onReceiveRecover(final Object recover) { if (recover instanceof RecoveryCompleted) { final ClientIdentifier nextId; if (lastId != null) { if (!currentFrontend.equals(lastId.getFrontendId())) { LOG.error("{}: Mismatched frontend identifier, shutting down. Current: {} Saved: {}", persistenceId(), currentFrontend, lastId.getFrontendId()); return null; } nextId = ClientIdentifier.create(currentFrontend, lastId.getGeneration() + 1); } else { nextId = ClientIdentifier.create(currentFrontend, 0); } LOG.debug("{}: persisting new identifier {}", persistenceId(), nextId); context().saveSnapshot(nextId); return new SavingClientActorBehavior(context(), nextId); } else if (recover instanceof SnapshotOffer) { lastId = (ClientIdentifier) ((SnapshotOffer)recover).snapshot(); LOG.debug("{}: recovered identifier {}", persistenceId(), lastId); } else { LOG.warn("{}: ignoring recovery message {}", persistenceId(), recover); } return this; } }