Exemple #1
0
  @Override
  public void start() throws CacheLoaderException {
    final Marshaller marshaller;
    if (configuration.marshaller() != null) {
      marshaller =
          Util.getInstance(
              configuration.marshaller(), ctx.getCache().getCacheConfiguration().classLoader());
    } else if (configuration.hotRodWrapping()) {
      marshaller = new HotRodEntryMarshaller(ctx.getByteBufferFactory());
    } else if (configuration.rawValues()) {
      marshaller = new GenericJBossMarshaller();
    } else {
      marshaller = ctx.getMarshaller();
    }
    ConfigurationBuilder builder = buildRemoteConfiguration(configuration, marshaller);
    remoteCacheManager = new RemoteCacheManager(builder.build());

    if (configuration.remoteCacheName().equals(BasicCacheContainer.DEFAULT_CACHE_NAME))
      remoteCache = remoteCacheManager.getCache();
    else remoteCache = remoteCacheManager.getCache(configuration.remoteCacheName());
    if (configuration.rawValues() && iceFactory == null) {
      iceFactory =
          ctx.getCache()
              .getAdvancedCache()
              .getComponentRegistry()
              .getComponent(InternalEntryFactory.class);
    }
  }
 @Override
 public void init(InitializationContext ctx) {
   this.ctx = ctx;
   cache = ctx.getCache().getAdvancedCache();
   rpcManager = cache.getRpcManager();
   this.configuration = ctx.getConfiguration();
 }
  @Override
  public void start() {
    try {
      // open the data file
      String location = configuration.location();
      if (location == null || location.trim().length() == 0)
        location = "Infinispan-SingleFileStore";

      file = new File(location, ctx.getCache().getName() + ".dat");
      if (!file.exists()) {
        File dir = file.getParentFile();
        if (!dir.mkdirs() && !dir.exists()) {
          throw log.directoryCannotBeCreated(dir.getAbsolutePath());
        }
      }
      channel = new RandomAccessFile(file, "rw").getChannel();

      // initialize data structures
      entries = newEntryMap();
      freeList = Collections.synchronizedSortedSet(new TreeSet<FileEntry>());

      // check file format and read persistent state if enabled for the cache
      byte[] header = new byte[MAGIC.length];
      if (channel.read(ByteBuffer.wrap(header), 0) == MAGIC.length
          && Arrays.equals(MAGIC, header)) {
        rebuildIndex();
        processFreeEntries();
      } else clear(); // otherwise (unknown file format or no preload) just reset the file

      // Initialize the fragmentation factor
      fragmentationFactor = configuration.fragmentationFactor();
    } catch (Exception e) {
      throw new PersistenceException(e);
    }
  }
  private <Key> Map<Key, FileEntry> newEntryMap() {
    // only use LinkedHashMap (LRU) for entries when cache store is bounded
    final Map<Key, FileEntry> entryMap;
    Equivalence<Object> keyEq =
        ctx.getCache().getCacheConfiguration().dataContainer().keyEquivalence();
    if (configuration.maxEntries() > 0)
      entryMap = CollectionFactory.makeLinkedMap(16, 0.75f, true, null, null);
    else entryMap = CollectionFactory.makeMap(keyEq, AnyEquivalence.<FileEntry>getInstance());

    return Collections.synchronizedMap(entryMap);
  }
Exemple #5
0
 @Override
 public void init(InitializationContext ctx) {
   this.configuration = ctx.getConfiguration();
   this.emfRegistry =
       ctx.getCache()
           .getAdvancedCache()
           .getComponentRegistry()
           .getGlobalComponentRegistry()
           .getComponent(EntityManagerFactoryRegistry.class);
   this.marshallerEntryFactory = ctx.getMarshalledEntryFactory();
   this.marshaller = ctx.getMarshaller();
   this.timeService = ctx.getTimeService();
 }
Exemple #6
0
  @Override
  public void start() {
    try {

      String name = ctx.getCache().getName();
      EmbeddedCacheManager cacheManager = ctx.getCache().getCacheManager();
      Cache<?, ?> metaCache = cacheManager.getCache(name + "-meta");
      Cache<?, ?> dataCache = cacheManager.getCache(name + "-chunk");

      BuildContext bcontext =
          DirectoryBuilder.newDirectoryInstance(metaCache, dataCache, metaCache, name);
      bcontext.chunkSize(1024 * 1024);
      Directory directory = bcontext.create();
      this.central =
          CentralConfig.oldFromDir(directory)
              .indexConfigBuilder()
              .executorService(new WithinThreadExecutor())
              .build();

      this.configuration.store(this);
    } catch (Exception e) {
      throw new PersistenceException(e);
    }
  }
  @Override
  public void stop() {
    try {
      if (channel != null) {
        log.tracef(
            "Stopping store %s, size = %d, file size = %d",
            ctx.getCache().getName(), entries.size(), channel.size());

        // reset state
        channel.close();
        channel = null;
        entries = null;
        freeList = null;
        filePos = MAGIC.length;
      }
    } catch (Exception e) {
      throw new PersistenceException(e);
    }
  }
Exemple #8
0
  @Override
  public void process(
      KeyFilter filter,
      final CacheLoaderTask task,
      Executor executor,
      final boolean fetchValue,
      final boolean fetchMetadata) {

    if (true) return;

    filter = PersistenceUtil.notNull(filter);
    Set<Object> keysToLoad = new HashSet<Object>(ctx.getCache().keySet());

    ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(executor);

    final TaskContextImpl taskContext = new TaskContextImpl();
    for (final Object key : keysToLoad) {
      if (taskContext.isStopped()) break;

      eacs.submit(
          new Callable<Void>() {
            @Override
            public Void call() throws Exception {
              try {
                final MarshalledEntry marshalledEntry = _load(key, fetchValue, fetchMetadata);
                if (marshalledEntry != null) {
                  Debug.line(task, marshalledEntry, fetchValue, fetchMetadata);
                  task.processEntry(marshalledEntry, taskContext);
                }
                return null;
              } catch (Exception e) {
                log.errorExecutingParallelStoreTask(e);
                throw e;
              }
            }
          });
    }
    eacs.waitUntilAllCompleted();
    if (eacs.isExceptionThrown()) {
      throw new PersistenceException("Execution exception!", eacs.getFirstException());
    }
  }