@Override public T fromSnapshotStore(final SnapshotOffer snapshotOffer) { return convertSnapshotToJsonifiable(snapshotOffer.snapshot()); }
@Override public T fromSnapshotStore(final SnapshotOffer snapshotOffer) { return convertSnapshotToJsonifiable(snapshotOffer.snapshot()); }
@Override protected void handleRecover(Object message) throws Exception { if (message instanceof RecoveryCompleted) { onRecoveryCompleted(); } else if (message instanceof SnapshotOffer) { applyShardManagerSnapshot((ShardManagerSnapshot)((SnapshotOffer) message).snapshot()); } }
@Nullable @Override public Set<String> fromSnapshotStore(final SnapshotOffer snapshotOffer) { final String persistenceId = snapshotOffer.metadata().persistenceId(); final Object snapshotEntity = snapshotOffer.snapshot(); return createSetFromSnapshot(persistenceId, snapshotEntity); }
@Nullable @Override public Set<String> fromSnapshotStore(final SnapshotOffer snapshotOffer) { final String persistenceId = snapshotOffer.metadata().persistenceId(); final Object snapshotEntity = snapshotOffer.snapshot(); return createSetFromSnapshot(persistenceId, snapshotEntity); }
@Nullable @Override public ConnectionData fromSnapshotStore(final SnapshotOffer snapshotOffer) { final String persistenceId = snapshotOffer.metadata().persistenceId(); final Object snapshotEntity = snapshotOffer.snapshot(); return createConnectionDataFromSnapshot(persistenceId, snapshotEntity); }
@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 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() { return receiveBuilder() .match(String.class, evt -> state.update(evt)) .match(SnapshotOffer.class, ss -> { System.out.println("offered state = " + ss); state = (ExampleState) ss.snapshot(); }) .build(); } }
@Override public Receive createReceiveRecover() { return receiveBuilder() .match(Evt.class, e -> { System.out.println(e.getData()); state.update(e); }) .match(SnapshotOffer.class, ss -> { System.out.println(ss.toString()); state = (ExampleState) ss.snapshot(); }) .build(); }
@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; } }
@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; } }
/** * Handle the following cases : * 1- if there is a snapshot , apply the snapshot state and stop * 2- else if it is an event reply without snapshot apply the event change and construct the state and behavior based into it * 3 - if none then construct empty state * <p> * * @return Receive logic for recovery */ @Override public final Receive createReceiveRecover() { return ReceiveBuilder.create() .match(SnapshotOffer.class, snapshot -> this.state = (S) snapshot.snapshot()) .match(RecoveryCompleted.class, recoveryCompleted -> this.state = recoveryCompleted(state) ).match(eventType, event -> { applyEvent(event); eventCount += 1; }) .build(); }
Snapshot snapshot = (Snapshot) offer.snapshot();