Package org.infinispan.loaders.bucket

Examples of org.infinispan.loaders.bucket.Bucket$Externalizer


public class BucketExternalizer implements Externalizer {
   /** The serialVersionUID */
   private static final long serialVersionUID = -515803326753484284L;

   public void writeObject(Marshaller output, Object subject) throws IOException {
      Bucket b = (Bucket) subject;
      UnsignedNumeric.writeUnsignedInt(output, b.getNumEntries());
      for (InternalCacheEntry se : b.getEntries().values()) output.writeObject(se);
   }
View Full Code Here


      UnsignedNumeric.writeUnsignedInt(output, b.getNumEntries());
      for (InternalCacheEntry se : b.getEntries().values()) output.writeObject(se);
   }

   public Object readObject(Unmarshaller input) throws IOException, ClassNotFoundException {
      Bucket b = new Bucket();
      int numEntries = UnsignedNumeric.readUnsignedInt(input);
      for (int i = 0; i < numEntries; i++) b.addEntry((InternalCacheEntry) input.readObject());
      return b;
   }
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;
            }
         }
      } catch (InterruptedException ie) {
         if (log.isDebugEnabled()) log.debug("Interrupted, so stop looping over buckets.");
View Full Code Here

            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 (InterruptedException ie) {
                           if (log.isDebugEnabled()) log.debug("Interrupted, so finish work.");
                        } catch (CacheLoaderException e) {
                           log.warn("Problems purging file " + bucketFile, e);
                        }
                     }
                  });
               } else {
                  Bucket bucket;
                  if ((bucket = loadBucket(bucketFile)) != null && bucket.removeExpiredEntries()) updateBucket(bucket);
               }
            }
         } catch (InterruptedException ie) {
            if (log.isDebugEnabled()) log.debug("Interrupted, so stop loading and finish with purging.");
            Thread.currentThread().interrupt();
View Full Code Here

         return null;
      }
   }

   protected Bucket loadBucket(File bucketFile) throws CacheLoaderException, InterruptedException {
      Bucket bucket = null;
      if (bucketFile.exists()) {
         if (log.isTraceEnabled()) log.trace("Found bucket file: '" + bucketFile + "'");
         FileInputStream is = null;
         try {
            is = new FileInputStream(bucketFile);
            bucket = (Bucket) objectFromInputStreamInReentrantMode(is);
         } catch (InterruptedException ie) {
            throw ie;
         } catch (Exception e) {
            String message = "Error while reading from file: " + bucketFile.getAbsoluteFile();
            log.error(message, e);
            throw new CacheLoaderException(message, e);
         } finally {
            safeClose(is);
         }
      }
      if (bucket != null) {
         bucket.setBucketName(bucketFile.getName());
      }
      return bucket;
   }
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

   private boolean doPurge(File bucketFile) {
      Integer bucketKey = Integer.valueOf(bucketFile.getName());
      boolean lockAcquired = false;
      boolean interrupted = false;
      try {
         Bucket bucket = loadBucket(bucketFile);

         if (bucket != null) {
            if (bucket.removeExpiredEntries()) {
               lockForWriting(bucketKey);
               lockAcquired = true;
            }
            updateBucket(bucket);
         } else {
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

   protected Bucket loadBucket(String bucketName) throws CacheLoaderException {
      return loadBucket(new File(root, bucketName));
   }

   protected Bucket loadBucket(File bucketFile) throws CacheLoaderException {
      Bucket bucket = null;
      if (bucketFile.exists()) {
         if (log.isTraceEnabled()) log.trace("Found bucket file: '" + bucketFile + "'");
         FileInputStream is = null;
         try {
            is = new FileInputStream(bucketFile);
            bucket = (Bucket) objectFromInputStreamInReentrantMode(is);
         } catch (Exception e) {
            String message = "Error while reading from file: " + bucketFile.getAbsoluteFile();
            log.error(message, e);
            throw new CacheLoaderException(message, e);
         } finally {
            safeClose(is);
         }
      }
      if (bucket != null) {
         bucket.setBucketName(bucketFile.getName());
      }
      return bucket;
   }
View Full Code Here

      this.config = (FileCacheStoreConfig) config;
   }
  
   protected void loopOverBuckets(BucketHandler handler) throws CacheLoaderException {
      for (File bucketFile : root.listFiles()) {
         Bucket bucket = loadBucket(bucketFile);
         if (handler.handle(bucket)) break;
      }
   }
View Full Code Here

TOP

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

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.