Package org.infinispan.loaders.bucket

Examples of org.infinispan.loaders.bucket.Bucket


         for (final File bucketFile : root.listFiles()) {
            if (multiThreadedPurge) {
               purgerService.execute(new Runnable() {
                  @Override
                  public void run() {
                     Bucket bucket;
                     try {
                        if ((bucket = loadBucket(bucketFile)) != null && bucket.removeExpiredEntries())
                           updateBucket(bucket);
                     } catch (CacheLoaderException e) {
                        log.warn("Problems purging file " + bucketFile, e);
                     }
                  }
               });
            } else {
               Bucket bucket;
               if ((bucket = loadBucket(bucketFile)) != null && bucket.removeExpiredEntries()) updateBucket(bucket);
            }
         }
      } finally {
         releaseGlobalLock(false);
         if (trace) log.trace("Exit purgeInternal()");
View Full Code Here


      boolean created = file.createNewFile();
      assert created;
   }

   public void testBucketRemoval() throws Exception {
      Bucket b;
      InternalCacheEntry se = TestInternalCacheEntryFactory.create("test", "value");
      fcs.store(se);
      b = fcs.loadBucketContainingKey("test");
      assert b != null;

      assert !b.getEntries().isEmpty();

      assert new File(fcs.root, b.getBucketIdAsString()).exists();

      b.removeEntry("test");
      assert b.getEntries().isEmpty();

      fcs.updateBucket(b);
      checkBucketExists(b);
   }
View Full Code Here

   public void testCacheStoreRebootable() throws Exception {
      String key = "testCacheStoreRebootable";
      InternalCacheEntry se = TestInternalCacheEntryFactory.create(key, "initialValue");
      fcs.store(se);
      Bucket b = fcs.loadBucketContainingKey(key);

      //stop and restart it:
      fcs.stop();
      fcs.start();

      InternalCacheEntry entry = b.getEntry(key);
      entry.setValue("updatedValue");
      fcs.updateBucket(b);
      assert "updatedValue".equals(fcs.load(key).getValue());
   }
View Full Code Here

   public void testBucketMarshalling() throws Exception {
      ImmortalCacheEntry entry1 = (ImmortalCacheEntry) TestInternalCacheEntryFactory.create("key", "value", System.currentTimeMillis() - 1000, -1, System.currentTimeMillis(), -1);
      MortalCacheEntry entry2 = (MortalCacheEntry) TestInternalCacheEntryFactory.create("key", "value", System.currentTimeMillis() - 1000, 200000, System.currentTimeMillis(), -1);
      TransientCacheEntry entry3 = (TransientCacheEntry) TestInternalCacheEntryFactory.create("key", "value", System.currentTimeMillis() - 1000, -1, System.currentTimeMillis(), 4000000);
      TransientMortalCacheEntry entry4 = (TransientMortalCacheEntry) TestInternalCacheEntryFactory.create("key", "value", System.currentTimeMillis() - 1000, 200000, System.currentTimeMillis(), 4000000);
      Bucket b = new Bucket();
      b.setBucketId(0);
      b.addEntry(entry1);
      b.addEntry(entry2);
      b.addEntry(entry3);
      b.addEntry(entry4);

      byte[] bytes = marshaller.objectToByteBuffer(b);
      Bucket rb = (Bucket) marshaller.objectFromByteBuffer(bytes);
      assert rb.getEntries().equals(b.getEntries()) : "Writen[" + b.getEntries() + "] and read[" + rb.getEntries() + "] objects should be the same";
   }
View Full Code Here

   protected Set<InternalCacheEntry> loadAllLockSafe() throws CacheLoaderException {
      Set<InternalCacheEntry> result = new HashSet<InternalCacheEntry>();

      for (Map.Entry<String, Blob> entry : ctx.createBlobMap(containerName).entrySet()) {
         Bucket bucket = readFromBlob(entry.getValue(), entry.getKey());
         if (bucket.removeExpiredEntries())
            updateBucket(bucket);
         result.addAll(bucket.getStoredEntries());
      }
      return result;
   }
View Full Code Here

      return readFromBlob(blobStore.getBlob(containerName, encodeBucketName(hash)), hash);
   }

   private void purge(BlobMap blobMap) throws CacheLoaderException {
      for (Map.Entry<String, Blob> entry : blobMap.entrySet()) {
         Bucket bucket = readFromBlob(entry.getValue(), entry.getKey());
         if (bucket.removeExpiredEntries())
            updateBucket(bucket);
      }
   }
View Full Code Here

   private Bucket readFromBlob(Blob blob, String bucketName) throws CacheLoaderException {
      if (blob == null)
         return null;
      try {
         Bucket bucket = (Bucket) marshaller.objectFromInputStream(blob.getContent());
         if (bucket != null)
            bucket.setBucketName(bucketName);
         return bucket;
      } catch (Exception e) {
         throw convertToCacheLoaderException("Unable to read blob", e);
      }
   }
View Full Code Here

   protected void loopOverBuckets(BucketHandler handler) throws CacheLoaderException {
      try {
         File[] listFiles;
         if (root != null && (listFiles = root.listFiles()) != null) {
            for (File bucketFile : listFiles) {
               Bucket bucket = loadBucket(bucketFile);
               if (handler.handle(bucket)) {
                  break;
               }
            }
         }
View Full Code Here

                  @Override
                  public void run() {
                     Integer bucketKey = Integer.valueOf(bucketFile.getName());
                     boolean lockAcquired = false;
                     try {
                        Bucket bucket = loadBucket(bucketFile);

                        if (bucket != null) {
                           if (bucket.removeExpiredEntries()) {
                              lockForWriting(bucketKey);
                              lockAcquired = true;
                           }
                           updateBucket(bucket);
                        }
                     } catch (InterruptedException ie) {
                        if (log.isDebugEnabled()) {
                           log.debug("Interrupted, so finish work.");
                        }
                     } catch (CacheLoaderException e) {
                        log.problemsPurgingFile(bucketFile, e);
                     } finally {
                        if (lockAcquired)
                           unlock(bucketKey);
                     }
                  }
               });
            } else {
               Integer bucketKey = Integer.valueOf(bucketFile.getName());
               boolean lockAcquired = false;
               try {
                  Bucket bucket = loadBucket(bucketFile);

                  if (bucket != null) {
                     if (bucket.removeExpiredEntries()) {
                        lockForWriting(bucketKey);
                        lockAcquired = true;
                     }
                     updateBucket(bucket);
                  }
View Full Code Here

         return null;
      }
   }

   protected Bucket loadBucket(File bucketFile) throws CacheLoaderException, InterruptedException {
      Bucket bucket = null;
      if (bucketFile.exists()) {
         if (trace) {
            log.trace("Found bucket file: '" + bucketFile + "'");
         }
         InputStream is = null;
         try {
            // It could happen that the output buffer might not have been
            // flushed, so just in case, flush it to be able to read it.
            fileSync.flush(bucketFile);
            if (bucketFile.length() == 0) {
               // short circuit
               return null;
            }
            is = new FileInputStream(bucketFile);
            bucket = (Bucket) objectFromInputStreamInReentrantMode(is);
         } catch (InterruptedException ie) {
            throw ie;
         } catch (Exception e) {
            log.errorReadingFromFile(bucketFile.getAbsoluteFile(), e);
            throw new CacheLoaderException("Error while reading from file", e);
         } finally {
            safeClose(is);
         }
      }
      if (bucket != null) {
         bucket.setBucketId(bucketFile.getName());
      }
      return bucket;
   }
View Full Code Here

TOP

Related Classes of org.infinispan.loaders.bucket.Bucket

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.