コード例 #1
0
    @Override
    public <K, V> OffHeapStore<K, V> createStore(
        Configuration<K, V> storeConfig, ServiceConfiguration<?>... serviceConfigs) {
      TimeSourceConfiguration timeSourceConfig =
          findSingletonAmongst(TimeSourceConfiguration.class, (Object[]) serviceConfigs);
      TimeSource timeSource =
          timeSourceConfig != null ? timeSourceConfig.getTimeSource() : SystemTimeSource.INSTANCE;

      if (serviceProvider == null) {
        throw new RuntimeException("ServiceProvider is null.");
      }
      SerializationProvider serializationProvider =
          serviceProvider.findService(SerializationProvider.class);
      Serializer<K> keySerializer =
          serializationProvider.createKeySerializer(
              storeConfig.getKeyType(), storeConfig.getClassLoader(), serviceConfigs);
      Serializer<V> valueSerializer =
          serializationProvider.createValueSerializer(
              storeConfig.getValueType(), storeConfig.getClassLoader(), serviceConfigs);

      ResourcePool offHeapPool =
          storeConfig.getResourcePools().getPoolForResource(ResourceType.Core.OFFHEAP);
      if (!(offHeapPool.getUnit() instanceof MemoryUnit)) {
        throw new IllegalArgumentException("OffHeapStore only supports resources with memory unit");
      }
      MemoryUnit unit = (MemoryUnit) offHeapPool.getUnit();

      OffHeapStore<K, V> offHeapStore =
          new OffHeapStore<K, V>(
              storeConfig,
              keySerializer,
              valueSerializer,
              timeSource,
              unit.toBytes(offHeapPool.getSize()));
      createdStores.add(offHeapStore);
      return offHeapStore;
    }