42. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/5/2017 12:06:35 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.

42.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\CacheAPI\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\CacheAPI\main\src\java\gov\va\med\imaging\storage\cache\impl\eviction LastAccessedEvictionStrategy.java Mon Dec 4 21:57:25 2017 UTC

42.2 Comparison summary

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

42.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

42.4 Active regular expressions

No regular expressions were active.

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