243. EPMO Open Source Coordination Office Redaction File Detail Report

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

243.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl\memory MemoryCache.java Mon Dec 4 21:35:34 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl\memory MemoryCache.java Mon Dec 4 22:01:42 2017 UTC

243.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 918
Changed 1 2
Inserted 0 0
Removed 0 0

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

243.4 Active regular expressions

No regular expressions were active.

243.5 Comparison detail

  1   /**
  2    * 
  3    */
  4   package go v.va.med.i maging.sto rage.cache .impl.memo ry;
  5  
  6   import gov .va.med.im aging.stor age.cache. *;
  7   import gov .va.med.im aging.stor age.cache. events.Gro upLifecycl eEvent;
  8   import gov .va.med.im aging.stor age.cache. events.Gro upLifecycl eListener;
  9   import gov .va.med.im aging.stor age.cache. events.Ins tanceLifec ycleEvent;
  10   import gov .va.med.im aging.stor age.cache. events.Ins tanceLifec ycleListen er;
  11   import gov .va.med.im aging.stor age.cache. exceptions .CacheExce ption;
  12   import gov .va.med.im aging.stor age.cache. exceptions .CacheStat eException ;
  13   import gov .va.med.im aging.stor age.cache. exceptions .RegionDoe sNotExistE xception;
  14   import gov .va.med.im aging.stor age.cache. exceptions .RegionIni tializatio nException ;
  15   import gov .va.med.im aging.stor age.cache. impl.memor y.data.Mem oryInstanc eDataFacto ry;
  16   import gov .va.med.im aging.stor age.cache. impl.memor y.memento. MemoryCach eMemento;
  17   import gov .va.med.im aging.stor age.cache. memento.Ev ictionStra tegyMement o;
  18   import gov .va.med.im aging.stor age.cache. memento.Re gionMement o;
  19  
  20   import jav a.net.URI;
  21   import jav a.util.*;
  22  
  23   import org .apache.lo gging.log4 j.LogManag er;
  24   import org .apache.lo gging.log4 j.Logger;
  25  
  26   /**
  27    * @author         
BECKEC
  28    *
  29    */
  30   public cla ss MemoryC ache 
  31   implements  Cache
  32   {
  33           pu blic final  static St ring proto col = "tra nsient";
  34           pr ivate fina l URI loca tionUri;
  35           pr ivate fina l String n ame;
  36           pr ivate fina l Eviction Timer evic tionTimer;
  37           pr ivate fina l Logger l ogger = Lo gManager.g etLogger(t his.getCla ss());
  38           
  39           pr ivate Bool ean enable d = Boolea n.TRUE;
  40           pr ivate Bool ean initia lized = Bo olean.TRUE ;
  41           pr ivate Coll ection<Evi ctionStrat egy> evict ionStrateg ies = new  HashSet<Ev ictionStra tegy>();
  42           pr ivate Coll ection<Reg ion> regio ns = new H ashSet<Reg ion>();
  43           pr ivate Coll ection<Cac heStructur eChangeLis tener> cac heStructur eChangeLis teners = n ew ArrayLi st<CacheSt ructureCha ngeListene r>();
  44           pr ivate fina l MemoryIn stanceData Factory in stanceData Factory;
  45           pr ivate fina l MemoryIn stanceByte ChannelFac tory insta nceByteCha nnelFactor y;
  46           pr ivate fina l MemoryRe gionFactor y regionFa ctory;         
  47           pr ivate fina l GroupFac tory group Factory;
  48           pr ivate fina l Instance Factory in stanceFact ory;
  49           
  50           pu blic stati c MemoryCa che create (String na me, URI lo cationUri,  EvictionT imer evict ionTimer)
  51           {
  52                    retu rn new Mem oryCache(n ame, locat ionUri, ev ictionTime r);
  53           }
  54           
  55           /* *
  56            *  
  57            *  @param na me
  58            *  @param lo cationUri  - a URI in  the forma
  59            *    memory: //ram&maxS ize=100000 ?maxInstan ceCount=10 0
  60            *  @param ev ictionTime r
  61            * /
  62           pr ivate Memo ryCache(St ring name,  URI locat ionUri, Ev ictionTime r eviction Timer)
  63           {
  64                    supe r();
  65                    this .locationU ri = locat ionUri;
  66                    pars eLocationU ri();
  67                    this .evictionT imer = evi ctionTimer ;
  68                    this .name = na me;
  69                    inst anceDataFa ctory = ne w MemoryIn stanceData Factory(ge tMaxCacheS ize());
  70                    inst anceByteCh annelFacto ry = new M emoryInsta nceByteCha nnelFactor y(instance DataFactor y);
  71                    
  72                    Life cycleLogge r lifecycl eLogger =  new Lifecy cleLogger( );
  73                    
  74                    inst anceFactor y = new Me moryInstan ceFactory( instanceBy teChannelF actory, li fecycleLog ger);
  75                    grou pFactory =  new Memor yGroupFact ory(lifecy cleLogger,  instanceF actory);
  76                    regi onFactory  = new Memo ryRegionFa ctory(getG roupFactor y(), getIn stanceFact ory()); 
  77           }
  78  
  79           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =====
  80           //  Immutable  Propertie s
  81           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =====
  82           pu blic Strin g getName( )
  83           {
  84                    retu rn this.na me;
  85           }
  86  
  87           /* *
  88            *  @return t he regionF actory
  89            * /
  90           pu blic Memor yRegionFac tory getRe gionFactor y()
  91           {
  92                    retu rn this.re gionFactor y;
  93           }
  94  
  95           /* *
  96            *  @return t he groupFa ctory
  97            * /
  98           pu blic Group Factory ge tGroupFact ory()
  99           {
  100                    retu rn this.gr oupFactory ;
  101           }
  102  
  103           /* *
  104            *  @return t he instanc eDataFacto ry
  105            * /
  106           pu blic Memor yInstanceD ataFactory  getInstan ceDataFact ory()
  107           {
  108                    retu rn this.in stanceData Factory;
  109           }
  110  
  111           /* *
  112            *  @return t he instanc eFactory
  113            * /
  114           pu blic Insta nceFactory  getInstan ceFactory( )
  115           {
  116                    retu rn this.in stanceFact ory;
  117           }
  118           
  119           /* *
  120            *  The URI m ay be inte rpreted as  follows:
  121            *  transient ://<name>[ ? + [maxSi ze=<cache- size>] + [ maxInstanc es=<instan ce-count>] ]
  122            *  where: 
  123            *  <name> is  the cache  identifie r
  124            *  <cache-si ze> is a p ositive in teger spec ifying the  maximum s ize of all  cache mem bers (in b ytes)
  125            *  <instance -count> is  a positiv e integer  specifying  the maxim um number  of instanc es in the  cache
  126            * /
  127           pr ivate Stri ng locatio nPath;
  128           pr ivate Stri ng locatio nProtocol;
  129           pr ivate int  maxInstanc eCount = I nteger.MAX _VALUE;
  130           pr ivate long  maxCacheS ize = Long .MAX_VALUE ;
  131           
  132           pr ivate void  parseLoca tionUri()
  133           {
  134                    loca tionPath =  getLocati onUri().ge tPath();
  135                    loca tionProtoc ol = getLo cationUri( ).getAutho rity();
  136                    Stri ng query =  getLocati onUri().ge tQuery();
  137                    if(q uery != nu ll)
  138                    {
  139                             String [] queryPa rameters =  query.spl it("&");
  140                             for(St ring query Parameter  : queryPar ameters)
  141                             {
  142                                      String[]  parsedQue ryParamete r = queryP arameter.s plit("=");
  143                                      if(parse dQueryPara meter.leng th == 2)
  144                                      {
  145                                               try
  146                                               {
  147                                                       if ("maxSize" .equals(pa rsedQueryP arameter[0 ]))
  148                                                                maxC acheSize =  Long.pars eLong( par sedQueryPa rameter[1]  );
  149                                                       el se if("max InstanceCo unt".equal s(parsedQu eryParamet er[0]))
  150                                                                maxI nstanceCou nt = Integ er.parseIn t( parsedQ ueryParame ter[1] );
  151                                              
  152                                               catch (Num berFormatE xception x )
  153                                               {
  154                                                       lo gger.warn( "Error ini tializing  parameter  '" + parse dQueryPara meter[0] +  "', value  must be p arsable as  a positiv e integer. ", x);
  155                                               }
  156                                      }
  157                             }
  158                    }
  159           }
  160           pu blic URI g etLocation Uri()
  161           {
  162                    retu rn locatio nUri;
  163           }
  164           pu blic Strin g getLocat ionPath()
  165           {
  166                    retu rn locatio nPath;
  167           }
  168           pu blic Strin g getLocat ionProtoco l()
  169           {
  170                    retu rn locatio nProtocol;
  171           }
  172           pu blic long  getMaxCach eSize()
  173           {
  174                    retu rn maxCach eSize;
  175           }
  176           pu blic long  getMaxInst anceCount( )
  177           {
  178                    retu rn maxInst anceCount;
  179           }
  180  
  181           pu blic long  getFreeSpa ce()
  182           {
  183                    retu rn instanc eDataFacto ry.getFree Space();
  184           }
  185           
  186           pu blic Evict ionTimer g etEviction Timer()
  187           {
  188                    retu rn evictio nTimer;
  189           }
  190  
  191           pu blic Insta nceByteCha nnelFactor y<?> getIn stanceByte ChannelFac tory()
  192           {
  193                    retu rn instanc eByteChann elFactory;
  194           }
  195           
  196           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =====
  197           //  Mutable P roperties
  198           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =====
  199           pu blic Boole an isEnabl ed()
  200           {
  201                    retu rn enabled ;
  202           }
  203           
  204           pu blic void  setEnabled (Boolean e nabled) 
  205           th rows Cache Exception
  206           {
  207                    this .enabled =  enabled;
  208           }
  209  
  210  
  211           pu blic Boole an isIniti alized()
  212           {
  213                    retu rn initial ized;
  214           }
  215           
  216           pu blic void  setInitial ized(Boole an initial ized) 
  217           th rows Cache Exception
  218           {
  219                    this .initializ ed = initi alized;
  220           }
  221  
  222           /* *
  223            *  
  224            * /
  225           pu blic Memor yCacheMeme nto create Memento()
  226           {
  227                    Memo ryCacheMem ento memen to = new M emoryCache Memento();
  228                    meme nto.setNam e(getName( ));
  229                    meme nto.setByt eChannelFa ctoryMemen to( getIns tanceByteC hannelFact ory().crea teMemento( ) );
  230                    meme nto.setEna bled(isEna bled());
  231                    meme nto.setIni tialized(i sInitializ ed());
  232                    
  233                    List <EvictionS trategyMem ento> esMe mentoes =  new ArrayL ist<Evicti onStrategy Memento>() ;
  234                    for( EvictionSt rategy evi ctionStrat egy : getE victionStr ategies())
  235                             esMeme ntoes.add(  evictionS trategy.cr eateMement o() );
  236                    meme nto.setEvi ctionStrat egyMemento s(esMement oes);
  237                    
  238                    meme nto.setLoc ationUri(g etLocation Uri().toSt ring());
  239                    
  240                    
  241                    List <RegionMem ento> regi onMementoe s = new Ar rayList<Re gionMement o>();
  242                    for( Region reg ion : getR egions())
  243                             region Mementoes. add( regio n.createMe mento() );
  244                    meme nto.setReg ionMemento s(regionMe mentoes);
  245                    
  246                    retu rn memento ;
  247           }
  248  
  249           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  250           //  Eviction  Strategies
  251           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  252           pu blic void  addEvictio nStrategie s(Collecti on<? exten ds Evictio nStrategy>  evictionS trategies)  
  253           th rows Cache StateExcep tion
  254           {
  255                    this .evictionS trategies. addAll(evi ctionStrat egies);
  256           }
  257  
  258           pu blic void  addEvictio nStrategy( EvictionSt rategy evi ctionStrat egy) 
  259           th rows Cache StateExcep tion
  260           {
  261                    this .evictionS trategies. add(evicti onStrategy );
  262           }
  263  
  264           pu blic Colle ction<? ex tends Evic tionStrate gy> getEvi ctionStrat egies()
  265           {
  266                    retu rn evictio nStrategie s;
  267           }
  268  
  269           /* *
  270            *  @see gov. va.med.ima ging.stora ge.cache.C ache#getEv ictionStra tegy(java. lang.Strin g)
  271            * /
  272           pu blic Evict ionStrateg y getEvict ionStrateg y(String e victionStr ategyName)
  273           {
  274                    for( EvictionSt rategy evi ctionStrat egy: getEv ictionStra tegies())
  275                             if( ev ictionStra tegyName.e quals(evic tionStrate gy.getName ()) )
  276                                      return e victionStr ategy;
  277                    
  278                    retu rn null;
  279           }
  280  
  281           /* *
  282            *  Given an  array of n ames, find  the evict ion strate gies regis tered with  this cach e whose na mes match
  283            *  the given  names.
  284            *  Duplicate s names in  the given  array are  ignored ( i.e. only  show up on ce in the  result)
  285            *  Unknown n ames in th e given ar ray are ig nored (i.e . do not s how up in  the result )
  286            *  
  287            *  @param ev ictionStra tegyNames
  288            *  @return
  289            * /
  290           pu blic Evict ionStrateg y[] getEvi ctionStrat egies(Stri ng[] evict ionStrateg yNames)
  291           {
  292                    if(e victionStr ategyNames  == null)
  293                             return  null;
  294                    
  295                    // m ake it a S et so that  duplicate s are effe ctively ig nored 
  296                    Set< EvictionSt rategy> ma tchedEvict ionStrateg ies = new  HashSet<Ev ictionStra tegy>();
  297                    
  298                    for( String evi ctionStrat egyName :  evictionSt rategyName s)
  299                    {
  300                             Evicti onStrategy  matchedEv ictionStra tegy = get EvictionSt rategy(evi ctionStrat egyName);
  301                             if(mat chedEvicti onStrategy  != null)
  302                                      matchedE victionStr ategies.ad d(matchedE victionStr ategy);
  303                    }
  304                    
  305                    retu rn matched EvictionSt rategies.s ize() > 0 
  306                             matche dEvictionS trategies. toArray(ne w Eviction Strategy[m atchedEvic tionStrate gies.size( )]) : 
  307                             null;
  308           }
  309           
  310           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  311           //  Region 
  312           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  313           pu blic Regio n createRe gion(Strin g name, St ring[] evi ctionStrat egyNames) 
  314           th rows Regio nInitializ ationExcep tion
  315           {
  316                    Evic tionStrate gy[] evict ionStrateg ies = getE victionStr ategies(ev ictionStra tegyNames) ;
  317                    retu rn getRegi onFactory( ).create(t his, name,  evictionS trategies) ;
  318           }
  319  
  320           pu blic Regio n createRe gion(Regio nMemento r egionMemen to) 
  321           th rows Regio nInitializ ationExcep tion
  322           {
  323                    Evic tionStrate gy[] regio nEvictionS trategies  = getEvict ionStrateg ies(region Memento.ge tEvictionS trategyNam es());
  324                    retu rn getRegi onFactory( ).create(t his, regio nMemento.g etName(),  regionEvic tionStrate gies);
  325           }
  326  
  327           pu blic void  addRegion( Region reg ion) 
  328           th rows Cache Exception
  329           {
  330                    regi ons.add(re gion);
  331                    noti fyCacheStr uctureChan geListener s();
  332           }
  333  
  334           pu blic void  addRegions (Collectio n<? extend s Region>  regions) 
  335           th rows Cache Exception
  336           {
  337                    for( Region reg ion : regi ons)
  338                             this.a ddRegion(r egion);
  339           }
  340  
  341           pu blic Regio n getRegio n(String n ame)
  342           {
  343                    if(n ame == nul l)
  344                             return  null;
  345                    
  346                    for( Region reg ion : getR egions())
  347                             if( na me.equals( region.get Name()) )
  348                                      return r egion;
  349                    
  350                    retu rn null;
  351           }
  352  
  353           pu blic Colle ction<? ex tends Regi on> getReg ions()
  354           {
  355                    retu rn Collect ions.unmod ifiableCol lection(th is.regions );
  356           }
  357           
  358           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  359           //  Instance  Management
  360           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  361           pu blic void  clear() 
  362           th rows Cache Exception
  363           {
  364                    for( Region reg ion : getR egions())
  365                             region .clear();
  366           }
  367  
  368           pu blic Insta nce getIns tance(Stri ng regionN ame, Strin g[] group,  String ke y) 
  369           th rows Cache Exception
  370           {
  371                    Regi on region  = getRegio n(regionNa me);
  372                    
  373                    if(r egion == n ull)
  374                             throw  new Region DoesNotExi stExceptio n();
  375                    
  376                    retu rn region. getInstanc e(group, k ey);
  377           }
  378  
  379           pu blic void  deleteInst ance(Strin g regionNa me, String [] group,  String key
  380           th rows Cache Exception
  381           {
  382                    Regi on region  = getRegio n(regionNa me);
  383                    
  384                    if(r egion == n ull)
  385                             throw  new Region DoesNotExi stExceptio n();
  386                    
  387                    regi on.deleteI nstance(gr oup, key);
  388           }
  389           
  390           pu blic Insta nce getOrC reateInsta nce(String  regionNam e, String[ ] group, S tring key)  
  391           th rows Cache Exception
  392           {
  393                    Regi on region  = getRegio n(regionNa me);
  394                    
  395                    if(r egion == n ull)
  396                             throw  new Region DoesNotExi stExceptio n();
  397                    
  398                    retu rn region. getOrCreat eInstance( group, key );
  399           }
  400  
  401           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  402           //  Managemen t and Moni toring
  403           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  404           /* *
  405            *  @see gov. va.med.ima ging.stora ge.cache.C ache#regis terCacheSt ructureCha ngeListene r(gov.va.m ed.imaging .storage.c ache.Cache StructureC hangeListe ner)
  406            * /
  407           pu blic void  registerCa cheStructu reChangeLi stener(Cac heStructur eChangeLis tener list ener)
  408           {
  409                    cach eStructure ChangeList eners.add( listener);
  410           }
  411  
  412           /* *
  413            *  @see gov. va.med.ima ging.stora ge.cache.C ache#unreg isterCache StructureC hangeListe ner(gov.va .med.imagi ng.storage .cache.Cac heStructur eChangeLis tener)
  414            * /
  415           pu blic void  unregister CacheStruc tureChange Listener(C acheStruct ureChangeL istener li stener)
  416           {
  417                    cach eStructure ChangeList eners.remo ve(listene r);
  418           }
  419  
  420           pu blic void  notifyCach eStructure ChangeList eners()
  421           {
  422                    for( CacheStruc tureChange Listener l istener :  cacheStruc tureChange Listeners)
  423                             listen er.cacheSt ructureCha nged(this) ;
  424           }
  425           
  426           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  427           //  Container  Lifecycle  Notificat ion
  428           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
  429           /* *
  430            *  @see gov. va.med.ima ging.stora ge.cache.C acheLifecy cleListene r#cacheLif ecycleEven t(gov.va.m ed.imaging .storage.c ache.Cache LifecycleE vent)
  431            * /
  432           pu blic void  cacheLifec ycleEvent( CacheLifec ycleEvent  event) 
  433           th rows Cache StateExcep tion
  434           {
  435                    for( Region reg ion : getR egions())
  436                             region .cacheLife cycleEvent (event);
  437           }
  438           
  439           cl ass Lifecy cleLogger
  440           im plements I nstanceLif ecycleList ener, Grou pLifecycle Listener
  441           {
  442  
  443                    /* ( non-Javado c)
  444                     * @ see gov.va .med.imagi ng.storage .cache.eve nts.Instan ceLifecycl eListener# notify(gov .va.med.im aging.stor age.cache. events.Ins tanceLifec ycleEvent)
  445                     */
  446                    publ ic void no tify(Insta nceLifecyc leEvent ev ent)
  447                    {
  448                             System .out.print ln("Instan ce event [ " + event. getLifecyc leEvent()  + "] " + e vent.getNa me() );
  449                    }
  450  
  451                    /* ( non-Javado c)
  452                     * @ see gov.va .med.imagi ng.storage .cache.eve nts.GroupL ifecycleLi stener#not ify(gov.va .med.imagi ng.storage .cache.eve nts.GroupL ifecycleEv ent)
  453                     */
  454                    publ ic void no tify(Group LifecycleE vent event )
  455                    {
  456                             System .out.print ln("Group  event [" +  event.get LifecycleE vent() + " ] " + even t.getName( ) );
  457                    }
  458                    
  459           }
  460   }