6 Replies Latest reply on Mar 21, 2007 11:09 AM by Elias Ross

    AsyncCacheLoader

    Srinivasan Bakthavachalam Newbie

      I want to use jdbc writes in async mode. I've tailored MyAsyncCacheLoader extending AsyncCacheLoader with overridden put methods. I'm calling super(new JDBCCacheLoader) in the constructor and loading the config file. Unexpectedly my properties file alone gets loaded, but doesn't call my put method which i've overrided, instead it writes to the DB directly. Please suggest me how to proceed. Alternate solutions are welcomed.

      My Code goes as

      import java.io.File;
      import java.io.FileInputStream;
      import java.io.FileNotFoundException;
      import java.io.IOException;
      import java.util.Iterator;
      import java.util.Map;
      import java.util.Properties;
      import java.util.Set;

      import org.jboss.cache.DataNode;
      import org.jboss.cache.Fqn;
      import org.jboss.cache.PropertyConfigurator;
      import org.jboss.cache.TreeCache;
      import org.jboss.cache.loader.AsyncCacheLoader;
      import org.jboss.cache.loader.AsyncExtendedCacheLoader;
      import org.jboss.cache.loader.ExtendedCacheLoader;
      import org.jboss.cache.loader.FileCacheLoader;
      import org.jboss.cache.loader.JDBCCacheLoader;
      import org.jboss.cache.loader.JDBCExtendedCacheLoader;


      public class MyAsyncCacheLoader extends AsyncCacheLoader {
      private static long timeStamp;
      private static long oneHrtimeStamp;

      public MyAsyncCacheLoader(){
      super(new JDBCCacheLoader());

      Properties cfg = new Properties();
      try {
      cfg.load(new FileInputStream(new File("async.properties")));
      } catch (FileNotFoundException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }
      System.out.println("Read the value : " + cfg);
      String key = "cache.async.batchSize";
      String val = cfg.getProperty (key) ;
      System.out.println("Read the value : " + val);
      this.setConfig(cfg);
      timeStamp=0;
      oneHrtimeStamp=0;
      }
      public Object put(Fqn name, Object key, Object value) throws Exception{
      System.out.println("Inside MyAsyncCacheLoader put....");
      if(!name.getLast().equals("operation"))
      {
      System.out.println(name.toString()+ " written to DB");
      super.put(name, key, value);
      }
      else
      System.out.println(name.toString()+ " will not be written to DB");

      return value;

      }

      public void put(Fqn name, Map attributes) throws Exception
      {
      System.out.println("Inside MyAsyncCacheLoader Put (map) method :: Fqn = "+ name );
      if(!name.getLast().equals("operation"))
      {
      System.out.println(name.toString()+ " written to DB");

      super.put(name, attributes);
      }
      else
      System.out.println(name.toString()+ " will not be written to DB");


      }
      }