当前位置: 首页>>代码示例>>Java>>正文


Java SnapshotMetadata类代码示例

本文整理汇总了Java中akka.persistence.SnapshotMetadata的典型用法代码示例。如果您正苦于以下问题:Java SnapshotMetadata类的具体用法?Java SnapshotMetadata怎么用?Java SnapshotMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SnapshotMetadata类属于akka.persistence包,在下文中一共展示了SnapshotMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doSaveAsync

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Override
public Future<Void> doSaveAsync(SnapshotMetadata snapshotMetadata, Object obj) {
    List<StoredSnapshot> snapshotList = snapshots.get(snapshotMetadata.persistenceId());

    LOG.trace("doSaveAsync: persistentId {}: sequenceNr: {}: timestamp {}: {}", snapshotMetadata.persistenceId(),
            snapshotMetadata.sequenceNr(), snapshotMetadata.timestamp(), obj);

    if (snapshotList == null) {
        snapshotList = new ArrayList<>();
        snapshots.put(snapshotMetadata.persistenceId(), snapshotList);
    }
    synchronized (snapshotList) {
        snapshotList.add(new StoredSnapshot(snapshotMetadata, obj));
    }

    CountDownLatch latch = SNAPSHOT_SAVED_LATCHES.get(snapshotMetadata.persistenceId());
    if (latch != null) {
        latch.countDown();
    }

    return Futures.successful(null);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:23,代码来源:InMemorySnapshotStore.java

示例2: doDeleteAsync

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Override
public Future<Void> doDeleteAsync(SnapshotMetadata metadata) {
    List<StoredSnapshot> snapshotList = snapshots.get(metadata.persistenceId());

    if (snapshotList != null) {
        synchronized (snapshotList) {
            for (int i = 0; i < snapshotList.size(); i++) {
                StoredSnapshot snapshot = snapshotList.get(i);
                if (metadata.equals(snapshot.metadata)) {
                    snapshotList.remove(i);
                    break;
                }
            }
        }
    }

    return Futures.successful(null);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:InMemorySnapshotStore.java

示例3: testOnSnapshotOfferWithServerConfiguration

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Test
public void testOnSnapshotOfferWithServerConfiguration() {
    long electionTerm = 2;
    String electionVotedFor = "member-2";
    ServerConfigurationPayload serverPayload = new ServerConfigurationPayload(Arrays.asList(
                                                    new ServerInfo(localId, true),
                                                    new ServerInfo("follower1", true),
                                                    new ServerInfo("follower2", true)));

    MockSnapshotState snapshotState = new MockSnapshotState(Arrays.asList(new MockPayload("1")));
    Snapshot snapshot = Snapshot.create(snapshotState, Collections.<ReplicatedLogEntry>emptyList(),
            -1, -1, -1, -1, electionTerm, electionVotedFor, serverPayload);

    SnapshotMetadata metadata = new SnapshotMetadata("test", 6, 12345);
    SnapshotOffer snapshotOffer = new SnapshotOffer(metadata , snapshot);

    sendMessageToSupport(snapshotOffer);

    assertEquals("Journal log size", 0, context.getReplicatedLog().size());
    assertEquals("Election term", electionTerm, context.getTermInformation().getCurrentTerm());
    assertEquals("Election votedFor", electionVotedFor, context.getTermInformation().getVotedFor());
    assertTrue("Dynamic server configuration", context.isDynamicServerConfigurationInUse());
    assertEquals("Peer List", Sets.newHashSet("follower1", "follower2"),
        Sets.newHashSet(context.getPeerIds()));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:RaftActorRecoverySupportTest.java

示例4: doLoadAsync

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Override
public Future<Optional<SelectedSnapshot>> doLoadAsync(final String persistenceId,
                                                      final SnapshotSelectionCriteria criteria) {
    LOG.debug("In doLoadAsync - persistenceId: {}, criteria: {}", persistenceId, criteria);

    // Select the youngest 'maxLoadAttempts' snapshots that match the criteria. This may help in situations where
    // saving of a snapshot could not be completed because of a JVM crash. Hence, an attempt to load that snapshot
    // will fail but loading an older snapshot may succeed.

    Deque<SnapshotMetadata> metadatas = getSnapshotMetadatas(persistenceId, criteria).stream()
            .sorted(LocalSnapshotStore::compare).collect(reverse()).stream().limit(maxLoadAttempts)
                .collect(Collectors.toCollection(ArrayDeque::new));

    if (metadatas.isEmpty()) {
        return Futures.successful(Optional.empty());
    }

    LOG.debug("doLoadAsync - found: {}", metadatas);

    return Futures.future(() -> doLoad(metadatas), executionContext);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:LocalSnapshotStore.java

示例5: doLoad

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
private Optional<SelectedSnapshot> doLoad(final Deque<SnapshotMetadata> metadatas) throws IOException {
    SnapshotMetadata metadata = metadatas.removeFirst();
    File file = toSnapshotFile(metadata);

    LOG.debug("doLoad {}", file);

    try {
        Object data = deserialize(file);

        LOG.debug("deserialized data: {}", data);

        return Optional.of(new SelectedSnapshot(metadata, data));
    } catch (IOException e) {
        LOG.error("Error loading snapshot file {}, remaining attempts: {}", file, metadatas.size(), e);

        if (metadatas.isEmpty()) {
            throw e;
        }

        return doLoad(metadatas);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:23,代码来源:LocalSnapshotStore.java

示例6: extractMetadata

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Nullable
private static SnapshotMetadata extractMetadata(final File file) {
    String name = file.getName();
    int sequenceNumberEndIndex = name.lastIndexOf('-');
    int persistenceIdEndIndex = name.lastIndexOf('-', sequenceNumberEndIndex - 1);
    if (PERSISTENCE_ID_START_INDEX >= persistenceIdEndIndex) {
        return null;
    }

    try {
        // Since the persistenceId is url encoded in the filename, we need
        // to decode relevant filename's part to obtain persistenceId back
        String persistenceId = decode(name.substring(PERSISTENCE_ID_START_INDEX, persistenceIdEndIndex));
        long sequenceNumber = Long.parseLong(name.substring(persistenceIdEndIndex + 1, sequenceNumberEndIndex));
        long timestamp = Long.parseLong(name.substring(sequenceNumberEndIndex + 1));
        return new SnapshotMetadata(persistenceId, sequenceNumber, timestamp);
    } catch (NumberFormatException e) {
        return null;
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:21,代码来源:LocalSnapshotStore.java

示例7: testDoLoadAsyncWithRetry

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Test
public void testDoLoadAsyncWithRetry() throws IOException  {
    createSnapshotFile(PERSISTENCE_ID, "one", 0, 1000);
    createSnapshotFile(PERSISTENCE_ID, null, 1, 2000);

    SnapshotMetadata metadata = new SnapshotMetadata(PERSISTENCE_ID, 0, 1000);

    JavaTestKit probe = new JavaTestKit(system);
    snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID,
            SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef());
    LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class);
    Option<SelectedSnapshot> possibleSnapshot = result.snapshot();

    assertEquals("SelectedSnapshot present", TRUE, possibleSnapshot.nonEmpty());
    assertEquals("SelectedSnapshot metadata", metadata, possibleSnapshot.get().metadata());
    assertEquals("SelectedSnapshot snapshot", "one", possibleSnapshot.get().snapshot());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:LocalSnapshotStoreTest.java

示例8: testDoLoadAsyncWithAkkaSerializedSnapshot

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Test
public void testDoLoadAsyncWithAkkaSerializedSnapshot() throws IOException {
    SnapshotSerializer snapshotSerializer = new SnapshotSerializer((ExtendedActorSystem) system);

    String name = toSnapshotName(PERSISTENCE_ID, 1, 1000);
    try (FileOutputStream fos = new FileOutputStream(new File(SNAPSHOT_DIR, name))) {
        fos.write(snapshotSerializer.toBinary(new Snapshot("one")));
    }

    SnapshotMetadata metadata = new SnapshotMetadata(PERSISTENCE_ID, 1, 1000);

    JavaTestKit probe = new JavaTestKit(system);
    snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID,
            SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef());
    LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class);
    Option<SelectedSnapshot> possibleSnapshot = result.snapshot();

    assertEquals("SelectedSnapshot present", TRUE, possibleSnapshot.nonEmpty());
    assertEquals("SelectedSnapshot metadata", metadata, possibleSnapshot.get().metadata());
    assertEquals("SelectedSnapshot snapshot", "one", possibleSnapshot.get().snapshot());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:LocalSnapshotStoreTest.java

示例9: testRecoveryAfterRestartFrontendIdMismatch

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Test
public void testRecoveryAfterRestartFrontendIdMismatch() throws Exception {
    system.stop(mockedActor);
    //start actor again
    mockedActor = system.actorOf(MockedActor.props(id, initialBehavior));
    probe.expectMsgClass(MockedSnapshotStore.LoadRequest.class);
    //offer snapshot with incorrect client id
    final SnapshotMetadata metadata = saveRequest.getMetadata();
    final FrontendIdentifier anotherFrontend = FrontendIdentifier.create(MemberName.forName("another"),
            FrontendType.forName("type-2"));
    final ClientIdentifier incorrectClientId = ClientIdentifier.create(anotherFrontend, 0);
    probe.watch(mockedActor);
    probe.reply(Optional.of(new SelectedSnapshot(metadata, incorrectClientId)));
    //actor should be stopped
    probe.expectTerminated(mockedActor, TIMEOUT);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:ActorBehaviorTest.java

示例10: doSaveAsync

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Override
public Future<Void> doSaveAsync(SnapshotMetadata metadata, Object snapshot) {
    return storage.execute(metadata.persistenceId(), cache, (entityIdParam, cacheParam) -> {
        if (log.isDebugEnabled()) {
            log.debug("doSaveAsync '{}' ({})", metadata.persistenceId(), metadata.sequenceNr());
        }
        SnapshotItem item = convert(metadata, snapshot);
        cache.put(item.getSequenceNr(), item);
        return null;
    });
}
 
开发者ID:Romeh,项目名称:akka-persistance-ignite,代码行数:12,代码来源:IgniteSnapshotStore.java

示例11: doDeleteAsync

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Override
public Future<Void> doDeleteAsync(SnapshotMetadata metadata) {
    return storage.execute(metadata.persistenceId(), cache, (entityIdParam, cacheParam) -> {
        if (log.isDebugEnabled()) {
            log.debug("doDeleteAsync '{}' ({})", metadata.persistenceId(), metadata.sequenceNr());
        }
        cache.remove(metadata.sequenceNr());
        return null;
    });
}
 
开发者ID:Romeh,项目名称:akka-persistance-ignite,代码行数:11,代码来源:IgniteSnapshotStore.java

示例12: addSnapshot

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
public static void addSnapshot(String persistentId, Object snapshot) {
    List<StoredSnapshot> snapshotList = snapshots.computeIfAbsent(persistentId, k -> new ArrayList<>());

    synchronized (snapshotList) {
        snapshotList.add(new StoredSnapshot(new SnapshotMetadata(persistentId, snapshotList.size(),
                System.currentTimeMillis()), snapshot));
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:9,代码来源:InMemorySnapshotStore.java

示例13: testDataRecoveredWithPersistenceDisabled

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Test
public void testDataRecoveredWithPersistenceDisabled() {
    doNothing().when(mockCohort).applyRecoverySnapshot(anyObject());
    doReturn(false).when(mockPersistence).isRecoveryApplicable();
    doReturn(10L).when(mockPersistentProvider).getLastSequenceNumber();

    Snapshot snapshot = Snapshot.create(new MockSnapshotState(Arrays.asList(new MockPayload("1"))),
            Collections.<ReplicatedLogEntry>emptyList(), 3, 1, 3, 1, -1, null, null);
    SnapshotOffer snapshotOffer = new SnapshotOffer(new SnapshotMetadata("test", 6, 12345), snapshot);

    sendMessageToSupport(snapshotOffer);

    sendMessageToSupport(new UpdateElectionTerm(5, "member2"));

    sendMessageToSupport(new SimpleReplicatedLogEntry(4, 1, new MockRaftActorContext.MockPayload("4")));
    sendMessageToSupport(new SimpleReplicatedLogEntry(5, 1, new MockRaftActorContext.MockPayload("5")));

    sendMessageToSupport(new ApplyJournalEntries(4));

    sendMessageToSupport(new DeleteEntries(5));

    assertEquals("Journal log size", 0, context.getReplicatedLog().size());
    assertEquals("Last index", -1, context.getReplicatedLog().lastIndex());
    assertEquals("Last applied", -1, context.getLastApplied());
    assertEquals("Commit index", -1, context.getCommitIndex());
    assertEquals("Snapshot term", -1, context.getReplicatedLog().getSnapshotTerm());
    assertEquals("Snapshot index", -1, context.getReplicatedLog().getSnapshotIndex());

    assertEquals("Current term", 5, context.getTermInformation().getCurrentTerm());
    assertEquals("Voted For", "member2", context.getTermInformation().getVotedFor());

    sendMessageToSupport(RecoveryCompleted.getInstance(), true);

    verify(mockCohort, never()).applyRecoverySnapshot(anyObject());
    verify(mockCohort, never()).getRestoreFromSnapshot();
    verifyNoMoreInteractions(mockCohort);

    verify(mockPersistentProvider).deleteMessages(10L);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:40,代码来源:RaftActorRecoverySupportTest.java

示例14: testOnSaveSnapshotSuccess

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Test
public void testOnSaveSnapshotSuccess() {

    long sequenceNumber = 100;
    long timeStamp = 1234L;
    sendMessageToSupport(new SaveSnapshotSuccess(new SnapshotMetadata("foo", sequenceNumber, timeStamp)));

    verify(mockSnapshotManager).commit(eq(sequenceNumber), eq(timeStamp));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:RaftActorSnapshotMessageSupportTest.java

示例15: testOnSaveSnapshotFailure

import akka.persistence.SnapshotMetadata; //导入依赖的package包/类
@Test
public void testOnSaveSnapshotFailure() {

    sendMessageToSupport(new SaveSnapshotFailure(new SnapshotMetadata("foo", 100, 1234L),
            new Throwable("mock")));

    verify(mockSnapshotManager).rollback();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:9,代码来源:RaftActorSnapshotMessageSupportTest.java


注:本文中的akka.persistence.SnapshotMetadata类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。