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

51.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\CacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl CacheManagerImpl.java Mon Dec 4 21:35:18 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\CacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl CacheManagerImpl.java Mon Dec 4 21:57:33 2017 UTC

51.2 Comparison summary

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

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

51.4 Active regular expressions

No regular expressions were active.

51.5 Comparison detail

  1   package go v.va.med.i maging.sto rage.cache .impl;
  2  
  3   import gov .va.med.im aging.stor age.cache. Cache;
  4   import gov .va.med.im aging.stor age.cache. CacheLifec ycleEvent;
  5   import gov .va.med.im aging.stor age.cache. CacheManag er;
  6   import gov .va.med.im aging.stor age.cache. CacheStruc tureChange Listener;
  7   import gov .va.med.im aging.stor age.cache. EvictionSt rategy;
  8   import gov .va.med.im aging.stor age.cache. EvictionTi mer;
  9   import gov .va.med.im aging.stor age.cache. Region;
  10   import gov .va.med.im aging.stor age.cache. exceptions .CacheExce ption;
  11   import gov .va.med.im aging.stor age.cache. exceptions .CacheInit ialization Exception;
  12   import gov .va.med.im aging.stor age.cache. exceptions .CacheStat eException ;
  13   import gov .va.med.im aging.stor age.cache. impl.evict ion.Evicti onStrategy Factory;
  14   import gov .va.med.im aging.stor age.cache. impl.files ystem.File SystemCach e;
  15   import gov .va.med.im aging.stor age.cache. impl.jmx.A bstractCac heMBean;
  16   import gov .va.med.im aging.stor age.cache. memento.Ev ictionStra tegyMement o;
  17   import gov .va.med.se rver.Cache ResourceRe ferenceFac tory;
  18   import gov .va.med.se rver.Serve rLifecycle Event;
  19   import gov .va.med.se rver.Serve rLifecycle Listener;
  20  
  21   import jav a.io.File;
  22   import jav a.io.FileN otFoundExc eption;
  23   import jav a.io.IOExc eption;
  24   import jav a.io.Input Stream;
  25   import jav a.lang.man agement.Ma nagementFa ctory;
  26   import jav a.net.URI;
  27   import jav a.net.URIS yntaxExcep tion;
  28   import jav a.util.Arr ayList;
  29   import jav a.util.Lis t;
  30  
  31   import jav ax.managem ent.Attrib ute;
  32   import jav ax.managem ent.Attrib uteNotFoun dException ;
  33   import jav ax.managem ent.Dynami cMBean;
  34   import jav ax.managem ent.Instan ceAlreadyE xistsExcep tion;
  35   import jav ax.managem ent.Instan ceNotFound Exception;
  36   import jav ax.managem ent.Invali dAttribute ValueExcep tion;
  37   import jav ax.managem ent.MBeanE xception;
  38   import jav ax.managem ent.MBeanI nfo;
  39   import jav ax.managem ent.MBeanN otificatio nInfo;
  40   import jav ax.managem ent.MBeanO perationIn fo;
  41   import jav ax.managem ent.MBeanR egistratio nException ;
  42   import jav ax.managem ent.MBeanS erver;
  43   import jav ax.managem ent.Malfor medObjectN ameExcepti on;
  44   import jav ax.managem ent.NotCom pliantMBea nException ;
  45   import jav ax.managem ent.Object Name;
  46   import jav ax.managem ent.Reflec tionExcept ion;
  47   import jav ax.managem ent.openmb ean.OpenDa taExceptio n;
  48   import jav ax.managem ent.openmb ean.OpenMB eanAttribu teInfo;
  49   import jav ax.managem ent.openmb ean.OpenMB eanAttribu teInfoSupp ort;
  50   import jav ax.managem ent.openmb ean.OpenMB eanConstru ctorInfo;
  51   import jav ax.managem ent.openmb ean.OpenMB eanConstru ctorInfoSu pport;
  52   import jav ax.managem ent.openmb ean.OpenMB eanInfoSup port;
  53   import jav ax.managem ent.openmb ean.OpenMB eanOperati onInfo;
  54   import jav ax.managem ent.openmb ean.OpenMB eanOperati onInfoSupp ort;
  55   import jav ax.managem ent.openmb ean.OpenMB eanParamet erInfo;
  56   import jav ax.managem ent.openmb ean.OpenMB eanParamet erInfoSupp ort;
  57   import jav ax.managem ent.openmb ean.Simple Type;
  58   import jav ax.naming. NamingExce ption;
  59   import jav ax.naming. Reference;
  60  
  61   import org .apache.lo gging.log4 j.LogManag er;
  62   import org .apache.lo gging.log4 j.Logger;
  63  
  64   /**
  65    * Cache i nstances m ust be cre ated throu gh this cl ass, not d irectly.  
  66    * This cl ass is the  interface  for the c ache lifec ycle and a lso for th e manageme nt and mon itoring of  the 
  67    * lifecyc le and par ameter per sistence m ethods of  a Cache in stance.
  68    * 
  69    * This cl ass also i s responsi ble for st oring and  loading th e FileSyst emCache st ate and fo r
  70    * restori ng the sta te of the  cache when  it is rec reated.
  71    * 
  72    * The Cac heManagerI mpl single ton may ma nage a num ber of cac he instanc es, each i dentified
  73    * by name .  This cl ass (Cache Factory) u ses the na me as iden tified in  the resour ce
  74    * declara tion as th e cache na me it need s from Cac heManagerI mpl.
  75    * 
  76    * The Cac heManagerI mpl manage s the life cycle and  the config uration of  the Cache
  77    * regardl ess of whe ther an MB eanServer  is availab le.  The C acheManage rImpl must  be
  78    * instant iated and  it must be  used for  Cache conf iguration,  not direc t
  79    * Cache a ccess.
  80    * 
  81    * @author         
BECKEC
  82    *
  83    */
  84   public cla ss CacheMa nagerImpl
  85   extends Ab stractCach eMBean
  86   implements  ServerLif ecycleList ener, Cach eStructure ChangeList ener, Cach eManager
  87   {
  88           pr ivate stat ic CacheMa nagerImpl  singleton;                // the  single in stance of  this class
  89           
  90           pr ivate Logg er logger  = LogManag er.getLogg er(this.ge tClass());
  91           pr ivate bool ean server Running =  false;                             // we ma y delay st arting the  managed c aches so w e set this  when we g et the sta rt
  92           pr ivate Know nCacheList  knownCach es;                                         // A list  of all the  caches th at this ma nager know s about, t his class  keeps the
  93                                                                                                                              // confi gurations  in the con fig direct ory consis tent with  the transi ent
  94                                                                                                                              // list  of caches.
  95           
  96           pu blic stati c final St ring defau ltConfigur ationDirec toryName =  "/vix";
  97           pu blic stati c final St ring cache Configurat ionSubdire ctoryName  = "cache-c onfig";
  98           
  99           pr ivate Cach e activeCa che;               //  used in i nteractive  managemen t, not use d in norma l operatio n
  100           
  101           /* *
  102            *  This clas s is a sin gleton bec ause the c ache insta nces may b e shared a cross mult iple web a pps 
  103            *  but each  cache must  behave wi th synchro nicity wit h respect  to its nam e as the p rimary key .
  104            *    
  105            *  @return
  106            *  @throws M BeanExcept ion
  107            *  @throws C acheExcept ion 
  108            * /
  109           pu blic stati c synchron ized Cache ManagerImp l getSingl eton() 
  110           th rows MBean Exception,  CacheExce ption
  111           {
  112                    if(s ingleton = = null)
  113                             single ton = new  CacheManag erImpl();
  114                    
  115                    retu rn singlet on;
  116           }
  117  
  118           /* *
  119            *  @throws M BeanExcept ion 
  120            *  @throws C acheInitia lizationEx ception 
  121            *  
  122            *
  123            * /
  124           pr ivate Cach eManagerIm pl() 
  125           th rows Cache Exception,  MBeanExce ption 
  126           {
  127                    know nCaches =  new KnownC acheList(g etConfigur ationDirec tory());
  128                    
  129                    regi sterCacheM anagerMBea n();             // r egister ou rselves as  an MBean
  130                    // r egister th e known ca ches so th at they ar e manageab le
  131                    for( Cache cach e : knownC aches)
  132                             regist erCacheMBe ans(cache) ;
  133           }
  134           
  135           /*  (non-Java doc)
  136            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#ge tKnownCach es()
  137            * /
  138           @O verride
  139           pu blic Known CacheList  getKnownCa ches()
  140           {
  141                    retu rn this.kn ownCaches;
  142           }
  143           
  144           pu blic Cache  getActive Cache()
  145           {
  146                    retu rn activeC ache;
  147           }
  148           
  149           pu blic void  setActiveC ache(Cache  activeCac he)
  150           {
  151                    this .activeCac he = activ eCache;
  152           }
  153  
  154           /* *
  155            *  Returns t rue if thi s instance  has recei ved a serv er start e vent and h as not 
  156            *  received  a server s top event.
  157            *  @return
  158            * /
  159           @O verride
  160           pu blic boole an isServe rRunning()
  161           {
  162                    retu rn serverR unning;
  163           }
  164  
  165           pu blic Cache  createCac he(String  name, URI  locationUr i) 
  166           th rows MBean Exception,  CacheExce ption, URI SyntaxExce ption, IOE xception
  167           {
  168                    retu rn createC ache(name,  locationU ri, (Strin g)null);
  169           }
  170           
  171           /*  (non-Java doc)
  172            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#cr eateCache( java.lang. String, ja va.net.URI , java.lan g.String)
  173            * /
  174           @O verride
  175           pu blic Cache  createCac he(String  name, URI  locationUr i, String  prototypeN ame) 
  176           th rows MBean Exception,  CacheExce ption, URI SyntaxExce ption, IOE xception
  177           {
  178                    Cach e cache =  getKnownCa ches().cre ate(name,  locationUr i, prototy peName);
  179                    
  180                    // r egister th e newly cr eated cach e so that  it is mana geable
  181                    regi sterCacheM Beans(cach e);
  182                    
  183                    retu rn cache;
  184           }
  185  
  186           pu blic Cache  createCac he(String  name, URI  locationUr i, InputSt ream proto type) 
  187           th rows MBean Exception,  CacheExce ption, URI SyntaxExce ption, IOE xception
  188           {
  189                    Cach e cache =  getKnownCa ches().cre ate(name,  locationUr i, prototy pe);
  190                    
  191                    // r egister th e newly cr eated cach e so that  it is mana geable
  192                    regi sterCacheM Beans(cach e);
  193                    
  194                    retu rn cache;
  195           }
  196  
  197           /*  (non-Java doc)
  198            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#ge tCache(jav a.lang.Str ing)
  199            * /
  200           @O verride
  201           pu blic Cache  getCache( String cac heName) 
  202           th rows FileN otFoundExc eption, IO Exception,  MBeanExce ption, Cac heExceptio n
  203           {
  204                    Cach e cache =  knownCache s.get(cach eName);
  205                    retu rn cache;
  206           }
  207           
  208           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== === 
  209           //  Basic Cac he managem ent method s made ava ilable her e so that  tests can  get a runn ing cache
  210           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ===
  211           /*  (non-Java doc)
  212            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Cache Manager#in itialize()
  213            * /
  214           /*  (non-Java doc)
  215            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#in itialize(g ov.va.med. imaging.st orage.cach e.Cache)
  216            * /
  217           @O verride
  218           pu blic Strin g initiali ze(Cache c ache)
  219           {
  220                    try
  221                    {
  222                             if(! c ache.isIni tialized() )
  223                             {
  224                                      cache.se tInitializ ed(Boolean .TRUE);
  225                                      if(serve rRunning)
  226                                               cache.cach eLifecycle Event(Cach eLifecycle Event.STAR T);
  227                             }
  228                             else
  229                                      return " Cache was  already in itialized" ;
  230                    } 
  231                    catc h (CacheEx ception cX )
  232                    {
  233                             logger .error("Er ror initia lizing cac he.", cX);
  234                             return  cX.getMes sage();
  235                    }
  236                    retu rn "Cache  Initialize d";
  237           }
  238           
  239           /*  (non-Java doc)
  240            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Cache Manager#en able()
  241            * /
  242           /*  (non-Java doc)
  243            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#en able(gov.v a.med.imag ing.storag e.cache.Ca che)
  244            * /
  245           @O verride
  246           pu blic Strin g enable(C ache cache )
  247           {
  248                    try
  249                    {
  250                             cache. setEnabled (Boolean.T RUE);
  251                    } 
  252                    catc h (CacheEx ception cX )
  253                    {
  254                             logger .error("Er ror enabli ng cache ' " + cache. getName()  + "'.", cX );
  255                             return  cX.getMes sage();
  256                    }
  257                    retu rn "Cache  Enabled";
  258           }
  259  
  260           /*  (non-Java doc)
  261            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Cache Manager#di sable()
  262            * /
  263           /*  (non-Java doc)
  264            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#di sable(gov. va.med.ima ging.stora ge.cache.C ache)
  265            * /
  266           @O verride
  267           pu blic Strin g disable( Cache cach e)
  268           {
  269                    try
  270                    {
  271                             cache. setEnabled (Boolean.F ALSE);
  272                    } 
  273                    catc h (CacheEx ception cX )
  274                    {
  275                             logger .error("Er ror disabl ing cache  '" + cache .getName()  + "'.", c X);
  276                             return  cX.getMes sage();
  277                    }
  278                    retu rn "Cache  Enabled";
  279           }
  280  
  281           /*  (non-Java doc)
  282            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#st ore(gov.va .med.imagi ng.storage .cache.Cac he)
  283            * /
  284           @O verride
  285           pu blic void  store(Cach e cache) 
  286           th rows IOExc eption
  287           {
  288                    getK nownCaches ().store(c ache);
  289           }
  290  
  291           /*  (non-Java doc)
  292            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#st oreAll()
  293            * /
  294           @O verride
  295           pu blic void  storeAll()  
  296           th rows IOExc eption
  297           {
  298                    getK nownCaches ().storeAl l();
  299           }
  300           
  301           /*  (non-Java doc)
  302            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#de lete(gov.v a.med.imag ing.storag e.cache.Ca che)
  303            * /
  304           @O verride
  305           pu blic void  delete(Cac he cache)
  306           {
  307                    // d isable the  cache to  stop new r equests
  308                    disa ble(cache) ;
  309                    unre gisterCach eMBeans(ca che);
  310                    
  311                    Stri ng cacheNa me = cache .getName() ;
  312                    cach e = null;             // drop th e referenc e
  313                    getK nownCaches ().remove( cacheName) ;
  314           }
  315           
  316           /*  (non-Java doc)
  317            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#cr eateEvicti onStrategy (gov.va.me d.imaging. storage.ca che.Cache,  gov.va.me d.imaging. storage.ca che.mement o.Eviction StrategyMe mento)
  318            * /
  319           @O verride
  320           pu blic Evict ionStrateg y createEv ictionStra tegy(Cache  cache, Ev ictionStra tegyMement o memento)
  321           th rows Cache Exception
  322           {
  323                    if(  getKnownCa ches().isK nownCache( cache) )
  324                    {
  325                             Evicti onStrategy Factory fa ctory = Ev ictionStra tegyFactor y.getSingl eton();
  326                             Evicti onTimer ti mer = cach e.getEvict ionTimer() ;
  327                             Evicti onStrategy  strategy  = factory. createEvic tionStrate gy(memento , timer);
  328                             
  329                             if(str ategy != n ull)
  330                                      cache.ad dEvictionS trategy(st rategy);
  331                             
  332                             try
  333                             {
  334                                      register EvictionSt rategyMBea n(cache, s trategy);
  335                             } 
  336                             catch  (Exception  x)
  337                             {
  338                                      logger.w arn(x);
  339                             }
  340                             
  341                             return  strategy;
  342                    }
  343                    
  344                    retu rn null;
  345           }
  346           
  347           /*  (non-Java doc)
  348            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.ICache Manager#cr eateRegion (gov.va.me d.imaging. storage.ca che.Cache,  java.lang .String, j ava.lang.S tring[])
  349            * /
  350           @O verride
  351           pu blic Regio n createRe gion(Cache  cache, St ring regio nName, Str ing[] evic tionStrate gyNames)
  352           th rows Cache Exception
  353           {
  354                    if(g etKnownCac hes().isKn ownCache(c ache) )
  355                    {
  356                             Region  region =  cache.crea teRegion(r egionName,  evictionS trategyNam es);
  357                             
  358                             cache. addRegion( region);
  359                             
  360                             try
  361                             {
  362                                      register RegionMBea n(cache, r egion);
  363                             } 
  364                             catch  (Exception  x)
  365                             {
  366                                      logger.w arn(x);
  367                             }
  368                             
  369                             return  region;
  370                    }
  371                    
  372                    retu rn null;
  373           }
  374           
  375           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== =
  376           //  
  377           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== =
  378           
  379           pr ivate fina l static S tring cach eManagerMB eanObjectN ame = "Vis taImaging. ViX:type=C acheManage rImpl,name =CacheMana gerImpl";
  380           pr ivate fina l static S tring cach eMBeanObje ctNamePref ix = "Vist aImaging.V iX:type=Ca che,name=" ;
  381           pr ivate fina l static S tring byte ChannelMBe anObjectNa mePrefix =  "VistaIma ging.ViX:t ype=CacheB yteChannel Factory,na me=";
  382           pr ivate fina l static S tring evic tionStrate gyMBeanObj ectNamePre fix = "Vis taImaging. ViX:type=C acheEvicti onStrategy ,name=";
  383           pr ivate fina l static S tring regi onMBeanObj ectNamePre fix = "Vis taImaging. ViX:type=C acheRegion ,name=";
  384           
  385           pr ivate Stri ng createC acheMBeanO bjectName( Cache cach e)
  386           {r eturn cach eMBeanObje ctNamePref ix + cache .getName() ; }
  387           
  388           pr ivate Stri ng createB yteChannel MBeanObjec tName(Cach e cache)
  389           {r eturn byte ChannelMBe anObjectNa mePrefix +  cache.get Name(); }
  390           
  391           pr ivate Stri ng createR egionMBean ObjectName (Cache cac he, Region  region)
  392           {r eturn regi onMBeanObj ectNamePre fix + cach e.getName( ) + "." +  region.get Name(); }
  393           
  394           pr ivate Stri ng createE victionStr ategyMBean ObjectName (Cache cac he, Evicti onStrategy  evictionS trategy)
  395           {r eturn evic tionStrate gyMBeanObj ectNamePre fix + cach e.getName( ) + "." +  evictionSt rategy.get Name(); }
  396           
  397           /* *
  398            *  Register  the cache  manager
  399            *  
  400            *  @param ca cheName
  401            * /
  402           pu blic void  registerCa cheManager MBean()
  403           {
  404                    MBea nServer mb s = Manage mentFactor y.getPlatf ormMBeanSe rver();
  405                    if(m bs != null )
  406                    {
  407                             try
  408                             {
  409                                      mbs.regi sterMBean( this, new  ObjectName (cacheMana gerMBeanOb jectName)) ;
  410                             } 
  411                             catch  (InstanceA lreadyExis tsExceptio n iaeX)
  412                             {
  413                                      logger.w arn("MBean  instance  '" + cache ManagerMBe anObjectNa me + "' al ready exis ts, regist ration is  being igno red");
  414                             }
  415                             catch  (Exception  x)
  416                             {
  417                                      logger.w arn("Unabl e to regis ter Cache  with JMX,  management  and monit oring will  not be av ailable",  x);
  418                             }
  419                    }
  420           }
  421           
  422           pr ivate void  registerC acheMBeans (Cache cac he)
  423           {
  424                    MBea nServer mb s = Manage mentFactor y.getPlatf ormMBeanSe rver();
  425                    
  426                    if(m bs != null )
  427                    {
  428                             try
  429                             {
  430                                      if( cach e instance of Dynamic MBean)
  431                                      {
  432                                               String cac heMBeanNam e = create CacheMBean ObjectName (cache);
  433                                               logger.inf o("Registe ring cache  '" + cach eMBeanName  + "'.");
  434                                              
  435                                               try
  436                                               {
  437                                                       mb s.register MBean(cach e, new Obj ectName(ca cheMBeanNa me));
  438                                               }
  439                                               catch(Inst anceAlread yExistsExc eption iae X)
  440                                               {
  441                                                       lo gger.warn( "MBean ins tance '" +  cacheMBea nName + "'  already e xists, att empt to re -register  is being i gnored.");
  442                                               }
  443                                      }
  444                                      
  445                                      logger.i nfo("Regis tering " +  cache.get EvictionSt rategies() .size() +  " eviction  strategie s for cach e '" + cac he.getName () + "'.") ;
  446                                      for(Evic tionStrate gy evictio nStrategy:  cache.get EvictionSt rategies() )
  447                                               registerEv ictionStra tegyMBean( cache, evi ctionStrat egy);
  448                    
  449                                      logger.i nfo("Regis tering " +  cache.get Regions(). size() + "  regions f or cache ' " + cache. getName()  + "'.");
  450                                      for(Regi on region  : cache.ge tRegions() )
  451                                               registerRe gionMBean( cache, reg ion);
  452                    
  453                                      if( cach e.getInsta nceByteCha nnelFactor y() instan ceof Dynam icMBean)
  454                                      {
  455                                               String byt eChannelMB eanName =  createByte ChannelMBe anObjectNa me(cache);
  456                                               logger.inf o("Registe ring byte  channel '"  + byteCha nnelMBeanN ame + "'." );
  457                                              
  458                                               try
  459                                               {
  460                                                       mb s.register MBean(cach e.getInsta nceByteCha nnelFactor y(), new O bjectName( byteChanne lMBeanName ));
  461                                              
  462                                               catch (Ins tanceAlrea dyExistsEx ception ia eX)
  463                                               {
  464                                                       lo gger.warn( "MBean ins tance '" +  byteChann elMBeanNam e + "' alr eady exist s, registr ation is b eing ignor ed");
  465                                               }
  466                                                       
  467                                      }
  468                             }
  469                             catch  (Exception  x)
  470                             {
  471                                      logger.w arn("Unabl e to regis ter Cache  with JMX,  management  and monit oring will  not be av ailable",  x);
  472                             }
  473                    }
  474           }
  475           
  476           pr ivate void  registerE victionStr ategyMBean (Cache cac he, Evicti onStrategy  evictionS trategy) 
  477           th rows Insta nceAlready ExistsExce ption, MBe anRegistra tionExcept ion, NotCo mpliantMBe anExceptio n, Malform edObjectNa meExceptio n, NullPoi nterExcept ion
  478           {
  479                    MBea nServer mb s = Manage mentFactor y.getPlatf ormMBeanSe rver();
  480                    
  481                    if(m bs != null )
  482                    {
  483                             String  evictionS trategyObj ectName =  createEvic tionStrate gyMBeanObj ectName(ca che, evict ionStrateg y);
  484                             logger .info("Reg istering e viction st rategy '"  + eviction StrategyOb jectName +  "'.");
  485                             try
  486                             {
  487                                      mbs.regi sterMBean(  evictionS trategy, n ew ObjectN ame(evicti onStrategy ObjectName ) );
  488                             } 
  489                             catch  (InstanceA lreadyExis tsExceptio n iaeX)
  490                             {
  491                                      logger.w arn("MBean  instance  '" + evict ionStrateg yObjectNam e + "' alr eady exist s, registr ation is b eing ignor ed");
  492                             }
  493                    }
  494           }
  495           
  496           pr ivate void  registerR egionMBean (Cache cac he, Region  region) 
  497           th rows Insta nceAlready ExistsExce ption, MBe anRegistra tionExcept ion, NotCo mpliantMBe anExceptio n, Malform edObjectNa meExceptio n, NullPoi nterExcept ion
  498           {
  499                    MBea nServer mb s = Manage mentFactor y.getPlatf ormMBeanSe rver();
  500                    
  501                    if(  mbs != nul l )
  502                    {
  503                             String  regionObj ectName =  createRegi onMBeanObj ectName(ca che, regio n);
  504                             logger .info("Reg istering r egion '" +  regionObj ectName +  "'.");
  505                             
  506                             try
  507                             {
  508                                      mbs.regi sterMBean(  region, n ew ObjectN ame(region ObjectName ) );
  509                             } 
  510                             catch  (InstanceA lreadyExis tsExceptio n iaeX)
  511                             {
  512                                      logger.w arn("MBean  instance  '" + regio nObjectNam e + "' alr eady exist s, registr ation is b eing ignor ed.");
  513                             }
  514                    }
  515           }
  516           
  517           pr ivate void  unregiste rCacheMBea ns(Cache c ache)
  518           {
  519                    MBea nServer mb s = Manage mentFactor y.getPlatf ormMBeanSe rver();
  520                    
  521                    if(m bs != null )
  522                    {
  523                             try
  524                             {
  525                                      if( cach e instance of Dynamic MBean)
  526                                      {
  527                                               String cac heMBeanNam e = create CacheMBean ObjectName (cache);
  528                                               try{mbs.un registerMB ean(new Ob jectName(c acheMBeanN ame));}
  529                                               catch(Inst anceNotFou ndExceptio n infX){lo gger.warn( infX);}                 // if th e MBean is  not regis tered then  don't wor ry 'bout i t
  530                                      }
  531                                      for(Evic tionStrate gy evictio nStrategy:  cache.get EvictionSt rategies() )
  532                                               try{unregi sterEvicti onStrategy MBean(cach e, evictio nStrategy) ;}
  533                                               catch(Inst anceNotFou ndExceptio n infX){lo gger.warn( infX);}                 // if th e MBean is  not regis tered then  don't wor ry 'bout i t
  534                    
  535                                      for(Regi on region  : cache.ge tRegions() )
  536                                               try{unregi sterRegion MBean(cach e, region) ;}
  537                                               catch(Inst anceNotFou ndExceptio n infX){lo gger.warn( infX);}                 // if th e MBean is  not regis tered then  don't wor ry 'bout i t
  538                    
  539                                      if( cach e.getInsta nceByteCha nnelFactor y() instan ceof Dynam icMBean)
  540                                      {
  541                                               String byt eChannelOb jectName =  createByt eChannelMB eanObjectN ame(cache) ;
  542                                               try{mbs.un registerMB ean(new Ob jectName(b yteChannel ObjectName ));}
  543                                               catch(Inst anceNotFou ndExceptio n infX){lo gger.warn( infX);}                 // if th e MBean is  not regis tered then  don't wor ry 'bout i t
  544                                      }
  545                             }
  546                             catch  (Exception  x)
  547                             {
  548                                      logger.w arn("Unabl e to unreg ister Cach e with JMX , manageme nt and mon itoring fo r new inst ances may  not be ava ilable", x );
  549                             }
  550                    }
  551           }
  552           pr ivate void  unregiste rEvictionS trategyMBe an(Cache c ache, Evic tionStrate gy evictio nStrategy)  
  553           th rows Insta nceAlready ExistsExce ption, MBe anRegistra tionExcept ion, NotCo mpliantMBe anExceptio n, Malform edObjectNa meExceptio n, NullPoi nterExcept ion, Insta nceNotFoun dException
  554           {
  555                    MBea nServer mb s = Manage mentFactor y.getPlatf ormMBeanSe rver();
  556                    
  557                    if(m bs != null  && evicti onStrategy  instanceo f DynamicM Bean)
  558                    {
  559                             String  evictionS trategyObj ectName =  createEvic tionStrate gyMBeanObj ectName(ca che, evict ionStrateg y);
  560                             logger .info("Unr egistering  eviction  strategy ' " + evicti onStrategy ObjectName  + "'.");
  561                             
  562                             mbs.un registerMB ean( new O bjectName( evictionSt rategyObje ctName) );
  563                    }
  564           }
  565           
  566           pr ivate void  unregiste rRegionMBe an(Cache c ache, Regi on region)  
  567           th rows Insta nceAlready ExistsExce ption, MBe anRegistra tionExcept ion, NotCo mpliantMBe anExceptio n, Malform edObjectNa meExceptio n, NullPoi nterExcept ion, Insta nceNotFoun dException
  568           {
  569                    MBea nServer mb s = Manage mentFactor y.getPlatf ormMBeanSe rver();
  570                    
  571                    if(  mbs != nul l && regio n instance of Dynamic MBean)
  572                    {
  573                             String  regionObj ectName =  createRegi onMBeanObj ectName(ca che, regio n);
  574                             logger .info("Unr egistering  region '"  + regionO bjectName  + "'.");
  575                             
  576                             mbs.un registerMB ean( new O bjectName( regionObje ctName) );
  577                    }
  578           }
  579           
  580           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== === 
  581           //  CacheLife cycleListe ner Implem entation
  582           //  These are  messages  from the a pp server,  abstracte d by a pla tform spec ific class
  583           //  to our se mantics
  584           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ===
  585           
  586           
  587           /* *
  588        * @se e gov.va.m ed.server. ServerLife cycleListe ner#server LifecycleE vent(gov.v a.med.serv er.ServerL ifecycleEv ent)
  589        * Tra nslate the  server li fecycle me ssages to  the cache  lifecycle  messages,  removing t he depende ncy
  590        * tha t the cach e even be  in a serve r environm ent.
  591        * Thi s replaces  the Cache LifecycleE vent handl ing in V-O ne.
  592        */
  593       @Overr ide
  594       public  void serv erLifecycl eEvent(Ser verLifecyc leEvent ev ent)
  595       {
  596                    bool ean previo usServerRu nning = se rverRunnin g;
  597                    
  598                    Cach eLifecycle Event cach eLifecycle Event = nu ll;
  599                    
  600                    if(e vent.getEv entType(). equals(Ser verLifecyc leEvent.Ev entType.ST ART))
  601                    {
  602                             server Running =  true;
  603                             cacheL ifecycleEv ent = Cach eLifecycle Event.STAR T;
  604                    }
  605                    if(e vent.getEv entType(). equals(Ser verLifecyc leEvent.Ev entType.ST OP))
  606                    {
  607                             server Running =  false;
  608                             cacheL ifecycleEv ent = Cach eLifecycle Event.STOP ;
  609                    }
  610                    
  611                    // i f this rep resents an  actual se rver runni ng state c hange then  pass
  612                    // i t on to th e cache in stances
  613                    if(p reviousSer verRunning  != server Running)
  614                    {
  615                             for( C ache cache  : getKnow nCaches()  )
  616                                      // if th e cache is  initializ ed, pass t his on to  the cache
  617                                      if(cache .isInitial ized())
  618                                      {
  619                                               try
  620                                               {
  621                                                       ca che.cacheL ifecycleEv ent(cacheL ifecycleEv ent);
  622                                              
  623                                               catch (Cac heStateExc eption x)
  624                                               {
  625                                                       lo gger.error (x);
  626                                               }
  627                                      }
  628                    }
  629       }
  630  
  631           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== === 
  632           //  DynamicMB ean Implem entation
  633           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ===
  634           @O verride
  635           pu blic MBean Info getMB eanInfo() 
  636           {
  637                    try
  638                    {
  639                             // the  MBeanInfo  must be r egenerated  because t he state o f some
  640                             // ope rations ma y change
  641                             return  createMBe anInfo();
  642                    } 
  643                    catc h (OpenDat aException  x)
  644                    {
  645                             logger .error(x);
  646                             return  null;
  647                    }
  648           }
  649           
  650           pr ivate Open MBeanInfoS upport cre ateMBeanIn fo() 
  651           th rows OpenD ataExcepti on
  652           {
  653           re turn new O penMBeanIn foSupport(
  654                             FileSy stemCache. class.getN ame(), 
  655                             "Cache  Managemen t (initial izing, ena bling, sto ring)", 
  656                             create MBeanAttri buteInfo()
  657                             create MBeanConst ructorInfo (), 
  658                                      createMB eanOperati onInfo(), 
  659                                      createMB eanNotific ationInfo( )
  660                             );
  661           }
  662  
  663           /* *
  664            *  
  665            *  @param ca che
  666            *  @throws O penDataExc eption 
  667            * /
  668           pr ivate Open MBeanAttri buteInfo[]  createMBe anAttribut eInfo() 
  669           th rows OpenD ataExcepti on
  670           {
  671                    List <OpenMBean AttributeI nfo> attri butes = ne w ArrayLis t<OpenMBea nAttribute Info>();
  672  
  673                    attr ibutes.add (
  674                             new Op enMBeanAtt ributeInfo Support("k nownCacheN ames", "A  comma sepe rated list  of known  cache name s", Simple Type.STRIN G, true, f alse, fals e)
  675                    );
  676                    
  677                    retu rn attribu tes.toArra y(new Open MBeanAttri buteInfo[a ttributes. size()]);
  678           }
  679  
  680           pr ivate Open MBeanConst ructorInfo [] createM BeanConstr uctorInfo( )
  681           {
  682           re turn new O penMBeanCo nstructorI nfoSupport []
  683           {
  684                             
  685           };
  686           }
  687           
  688           pr ivate MBea nNotificat ionInfo[]  createMBea nNotificat ionInfo()
  689           {
  690                    retu rn new MBe anNotifica tionInfo[]
  691                    {
  692                                      
  693                    };
  694           }
  695  
  696           pr ivate fina l static S tring init ializePref ix = "init ialize-";
  697           pr ivate fina l static S tring enab lePrefix =  "enable-" ;
  698           pr ivate fina l static S tring disa blePrefix  = "disable -";
  699           pr ivate fina l static S tring stor eOperation  = "store" ;
  700           pr ivate fina l static S tring stor eAllOperat ion = "sto reAll";
  701           pr ivate fina l static S tring crea teOperatio n = "creat eCache";
  702           
  703           /* *
  704            *  The opera tions are  pulled fro m the core  cache and  the membe r regions.
  705            *  @param ca che 
  706            *
  707            * /
  708           pr ivate Open MBeanOpera tionInfo[]  createMBe anOperatio nInfo()
  709           {
  710                    List <OpenMBean OperationI nfo> opera tions = ne w ArrayLis t<OpenMBea nOperation Info>();
  711                    
  712                    for( Cache cach e : getKno wnCaches() )
  713                    {
  714                             if(cac he != null  && !cache .isInitial ized())
  715                                      operatio ns.add(
  716                                      new Open MBeanOpera tionInfoSu pport(init ializePref ix + cache .getName()
  717                                                       "I nitialize  the cache  (root dire ctory must  be set fi rst) \n" +
  718                                                       "T his action  is ignore d if the c ache is in itialized. \n" + 
  719                                                       "I f the cach e has been  started w ith a vali d configur ation stat e availabl e \n" +
  720                                                       "i t will sta rt in an i nitialized  state.  C hanges to  configurat ion will t hen requir e a restar t of the s erver.", 
  721                                                       ne w OpenMBea nParameter Info[]{}, 
  722                                                       Si mpleType.V OID, MBean OperationI nfo.ACTION )
  723                             );
  724           
  725                             if(cac he != null  && cache. isInitiali zed() && ! cache.isEn abled() )
  726                                      operatio ns.add(
  727                                      new Open MBeanOpera tionInfoSu pport(enab lePrefix +  cache.get Name(), 
  728                                                       "E nable the  cache (cac he must be  initializ ed)", 
  729                                                       ne w OpenMBea nParameter Info[]{}, 
  730                                                       Si mpleType.V OID, MBean OperationI nfo.ACTION )
  731                             );
  732                             
  733                             else i f(cache !=  null && c ache.isEna bled())
  734                                      operatio ns.add(
  735                                      new Open MBeanOpera tionInfoSu pport(disa blePrefix  + cache.ge tName(), 
  736                                                       "D isable the  cache (ca che must b e initiali zed and en abled)", 
  737                                                       ne w OpenMBea nParameter Info[]{}, 
  738                                                       Si mpleType.V OID, MBean OperationI nfo.ACTION )
  739                             );
  740                    }
  741                    
  742                    oper ations.add (
  743                             new Op enMBeanOpe rationInfo Support(st oreOperati on, 
  744                                               "Store the  named cac he configu ration to  persistent  storage",  
  745                                               new OpenMB eanParamet erInfo[]{n ew OpenMBe anParamete rInfoSuppo rt("name",  "the bnam e of the c ache to sa ve configu ration of" , SimpleTy pe.STRING) }, 
  746                                               SimpleType .VOID, MBe anOperatio nInfo.ACTI ON)
  747                    );
  748                    
  749                    oper ations.add (
  750                             new Op enMBeanOpe rationInfo Support(st oreAllOper ation, 
  751                                               "Store all  current c ache confi guration t o persiste nt storage ", 
  752                                               new OpenMB eanParamet erInfo[]{}
  753                                               SimpleType .VOID, MBe anOperatio nInfo.ACTI ON)
  754                    );
  755                    
  756                    oper ations.add (
  757                    new  OpenMBeanO perationIn foSupport( createOper ation, 
  758                                      "Create  a new cach e at the s pecified l ocation.",  
  759                                      new Open MBeanParam eterInfo[]
  760                                      {
  761                                               new OpenMB eanParamet erInfoSupp ort("cache Name", "Th e name of  the cache  (and the r oot of the  configura tion file  name)", Si mpleType.S TRING),
  762                                               new OpenMB eanParamet erInfoSupp ort("cache Location",  "The URI  of the cac he locatio n (e.g. 'f ile:///vix /cache' or  'smb://se rver/cache root')", S impleType. STRING),
  763                                               new OpenMB eanParamet erInfoSupp ort("proto typeName",  "The name  of the pr ototype or  blank(e.g . 'VixProt otype', 'T estWithEvi ctionProto type')", S impleType. STRING)
  764                                      }, 
  765                                      SimpleTy pe.STRING,  
  766                                      MBeanOpe rationInfo .ACTION)
  767           );
  768                    
  769                    retu rn operati ons.toArra y(new Open MBeanOpera tionInfoSu pport[oper ations.siz e()]);
  770           }
  771  
  772           @O verride
  773           pu blic Objec t getAttri bute(Strin g attribut e) 
  774           th rows Attri buteNotFou ndExceptio n, MBeanEx ception, R eflectionE xception
  775           {
  776                    if(" knownCache Names".equ als(attrib ute))
  777                    {
  778                             String Builder sb  = new Str ingBuilder ();
  779                             for(Ca che cache  : getKnown Caches())
  780                             {
  781                                      if(sb.le ngth() > 0 )
  782                                               sb.append( ",");
  783                                      sb.appen d(cache.ge tName());
  784                             }
  785                             
  786                             return  sb.toStri ng();
  787                    }
  788                    else
  789                             return  super.get Attribute( attribute) ;
  790           }
  791  
  792           @O verride
  793           pu blic void  setAttribu te(Attribu te attribu te) 
  794           th rows Attri buteNotFou ndExceptio n, Invalid AttributeV alueExcept ion, MBean Exception,  Reflectio nException
  795           {
  796                    supe r.setAttri bute(attri bute);
  797           }
  798  
  799           @O verride
  800           pu blic Objec t invoke(S tring acti onName, Ob ject[] par ams, Strin g[] signat ure) 
  801           th rows MBean Exception,  Reflectio nException
  802           {
  803                    
  804                    if(a ctionName. startsWith (initializ ePrefix))
  805                    {
  806                             String  cacheName  = actionN ame.substr ing(initia lizePrefix .length()) ;
  807                             logger .info("Pro cessing re quest to i nitialize  cache '" +  cacheName  + "'.");
  808                             return  initializ e(getKnown Caches().g et(cacheNa me));
  809                    }
  810                    else  if(action Name.start sWith(enab lePrefix))
  811                    {
  812                             String  cacheName  = actionN ame.substr ing(initia lizePrefix .length()) ;
  813                             logger .info("Pro cessing re quest to e nable cach e '" + cac heName + " '.");
  814                             return  enable(ge tKnownCach es().get(c acheName)) ;
  815                    }
  816                    else  if(action Name.start sWith(disa blePrefix) )
  817                    {
  818                             String  cacheName  = actionN ame.substr ing(initia lizePrefix .length()) ;
  819                             logger .info("Pro cessing re quest to d isable cac he '" + ca cheName +  "'.");
  820                             return  disable(g etKnownCac hes().get( cacheName) );
  821                    }
  822                    else  if(storeO peration.e quals(acti onName))
  823                    {
  824                             String  cacheName  = (String )params[0] ;
  825                             try
  826                             {
  827                                      Cache ca che = getC ache(cache Name);
  828                                      logger.i nfo("Proce ssing requ est to sto re configu ration of  '" + cache Name + "'. ");
  829                                      store(ca che);
  830                             }
  831                             catch  (Exception  x)
  832                             {
  833                                      logger.e rror("Erro r storing  configurat ion of '"  + cacheNam e + "'.");
  834                                      throw ne w MBeanExc eption(x);
  835                             }
  836                             return  "Cache co nfiguratio n stored." ;
  837                    }
  838                    else  if(storeA llOperatio n.equals(a ctionName) )
  839                    {
  840                             try
  841                             {
  842                                      logger.i nfo("Proce ssing requ est to sto re configu ration of  all known  caches.");
  843                                      storeAll ();
  844                             }
  845                             catch  (Exception  x)
  846                             {
  847                                      logger.e rror("Erro r storing  configurat ion to per sistent st orage.", x );
  848                                      throw ne w MBeanExc eption(x);
  849                             }
  850                             return  "All cach e configur ations sto red.";
  851                    }
  852                    else  if(create Operation. equals(act ionName) &
  853                                      signatur e.length = = 3 && 
  854                                      params[0 ] instance of String  && 
  855                                      params[1 ] instance of String  && 
  856                                      params[2 ] instance of String  )
  857                    {
  858                             String  cacheName  = (String )params[0] ;
  859                             String  cacheLoca tion = (St ring)param s[1];
  860                             String  prototype Name = (St ring)param s[2];
  861                             
  862                             try
  863                             {
  864                                      logger.i nfo("Proce ssing requ est to cre ate cache  '" + cache Name + "'  at '" + ca cheLocatio n + "' as  '" + proto typeName +  "'." );
  865                                      getKnown Caches().c reate(cach eName, new  URI(cache Location),  prototype Name);
  866                             } 
  867                             catch  (Exception  x)
  868                             {
  869                                      throw ne w MBeanExc eption(x);
  870                             }
  871                             return  "Cache '"  + cacheNa me + "' cr eated at ' " + cacheL ocation +  "' as '" +  prototype Name + "'. ";
  872                    }
  873                    
  874                    retu rn super.i nvoke(acti onName, pa rams, sign ature);
  875           }
  876  
  877           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== =
  878           
  879           /* *
  880            *  Return a  refererenc e to the c onfigurati on directo ry, creati ng
  881            *  directori es as nece ssary to a ssure it e xists befo re returni ng.
  882            * /
  883           pr ivate File  getConfig urationDir ectory()
  884           {
  885                    Stri ng rootCon figDirName  = System. getenv("vi xconfig");
  886                    if(r ootConfigD irName ==  null)
  887                             rootCo nfigDirNam e = defaul tConfigura tionDirect oryName;
  888                    
  889                    File  rootConfi gDir = new  File(root ConfigDirN ame);
  890                    if(  ! rootConf igDir.exis ts() )
  891                             rootCo nfigDir.mk dirs();
  892  
  893                    // t he cache c onfigurati on is in a  subdirect ory of the  configura tion direc tory
  894                    File  cacheConf igDir = ne w File(roo tConfigDir , cacheCon figuration Subdirecto ryName);
  895                    if(  ! cacheCon figDir.exi sts() )
  896                             cacheC onfigDir.m kdirs();
  897                    
  898                    
  899                    retu rn cacheCo nfigDir;
  900           }
  901  
  902           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ==========
  903           //  interface  CacheStru ctureChang eListener  realizatio n
  904           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ==========
  905           @O verride
  906           pu blic void  cacheStruc tureChange d(Cache ca che)
  907           {
  908                    unre gisterCach eMBeans(ca che);
  909                    regi sterCacheM Beans(cach e);
  910           }
  911           
  912           @O verride
  913           pu blic void  evictionSt rategyAdde d(Cache ca che, Evict ionStrateg y newEvict ionStrateg y)
  914           {
  915                    try
  916                    {
  917                             regist erEviction StrategyMB ean(cache,  newEvicti onStrategy );
  918                    } 
  919                    catc h (Excepti on x)
  920                    {
  921                             logger .warn(x);
  922                    }
  923           }
  924  
  925           @O verride
  926           pu blic void  evictionSt rategyRemo ved(Cache  cache, Evi ctionStrat egy oldEvi ctionStrat egy)
  927           {
  928                    try
  929                    {
  930                             unregi sterEvicti onStrategy MBean(cach e, oldEvic tionStrate gy);
  931                    } 
  932                    catc h (Excepti on x)
  933                    {
  934                             logger .warn(x);
  935                    }
  936           }
  937  
  938           @O verride
  939           pu blic void  regionAdde d(Cache ca che, Regio n newRegio n)
  940           {
  941                    try
  942                    {
  943                             regist erRegionMB ean(cache,  newRegion );
  944                    } 
  945                    catc h (Excepti on x)
  946                    {
  947                             logger .warn(x);
  948                    }
  949           }
  950  
  951           @O verride
  952           pu blic void  regionRemo ved(Cache  cache, Reg ion oldReg ion)
  953           {
  954                    try
  955                    {
  956                             unregi sterRegion MBean(cach e, oldRegi on);
  957                    } 
  958                    catc h (Excepti on x)
  959                    {
  960                             logger .warn(x);
  961                    }
  962           }
  963  
  964           @O verride
  965           pu blic Refer ence getRe ference() 
  966           th rows Namin gException
  967           {
  968                    retu rn new Ref erence(thi s.getClass ().getName (), CacheR esourceRef erenceFact ory.class. getName(),  null);
  969           }
  970   }