Beispiel #1
0
 public static StaticResource instance(
     String _listen_path, long delay_load, long file_max_size, int file_cache_min_uses) {
   if (instance == null) {
     instance = new StaticResource();
     instance.init(_listen_path, delay_load, file_max_size, file_cache_min_uses);
   }
   return instance;
 }
Beispiel #2
0
 public void init(
     String _listen_path, long delay_load, long file_max_size, int file_cache_min_uses) {
   file_map = new HashMap<String, Resource>();
   listen_path = _listen_path;
   instance.delay_load = delay_load;
   instance.file_max_size = file_max_size;
   instance.file_cache_min_uses = file_cache_min_uses;
   checker =
       new Thread() {
         @Override
         public void run() {
           while (!end) {
             try {
               sleep(instance.delay_load);
             } catch (InterruptedException e) {
               log.debug(
                   "static resource checker sleep  has been interrupted as the thread is going to close.");
             }
             List<String> keys = new LinkedList<String>();
             for (Resource rs : file_map.values()) {
               rs.use = 1;
               if (!rs.file.exists()
                   || rs.use < instance.file_cache_min_uses
                   || rs.file.lastModified() != rs.last_modify_time) {
                 keys.add(MyMath.encryptionWithMD5(rs.file.getPath()));
                 continue;
               }
             }
             for (String key : keys) {
               file_map.remove(key);
             }
           }
           log.info(
               "..............................................................................");
           log.info("\t\t\tStatic Resource Checker has been successfully terminated.");
           log.info(
               "..............................................................................");
         }
       };
   checker.start();
 }