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


Java StorageLevel类代码示例

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


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

示例1: RaftStorage

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
private RaftStorage(
    String prefix,
    StorageLevel storageLevel,
    File directory,
    Serializer serializer,
    int maxSegmentSize,
    int maxEntriesPerSegment,
    boolean dynamicCompaction,
    double freeDiskBuffer,
    boolean flushOnCommit,
    boolean retainStaleSnapshots) {
  this.prefix = prefix;
  this.storageLevel = storageLevel;
  this.directory = directory;
  this.serializer = serializer;
  this.maxSegmentSize = maxSegmentSize;
  this.maxEntriesPerSegment = maxEntriesPerSegment;
  this.dynamicCompaction = dynamicCompaction;
  this.freeDiskBuffer = freeDiskBuffer;
  this.flushOnCommit = flushOnCommit;
  this.retainStaleSnapshots = retainStaleSnapshots;
  this.statistics = new StorageStatistics(directory);
  directory.mkdirs();
}
 
开发者ID:atomix,项目名称:atomix,代码行数:25,代码来源:RaftStorage.java

示例2: MetaStore

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
public MetaStore(RaftStorage storage, Serializer serializer) {
  this.serializer = checkNotNull(serializer, "serializer cannot be null");

  if (!(storage.directory().isDirectory() || storage.directory().mkdirs())) {
    throw new IllegalArgumentException(String.format("Can't create storage directory [%s].", storage.directory()));
  }

  // Note that for raft safety, irrespective of the storage level, <term, vote> metadata is always persisted on disk.
  File metaFile = new File(storage.directory(), String.format("%s.meta", storage.prefix()));
  metadataBuffer = FileBuffer.allocate(metaFile, 12);

  if (storage.storageLevel() == StorageLevel.MEMORY) {
    configurationBuffer = HeapBuffer.allocate(32);
  } else {
    File confFile = new File(storage.directory(), String.format("%s.conf", storage.prefix()));
    configurationBuffer = FileBuffer.allocate(confFile, 32);
  }
}
 
开发者ID:atomix,项目名称:atomix,代码行数:19,代码来源:MetaStore.java

示例3: createServer

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
/**
 * Creates a Raft server.
 */
private RaftServer createServer(NodeId nodeId) {
  RaftServer.Builder builder = RaftServer.builder(nodeId)
      .withClusterService(mock(ClusterService.class))
      .withProtocol(protocolFactory.newServerProtocol(nodeId))
      .withStorage(RaftStorage.builder()
          .withStorageLevel(StorageLevel.DISK)
          .withDirectory(new File(String.format("target/test-logs/%s", nodeId)))
          .withSerializer(storageSerializer)
          .withMaxSegmentSize(1024 * 10)
          .withMaxEntriesPerSegment(10)
          .build())
      .addPrimitiveType(TestPrimitiveType.INSTANCE);

  RaftServer server = builder.build();
  servers.add(server);
  return server;
}
 
开发者ID:atomix,项目名称:atomix,代码行数:21,代码来源:RaftTest.java

示例4: SegmentedJournal

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
public SegmentedJournal(
    String name,
    StorageLevel storageLevel,
    File directory,
    Serializer serializer,
    int maxSegmentSize,
    int maxEntriesPerSegment) {
  this.name = checkNotNull(name, "name cannot be null");
  this.storageLevel = checkNotNull(storageLevel, "storageLevel cannot be null");
  this.directory = checkNotNull(directory, "directory cannot be null");
  this.serializer = checkNotNull(serializer, "serializer cannot be null");
  this.maxSegmentSize = maxSegmentSize;
  this.maxEntriesPerSegment = maxEntriesPerSegment;
  open();
  this.writer = openWriter();
}
 
开发者ID:atomix,项目名称:atomix,代码行数:17,代码来源:SegmentedJournal.java

示例5: buildServer

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
private RaftServer buildServer() {
    RaftServer.Builder builder = RaftServer.newBuilder(localMemberId)
            .withName(String.format("partition-%s", partition.getId()))
            .withProtocol(new RaftServerCommunicator(
                    String.format("partition-%s-%s", partition.getId(), partition.getVersion()),
                    Serializer.using(StorageNamespaces.RAFT_PROTOCOL),
                    clusterCommunicator))
            .withElectionTimeout(Duration.ofMillis(ELECTION_TIMEOUT_MILLIS))
            .withHeartbeatInterval(Duration.ofMillis(HEARTBEAT_INTERVAL_MILLIS))
            .withElectionThreshold(ELECTION_THRESHOLD)
            .withStorage(RaftStorage.newBuilder()
                    .withPrefix(String.format("partition-%s", partition.getId()))
                    .withStorageLevel(StorageLevel.DISK)
                    .withFlushOnCommit()
                    .withSerializer(new AtomixSerializerAdapter(Serializer.using(StorageNamespaces.RAFT_STORAGE)))
                    .withDirectory(partition.getDataFolder())
                    .withMaxSegmentSize(MAX_SEGMENT_SIZE)
                    .build());
    StoragePartition.RAFT_SERVICES.forEach(builder::addService);
    return builder.build();
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:22,代码来源:StoragePartitionServer.java

示例6: createServer

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
/**
 * Creates a Raft server.
 */
private RaftServer createServer(RaftMember member) {
    RaftServer.Builder builder = RaftServer.newBuilder(member.memberId())
            .withType(member.getType())
            .withProtocol(new RaftServerCommunicator(
                    "partition-1",
                    Serializer.using(StorageNamespaces.RAFT_PROTOCOL),
                    communicationServiceFactory.newCommunicationService(NodeId.nodeId(member.memberId().id()))))
            .withStorage(RaftStorage.newBuilder()
                    .withStorageLevel(StorageLevel.MEMORY)
                    .withDirectory(new File(String.format("target/primitives/%s", member.memberId())))
                    .withSerializer(new AtomixSerializerAdapter(Serializer.using(StorageNamespaces.RAFT_STORAGE)))
                    .withMaxSegmentSize(1024 * 1024)
                    .build())
            .addService("test", this::createService);

    RaftServer server = builder.build();
    servers.add(server);
    return server;
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:23,代码来源:AtomixTestBase.java

示例7: buildCorePartitionGroup

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
@Override
protected ManagedPartitionGroup buildCorePartitionGroup() {
  return RaftPartitionGroup.builder("core")
      .withStorageLevel(StorageLevel.MEMORY)
      .withDataDirectory(new File(dataDirectory, "core"))
      .withNumPartitions(1)
      .build();
}
 
开发者ID:atomix,项目名称:atomix-vertx,代码行数:9,代码来源:AtomixVertxTestHelper.java

示例8: buildPartitionService

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
@Override
protected ManagedPartitionService buildPartitionService() {
  if (partitionGroups.isEmpty()) {
    partitionGroups.add(RaftPartitionGroup.builder(COORDINATION_GROUP_NAME)
        .withStorageLevel(StorageLevel.MEMORY)
        .withDataDirectory(new File(dataDirectory, "coordination"))
        .withNumPartitions(numCoordinationPartitions > 0 ? numCoordinationPartitions : bootstrapNodes.size())
        .withPartitionSize(coordinationPartitionSize)
        .build());
    partitionGroups.add(PrimaryBackupPartitionGroup.builder(DATA_GROUP_NAME)
        .withNumPartitions(numDataPartitions)
        .build());
  }
  return new DefaultPartitionService(partitionGroups);
}
 
开发者ID:atomix,项目名称:atomix-vertx,代码行数:16,代码来源:AtomixVertxTestHelper.java

示例9: newSnapshot

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
/**
 * Creates a new snapshot buffer.
 */
private Snapshot newSnapshot(String serviceName, SnapshotDescriptor descriptor, StorageLevel storageLevel) {
  if (storageLevel == StorageLevel.MEMORY) {
    return createMemorySnapshot(serviceName, descriptor);
  } else {
    return createDiskSnapshot(serviceName, descriptor);
  }
}
 
开发者ID:atomix,项目名称:atomix,代码行数:11,代码来源:SnapshotStore.java

示例10: persist

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
@Override
public Snapshot persist() {
  if (store.storage.storageLevel() != StorageLevel.MEMORY) {
    try (Snapshot newSnapshot = store.newSnapshot(serviceId(), name, index(), timestamp())) {
      try (SnapshotWriter newSnapshotWriter = newSnapshot.openWriter()) {
        buffer.flip().skip(SnapshotDescriptor.BYTES);
        newSnapshotWriter.write(buffer.array(), buffer.position(), buffer.remaining());
      }
      return newSnapshot;
    }
  }
  return this;
}
 
开发者ID:atomix,项目名称:atomix,代码行数:14,代码来源:MemorySnapshot.java

示例11: createSnapshotStore

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
/**
 * Returns a new snapshot store.
 */
protected SnapshotStore createSnapshotStore() {
  RaftStorage storage = RaftStorage.builder()
      .withPrefix("test")
      .withStorageLevel(StorageLevel.MEMORY)
      .build();
  return new SnapshotStore(storage);
}
 
开发者ID:atomix,项目名称:atomix,代码行数:11,代码来源:MemorySnapshotStoreTest.java

示例12: createSnapshotStore

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
/**
 * Returns a new snapshot store.
 */
protected SnapshotStore createSnapshotStore() {
  RaftStorage storage = RaftStorage.builder()
      .withPrefix("test")
      .withDirectory(new File(String.format("target/test-logs/%s", testId)))
      .withStorageLevel(StorageLevel.DISK)
      .build();
  return new SnapshotStore(storage);
}
 
开发者ID:atomix,项目名称:atomix,代码行数:12,代码来源:FileSnapshotStoreTest.java

示例13: createJournal

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
private Journal<TestEntry> createJournal() {
  return SegmentedJournal.<TestEntry>builder()
      .withName("test")
      .withSerializer(serializer)
      .withStorageLevel(StorageLevel.MEMORY)
      .build();
}
 
开发者ID:atomix,项目名称:atomix,代码行数:8,代码来源:JournalTest.java

示例14: testSnapshot

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testSnapshot() throws Exception {
    SnapshotStore store = new SnapshotStore(RaftStorage.newBuilder()
            .withPrefix("test")
            .withStorageLevel(StorageLevel.MEMORY)
            .build());
    Snapshot snapshot = store.newSnapshot(ServiceId.from(1), "test", 2, new WallClockTimestamp());

    AtomixConsistentSetMultimapService service = new AtomixConsistentSetMultimapService();
    service.put(new DefaultCommit<>(
            2,
            PUT,
            new AtomixConsistentSetMultimapOperations.Put(
                    "foo", Collections.singletonList("Hello world!".getBytes()), Match.ANY),
            mock(RaftSessionContext.class),
            System.currentTimeMillis()));

    try (SnapshotWriter writer = snapshot.openWriter()) {
        service.snapshot(writer);
    }

    snapshot.complete();

    service = new AtomixConsistentSetMultimapService();
    try (SnapshotReader reader = snapshot.openReader()) {
        service.install(reader);
    }

    Versioned<Collection<? extends byte[]>> value = service.get(new DefaultCommit<>(
            2,
            GET,
            new AtomixConsistentSetMultimapOperations.Get("foo"),
            mock(RaftSessionContext.class),
            System.currentTimeMillis()));
    assertNotNull(value);
    assertEquals(1, value.value().size());
    assertArrayEquals("Hello world!".getBytes(), value.value().iterator().next());
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:40,代码来源:AtomixConsistentSetMultimapServiceTest.java

示例15: testSnapshot

import io.atomix.storage.StorageLevel; //导入依赖的package包/类
@Test
public void testSnapshot() throws Exception {
    SnapshotStore store = new SnapshotStore(RaftStorage.newBuilder()
            .withPrefix("test")
            .withStorageLevel(StorageLevel.MEMORY)
            .build());
    Snapshot snapshot = store.newSnapshot(ServiceId.from(1), "test", 2, new WallClockTimestamp());

    AtomixAtomicCounterMapService service = new AtomixAtomicCounterMapService();
    service.put(new DefaultCommit<>(
            2,
            PUT,
            new AtomixAtomicCounterMapOperations.Put("foo", 1),
            mock(RaftSessionContext.class),
            System.currentTimeMillis()));

    try (SnapshotWriter writer = snapshot.openWriter()) {
        service.snapshot(writer);
    }

    snapshot.complete();

    service = new AtomixAtomicCounterMapService();
    try (SnapshotReader reader = snapshot.openReader()) {
        service.install(reader);
    }

    long value = service.get(new DefaultCommit<>(
            2,
            GET,
            new AtomixAtomicCounterMapOperations.Get("foo"),
            mock(RaftSessionContext.class),
            System.currentTimeMillis()));
    assertEquals(1, value);
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:36,代码来源:AtomixAtomicCounterMapServiceTest.java


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