Package org.infinispan.lucene

Examples of org.infinispan.lucene.FileMetadata


   public void testAutoChunkingOnLargeFiles() throws CacheLoaderException {
      FileCacheKey k = new FileCacheKey(INDEX_NAME, FILE_NAME);
      DirectoryLoaderAdaptor adaptor = new DirectoryLoaderAdaptor(new InternalDirectoryContractImpl(), INDEX_NAME, AUTO_BUFFER);
      Object loaded = adaptor.load(k);
      AssertJUnit.assertTrue(loaded instanceof FileMetadata);
      FileMetadata metadata = (FileMetadata)loaded;
      AssertJUnit.assertEquals(23, metadata.getLastModified());
      AssertJUnit.assertEquals(TEST_SIZE, metadata.getSize());
      AssertJUnit.assertEquals(AUTO_BUFFER, metadata.getBufferSize());
   }
View Full Code Here


      final String fileName = key.getFileName();
      final long fileModified = directory.fileModified(fileName);
      final long fileLength = directory.fileLength(fileName);
      // We're forcing the buffer size of a to-be-read segment to the full file size:
      final int bufferSize = (int) Math.min(fileLength, (long)autoChunkSize);
      final FileMetadata meta = new FileMetadata(bufferSize);
      meta.setLastModified(fileModified);
      meta.setSize(fileLength);
      return meta;
   }
View Full Code Here

    /**
     * Used by Lucene v3.x only
     */
    long fileModified(final String name) {
       final FileMetadata fileMetadata = fileOps.getFileMetadata(name);
       if (fileMetadata == null) {
          return 0L;
       }
       else {
          return fileMetadata.getLastModified();
       }
    }
View Full Code Here

    /**
     * Used by Lucene v3.x only
     */
    void touchFile(final String fileName) {
       final FileMetadata file = fileOps.getFileMetadata(fileName);
       if (file != null) {
          final FileCacheKey key = new FileCacheKey(indexName, fileName);
          file.touch();
          metadataCache.put(key, file);
       }
    }
View Full Code Here

       }
    }

    void renameFile(final String from, final String to) {
       final FileCacheKey fromKey = new FileCacheKey(indexName, from);
       final FileMetadata metadata = metadataCache.get(fromKey);
       final int bufferSize = metadata.getBufferSize();
       // preparation: copy all chunks to new keys
       int i = -1;
       Object ob;
       do {
          final ChunkCacheKey fromChunkKey = new ChunkCacheKey(indexName, from, ++i, bufferSize);
View Full Code Here

          log.tracef("Renamed file from: %s to: %s in index %s", from, to, indexName);
       }
    }

    long fileLength(final String name) {
       final FileMetadata fileMetadata = fileOps.getFileMetadata(name);
       if (fileMetadata == null) {
          return 0L; //as in FSDirectory (RAMDirectory throws an exception instead)
       }
       else {
          return fileMetadata.getSize();
       }
    }
View Full Code Here

       return new InfinispanIndexOutput(metadataCache, chunksCache, key, chunkSize, fileOps);
    }

    IndexInputContext openInput(final String name) throws IOException {
       final FileCacheKey fileKey = new FileCacheKey(indexName, name);
       final FileMetadata fileMetadata = metadataCache.get(fileKey);
       if (fileMetadata == null) {
          throw new FileNotFoundException("Error loading metadata for index file: " + fileKey);
       }
       else if (fileMetadata.getSize() <= fileMetadata.getBufferSize()) {
          //files smaller than chunkSize don't need a readLock
          return new IndexInputContext(chunksCache, fileKey, fileMetadata, null);
       }
       else {
          boolean locked = readLocks.acquireReadLock(name);
View Full Code Here

      final boolean trace = log.isTraceEnabled();
      final String indexName = readLockKey.getIndexName();
      final String filename = readLockKey.getFileName();
      FileCacheKey key = new FileCacheKey(indexName, filename);
      if (trace) log.tracef("deleting metadata: %s", key);
      FileMetadata file = (FileMetadata) metadataCache.remove(key);
      if (file != null) { //during optimization of index a same file could be deleted twice, so you could see a null here
         for (int i = 0; i < file.getNumberOfChunks(); i++) {
            ChunkCacheKey chunkKey = new ChunkCacheKey(indexName, filename, i);
            if (trace) log.tracef("deleting chunk: %s", chunkKey);
            chunksCache.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.SKIP_CACHE_LOAD).removeAsync(chunkKey);
         }
      }
View Full Code Here

   public void testMultiThreaded() {
      final Cache<Object, Object> metadata = cacheManager.getCache("metadata");
      final Cache<Object, Object> chunks = cacheManager.getCache("chunks");
      final Cache<Object, Integer> locks = cacheManager.getCache("locks");

      FileMetadata fileMetadata = new FileMetadata(10);
      fileMetadata.setSize(11); // Make it chunked otherwise no read lock will involved
      metadata.put(new FileCacheKey("indexName", "fileName"), fileMetadata);
      final LocalLockMergingSegmentReadLocker locker = new LocalLockMergingSegmentReadLocker(locks, chunks, metadata, "indexName");
      final AtomicBoolean testFailed = new AtomicBoolean(false);
      final ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS);
View Full Code Here

      FileCacheKey k = new FileCacheKey(INDEX_NAME, FILE_NAME);
      DirectoryLoaderAdaptor adaptor = new DirectoryLoaderAdaptor(mockDirectory, INDEX_NAME, AUTO_BUFFER);
      Object loaded = adaptor.load(k);
      AssertJUnit.assertTrue(loaded instanceof FileMetadata);
      FileMetadata metadata = (FileMetadata)loaded;
      AssertJUnit.assertEquals(TEST_SIZE, metadata.getSize());
      AssertJUnit.assertEquals(AUTO_BUFFER, metadata.getBufferSize());
   }
View Full Code Here

TOP

Related Classes of org.infinispan.lucene.FileMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.