231. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/5/2017 12:06:42 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

231.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCache\main\src\java\gov\va\med\imaging\storage\cache\impl\eviction LastAccessedEvictionStrategy.java Mon Dec 4 21:35:30 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCache\main\src\java\gov\va\med\imaging\storage\cache\impl\eviction LastAccessedEvictionStrategy.java Mon Dec 4 22:01:25 2017 UTC

231.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 4 548
Changed 3 6
Inserted 0 0
Removed 0 0

231.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

231.4 Active regular expressions

No regular expressions were active.

231.5 Comparison detail

  1   package go v.va.med.i maging.sto rage.cache .impl.evic tion;
  2  
  3   import gov .va.med.im aging.stor age.cache. *;
  4   import gov .va.med.im aging.stor age.cache. exceptions .CacheExce ption;
  5  
  6   import jav a.text.Dat eFormat;
  7   import jav a.text.Sim pleDateFor mat;
  8   import jav a.util.*;
  9   import jav a.util.con current.Ca llable;
  10   import jav a.util.con current.Ex ecutionExc eption;
  11   import jav a.util.con current.Fu ture;
  12  
  13   import org .apache.lo gging.log4 j.LogManag er;
  14   import org .apache.lo gging.log4 j.Logger;
  15  
  16   /**
  17    * 
  18    * @author         
BECKEC
  19    *
  20    */
  21   public cla ss LastAcc essedEvict ionStrateg y
  22   extends Pe riodicSwee pEvictionS trategy
  23   implements  EvictionS trategy, L astAccesse dEvictionS trategyMBe an
  24   {
  25           pu blic final  static St ring maxTi meProperty Key = "max imumAge"; 
  26           pu blic final  static St ring initi alizedProp ertyKey =  "initializ ed";
  27           
  28           pr ivate fina l long max imumTimeSi nceLastAcc ess;
  29           pr ivate fina l DateForm at df = ne w SimpleDa teFormat(" dd-MMM-yyy y hh:mm:ss ");
  30           pr ivate fina l Logger l og = LogMa nager.getL ogger(this .getClass( ));
  31           pr ivate Swee pStatistic s lastSwee pStatistic s = new Sw eepStatist ics(System .currentTi meMillis() , 0);
  32           
  33           /* *
  34            *  Factory m ethod used  by the in teractive  tool.
  35            *  
  36            *  @param me mento
  37            *  @param ti mer
  38            *  @return
  39            * /
  40           st atic LastA ccessedEvi ctionStrat egy create (Propertie s prop, Ev ictionTime r timer)
  41           {
  42                    Stri ng name =  (String)pr op.get(Sim pleEvictio nStrategy. nameProper tyKey);
  43                    long  maxTimeSi nceLastAcc ess = ((Lo ng)prop.ge t(maxTimeP ropertyKey )).longVal ue();
  44                    bool ean initia lized = (( Boolean)pr op.get(ini tializedPr opertyKey) ).booleanV alue();
  45                    
  46                    retu rn new Las tAccessedE victionStr ategy(name , maxTimeS inceLastAc cess, init ialized, t imer);
  47           }
  48           
  49           st atic LastA ccessedEvi ctionStrat egy create (LastAcces sedEvictio nStrategyM emento mem ento, Evic tionTimer  timer)
  50           {
  51                    retu rn new Las tAccessedE victionStr ategy(meme nto.getNam e(), memen to.getMaxi mumTimeSin ceLastAcce ss(), meme nto.isInit ialized(),  timer);
  52           }
  53           
  54           st atic LastA ccessedEvi ctionStrat egy create (String na me, Long m aximumTime SinceLastA ccess, boo lean initi alized, Ev ictionTime r timer)
  55           {
  56                    retu rn new Las tAccessedE victionStr ategy(name , maximumT imeSinceLa stAccess,  initialize d, timer);
  57           }
  58           
  59           pr otected La stAccessed EvictionSt rategy(Str ing name,  Long maxim umTimeSinc eLastAcces s, boolean  initializ ed, Evicti onTimer ti mer)
  60           {
  61                    supe r(name, ti mer);
  62                    this .maximumTi meSinceLas tAccess =  maximumTim eSinceLast Access.lon gValue();
  63           }
  64           
  65           /* *
  66            *  Get the m aximum age  of a grou p as measu red from n ow to its  last acces s.
  67            *  
  68            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.evicti on.LastAcc essedEvict ionStrateg yMBean#get MaximumTim eSinceLast Access()
  69            * /
  70           @O verride
  71           pu blic long  getMaximum Age()
  72           {
  73                    retu rn maximum TimeSinceL astAccess;
  74           }
  75           
  76           
  77           /*  (non-Java doc)
  78            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.evicti on.LastAcc essedEvict ionStrateg yMBean#get EvictedLas tSweep()
  79            * /
  80           pu blic int g etEvictedL astSweep()
  81           {
  82                    retu rn getLast SweepStati stics().ge tTotalEvic tedGroups( );
  83           }
  84  
  85           /*  (non-Java doc)
  86            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.evicti on.LastAcc essedEvict ionStrateg yMBean#get LastRunDat e()
  87            * /
  88           pu blic Strin g getLastR unDate()
  89           {
  90                    retu rn df.form at( new Da te(getLast SweepStati stics().ge tSweepTime ()) );
  91           }
  92  
  93           
  94           /* *
  95            *  Create a  Memento th at may be  serialized  and later  used to r estore the  state of  this class .
  96            *  
  97            *  @return
  98            * /
  99           @O verride
  100           pu blic LastA ccessedEvi ctionStrat egyMemento  createMem ento()
  101           {
  102                    retu rn new Las tAccessedE victionStr ategyMemen to(getName (), isInit ialized(),  getMaximu mAge());
  103           }
  104  
  105           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== =======
  106           //
  107           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== =======
  108           
  109           @O verride
  110           pu blic Sweep Statistics  getLastSw eepStatist ics()
  111           {
  112                    retu rn lastSwe epStatisti cs;
  113           }
  114           
  115           vo id setLast SweepStati stics(Swee pStatistic s sweepSta tistics)
  116           {
  117                    this .lastSweep Statistics  = sweepSt atistics;
  118           }
  119           
  120           @O verride
  121           pu blic void  sweep()
  122           {
  123                    log. info("Evic tion sweep  commencin g, startin g worker t asks.");
  124                    
  125                    long  maxAge =  getMaximum Age();           // t he max per iod of a c ached item  before it  gets dele ted
  126                                                                                                                                       // this me thod is ov erriden in  derived c lasses and  should be  called on ly
  127                                                                                                                                       // once pe r sweep
  128                    Date  now = new  Date();                                                                // t he current  date/time
  129                    Date  minLastAc cess = new  Date(now. getTime()  - maxAge);            // anythin g accessed  before th is time sh ould be de leted.
  130                    Last AccessedDa teJudge ju dge = new  LastAccess edDateJudg e(minLastA ccess);
  131  
  132                    List <Future<Sw eepStatist ics>> futu res = new  ArrayList< Future<Swe epStatisti cs>>();
  133                    for( Region reg ion: getRe gions())
  134                    {
  135                             future s.add( get Executor() .submit( n ew LastAcc essedEvict ionTask(ju dge, regio n) ) );
  136                    }
  137                    
  138                    getE xecutor(). execute(ne w Statisti csCollecti onTask(fut ures));
  139                    
  140                    log. info("Evic tion sweep  commencin g, worker  tasks star ted.");
  141           }
  142           
  143           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== =======
  144           //
  145           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== =======
  146  
  147           /* *
  148            *  This is t he class t hat actual ly does th e work of  deleting ( evicting)
  149            *  files fro m the cach e.
  150            *  
  151              * @author        
BECKEC
  152            *
  153            * /
  154           cl ass LastAc cessedEvic tionTask
  155           im plements C allable<Sw eepStatist ics>
  156           {
  157                    priv ate final  Region reg ion;
  158                    priv ate final  EvictionJu dge<Group>  judge;
  159                    
  160                    /**
  161                     * S tarting wi th the spe cified reg ion, delet e anything  older (i. e. last ac cess befor e the minL astAccess)
  162                     * @ param regi on
  163                     * @ param minL astAccess
  164                     */
  165                    Last AccessedEv ictionTask (EvictionJ udge<Group > judge, R egion regi on)
  166                    { 
  167                             this.j udge = jud ge;
  168                             this.r egion = re gion;
  169                    }
  170                    
  171                    Evic tionJudge< Group> get Judge()
  172                    {
  173                             return  this.judg e;
  174                    }
  175  
  176                    Regi on getRegi on()
  177                    {
  178                             return  this.regi on;
  179                    }
  180  
  181                    
  182                    /* ( non-Javado c)
  183                     * @ see java.u til.concur rent.Calla ble#call()
  184                     */
  185                    publ ic SweepSt atistics c all() 
  186                    thro ws Excepti on
  187                    {
  188                             int ev icted = 0;
  189                             long s tart = Sys tem.curren tTimeMilli s();
  190                             log.in fo(Thread. currentThr ead().getN ame() + "  beginning  eviction s weep of re gion '" +  getRegion( ).getName( ) + "'.");
  191  
  192                             try
  193                             {
  194                                      evicted  = region.e valuateAnd EvictChild Groups(get Judge());
  195                             } 
  196                             catch  (CacheExce ption e)
  197                             {
  198                                      e.printS tackTrace( );
  199                             }
  200  
  201                             log.in fo(Thread. currentThr ead().getN ame() + "  completed  sweep, " +  evicted +  " groups  evicted.") ;
  202                             
  203                             return  new Sweep Statistics (start, ev icted);
  204                    }
  205           }
  206           
  207           /* *
  208            *  A class t hat waits  for result s from the  region sw eep tasks  and then c ollects th e statisti cs.
  209            *  
  210              * @author        
BECKEC
  211            * /
  212           cl ass Statis ticsCollec tionTask
  213           im plements R unnable
  214           {
  215                    priv ate List<F uture<Swee pStatistic s>> future s;
  216                    Stat isticsColl ectionTask (List<Futu re<SweepSt atistics>>  futures)
  217                    {
  218                             this.f utures = f utures;
  219                    }
  220                    
  221                    priv ate List<F uture<Swee pStatistic s>> getFut ures()
  222                    {
  223                             return  futures;
  224                    }
  225                    
  226                    /* ( non-Javado c)
  227                     * @ see java.l ang.Runnab le#run()
  228                     */
  229                    publ ic void ru n()
  230                    {
  231                             SweepS tatistics  sweepStati stics = ne w SweepSta tistics();
  232                             
  233                             for( F uture<Swee pStatistic s> future  : getFutur es() )
  234                             {
  235                                      try
  236                                      {
  237                                               sweepStati stics.add(  future.ge t() );
  238                                      } 
  239                                      catch (I nterrupted Exception  x)
  240                                      {
  241                                               log.error( "Error get ting resul ts of regi on sweep,  eviction s tatistics  may not be  accurate" , x);
  242                                      } 
  243                                      catch (E xecutionEx ception x)
  244                                      {
  245                                               log.error( "Error get ting resul ts of regi on sweep,  eviction s tatistics  may not be  accurate" , x);
  246                             
  247                                      }
  248                             }
  249                             
  250                             setLas tSweepStat istics(swe epStatisti cs);
  251                    }
  252           }
  253           
  254           /* *
  255            *  A simple  EvictionJu dge that j ust looks  at the las t accessed  date
  256            *  @author v haiswbecke c
  257            *
  258            * /
  259           cl ass LastAc cessedDate Judge
  260           im plements E victionJud ge<Group>
  261           {
  262                    fina l long min LastAccess Milli;
  263                    
  264                    Last AccessedDa teJudge(Da te minLast Access)
  265                    {
  266                             minLas tAccessMil li = minLa stAccess.g etTime();
  267                    }
  268                    
  269                    publ ic boolean  isEvictab le(Group g roup) 
  270                    thro ws CacheEx ception
  271                    {
  272                             Date g roupLastAc cessed = g roup == nu ll ? null  : group.ge tLastAcces sed();
  273                             return  groupLast Accessed = = null ? f alse : (gr oupLastAcc essed.getT ime() < mi nLastAcces sMilli);
  274                    }
  275                    
  276           }
  277   }