344. EPMO Open Source Coordination Office Redaction File Detail Report

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

344.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ROICommands\main\src\java\gov\va\med\imaging\roi\cache AbstractROICache.java Mon Dec 4 21:35:04 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ROICommands\main\src\java\gov\va\med\imaging\roi\cache AbstractROICache.java Mon Dec 4 22:05:20 2017 UTC

344.2 Comparison summary

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

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

344.4 Active regular expressions

No regular expressions were active.

344.5 Comparison detail

  1   /**
  2    * 
  3     Package:  MAG - Vis tA Imaging
  4     WARNING:  Per VHA D irective 2 004-038, t his routin e should n ot be modi fied.
  5     Date Cre ated: Apr  4, 2012
  6     Site Nam e:  Washin gton OI Fi eld Office , Silver S pring, MD
  7       Developer:          
WERFEJ
  8     Descript ion: 
  9  
  10           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  11           ;;  Property  of the US  Government .
  12           ;;  No permis sion to co py or redi stribute t his softwa re is give n.
  13           ;;  Use of un released v ersions of  this soft ware requi res the us er
  14           ;;   to execu te a writt en test ag reement wi th the Vis tA Imaging
  15           ;;   Developm ent Office  of the De partment o f Veterans  Affairs,
  16           ;;   telephon e (301) 73 4-0100.
  17           ;;
  18           ;;  The Food  and Drug A dministrat ion classi fies this  software a s
  19           ;;  a Class I I medical  device.  A s such, it  may not b e changed
  20           ;;  in any wa y.  Modifi cations to  this soft ware may r esult in a n
  21           ;;  adulterat ed medical  device un der 21CFR8 20, the us e of which
  22           ;;  is consid ered to be  a violati on of US F ederal Sta tutes.
  23           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  24  
  25    */
  26   package go v.va.med.i maging.roi .cache;
  27  
  28   import gov .va.med.im aging.chan nels.ByteS treamPump;
  29   import gov .va.med.im aging.exch ange.stora ge.cache.I mmutableIn stance;
  30   import gov .va.med.im aging.rout er.command s.CommonIm ageCacheFu nctions;
  31   import gov .va.med.im aging.rout er.command s.provider .ImagingCo mmandConte xt;
  32   import gov .va.med.im aging.stor age.cache. InstanceRe adableByte Channel;
  33   import gov .va.med.im aging.stor age.cache. InstanceRe adableVO;
  34   import gov .va.med.im aging.stor age.cache. InstanceWr itableByte Channel;
  35   import gov .va.med.im aging.stor age.cache. exceptions .CacheExce ption;
  36   import gov .va.med.im aging.stor age.cache. exceptions .InstanceI naccessibl eException ;
  37   import gov .va.med.im aging.stor age.cache. exceptions .InstanceU navailable Exception;
  38  
  39   import jav a.io.IOExc eption;
  40   import jav a.io.Input Stream;
  41   import jav a.io.Outpu tStream;
  42   import jav a.nio.chan nels.Chann els;
  43  
  44   import org .apache.lo gging.log4 j.LogManag er;
  45   import org .apache.lo gging.log4 j.Logger;
  46  
  47   /**
  48    * @author         
WERFEJ
  49    *
  50    */
  51   public abs tract clas s Abstract ROICache
  52   {
  53           pr ivate fina l static L ogger logg er = LogMa nager.getL ogger(Abst ractROICac he.class);
  54           
  55           pr otected Lo gger getLo gger()
  56           {
  57                    retu rn logger;
  58           }
  59           
  60           pr otected fi nal Imagin gCommandCo ntext comm andContext ;
  61  
  62           pu blic Abstr actROICach e(ImagingC ommandCont ext comman dContext)
  63           {
  64                    this .commandCo ntext = co mmandConte xt;
  65           }
  66           
  67           pr otected ab stract Str ing getCac heItemName ();
  68           
  69           pr otected ab stract Str ing getCac heItemDesc ription();
  70           
  71           pr otected ab stract Imm utableInst ance creat eCacheItem ()
  72           th rows Cache Exception;
  73           
  74           pr otected ab stract Imm utableInst ance getIt emFromCach e()
  75           th rows Cache Exception;
  76           
  77           pu blic void  cacheItem( InputStrea m inputStr eam)
  78           {
  79                    if(c ommandCont ext.isCach ingEnabled ()) 
  80                    {
  81                             if(inp utStream = = null)
  82                                      return ;
  83                             getLog ger().info ("Caching  " + getCac heItemName () + " for  " + getCa cheItemDes cription() );
  84  
  85                             Immuta bleInstanc e instance  = null;
  86                             Instan ceWritable ByteChanne l instance WritableCh annel = nu ll;
  87                             Output Stream cac heOutStrea m = null;
  88                             try
  89                             {                                  
  90                                      instance  = createC acheItem() ;                             
  91           
  92                                      instance WritableCh annel = in stance.get WritableCh annel();
  93                                      cacheOut Stream = C hannels.ne wOutputStr eam(instan ceWritable Channel);
  94                                      ByteStre amPump pum p = ByteSt reamPump.g etByteStre amPump(Byt eStreamPum p.TRANSFER _TYPE.Netw orkToNetwo rk);
  95                                      // if th e cacheStr eam is nul l the Byte StreamPump  will igno re it
  96                                      pump.xfe r(inputStr eam, cache OutStream) ;
  97                                      if(input Stream !=  null)
  98                                      {
  99                                               getLogger( ).debug("C losing " +  getCacheI temName()  + " input  stream aft er writing  to the ca che");
  100                                               inputStrea m.close();
  101                                      }
  102                                      cacheOut Stream.clo se();
  103                                      getLogge r().info(g etCacheIte mName() +  " cached." );
  104                             }
  105                             catch( InstanceIn accessible Exception  iaX)
  106                             {
  107                                      // speci al excepti on handlin g, another  thread is  requestin g to write  to the in stance
  108                                      // just  before we  did.  Try  once again  to read f rom the ca che, our t hread will  be held u ntil
  109                                      // the w rite is co mplete
  110                                      getLogge r().debug( iaX);
  111                             }
  112                             catch( CacheExcep tion cX)
  113                             {
  114                                      // any k ind of cac he excepti ons should  be logged , but the  image must  still be  retreived  from the D oD
  115                                      // from  here on if  cacheOutS tream is n ot null we 'll write  to it 
  116                                      getLogge r().error( cX);
  117                                      instance  = null;
  118                                      instance WritableCh annel= nul l;
  119                                      cacheOut Stream = n ull;
  120                             }
  121                             catch( IOExceptio n ioX)
  122                             {
  123                                      getLogge r().error( ioX);
  124                             }
  125                    }                 
  126           }
  127           
  128           pu blic Input Stream get InputStrea mItemFromC ache()
  129           th rows IOExc eption
  130           {
  131                    Inst anceReadab leVO reada bleVO = ge tCacheItem ReadableCh annelFromC ache();
  132                    Inst anceReadab leByteChan nel cacheR eadChannel  = (readab leVO == nu ll ? null  : readable VO.getRead ByteChanne l());
  133                    if(r eadableVO  != null &&  cacheRead Channel !=  null)
  134                    {
  135                             // ima ge is in t he cache a nd we have  a usable  ReadableBy teChannel,                
  136  
  137                             // ima ge is in t he cache a nd we have  a usable  ReadableBy teChannel,  return th e stream.
  138                             InputS tream cach eInStream  = Channels .newInputS tream(cach eReadChann el);                    
  139                             return  cacheInSt ream;
  140                    }
  141                    retu rn null;
  142           }
  143           
  144           pu blic int s treamItemF romCache(
  145                             Output Stream out Stream)
  146           th rows IOExc eption
  147           {
  148                    int  bytesOut =  0;                //  return va lue indica tes how ma ny bytes w ere sent.
  149                    Inst anceReadab leVO reada bleVO = ge tCacheItem ReadableCh annelFromC ache();
  150                    Inst anceReadab leByteChan nel cacheR eadChannel  = (readab leVO == nu ll ? null  : readable VO.getRead ByteChanne l());
  151                    if(r eadableVO  != null &&  cacheRead Channel !=  null)
  152                    {
  153                             // ima ge is in t he cache a nd we have  a usable  ReadableBy teChannel,  
  154                             // not ify the ch ecksum not ification  listener i f it exist s
  155                             //TODO : actually  know the  file lengt h and set  it here so  that we c an respond  with the  correct fi le length!
  156  
  157                             // ima ge is in t he cache a nd we have  a usable  ReadableBy teChannel,  stream th e image
  158                             InputS tream cach eInStream  = Channels .newInputS tream(cach eReadChann el);
  159  
  160                             // get  a byte st ream pump  from file  (cache) to  network ( client)
  161                             ByteSt reamPump p ump = Byte StreamPump .getByteSt reamPump(B yteStreamP ump.TRANSF ER_TYPE.Fi leToNetwor k);
  162                             // onc e we start  the trans fer we are  committed  to readin g from the  cache, 
  163                             // i.e . failures  result in  errors, n ot retries  from DOD
  164                             try
  165                             {
  166                                      bytesOut =pump.xfer (cacheInSt ream, outS tream);
  167                                      getLogge r().debug( "Pumped ["  + bytesOu t + "] byt es to outp ut stream" );
  168                             }
  169                             catch( IOExceptio n ioX) 
  170                             {
  171                                      getLogge r().error( ioX); 
  172                                      throw io X;
  173                             }
  174                             catch( IllegalArg umentExcep tion iaX)
  175                             {
  176                                      getLogge r().error( iaX);
  177                                      bytesOut  = 0;
  178                             }
  179                             finall y
  180                             {
  181                                      try{cach eInStream. close();}
  182                                      catch(IO Exception  ioX)
  183                                      {
  184                                               getLogger( ).warn("IO Exception  caught whe n closing  '" + getCa cheItemDes cription()  + "', cha nnel may h ave been c losed earl ier with a  timeout." );
  185                                      }
  186                             }
  187                    }
  188                    getL ogger().de bug("Retur ning [" +  bytesOut +  "] bytes" );
  189                    retu rn bytesOu t;
  190           }
  191           
  192           pr ivate Inst anceReadab leVO getCa cheItemRea dableChann elFromCach e()
  193           {                 
  194                    try
  195                    {
  196                             Immuta bleInstanc e instance  = getCach eItemImmut ableInstan ce();
  197                             
  198                             // try  to get im age from C ache
  199                             for( i nt retryCo unt = 0; i nstance !=  null && r etryCount  < CommonIm ageCacheFu nctions.ca cheReadRet ry; ++retr yCount) 
  200                             {
  201                                      getLogge r().info(g etCacheIte mName() +  " for " +  getCacheIt emDescript ion() + "  in cache,  returning  readable b yte channe l.");
  202  
  203                                      // try b lock for r etry-able  exceptions
  204                                      try 
  205                                      {
  206                                               InstanceRe adableByte Channel re sult = ins tance.getR eadableCha nnel();
  207                                               String che cksumValue  = instanc e.getCheck sumValue() ;
  208  
  209                                               getLogger( ).info("In stanceRead ableByteCh annel obta ined on re try #" + r etryCount  + ".");
  210                                               return new  InstanceR eadableVO( result, ch ecksumValu e);
  211                                      }
  212                                      // cache  access re sulting in  an Instan ceUnavaila bleExcepti on may be  reasonably  retried
  213                                      catch (I nstanceUna vailableEx ception iu e) 
  214                                      {
  215                                               getLogger( ).info("In stanceUnav ailableExc eption cau ght (#" +  retryCount  + ((retry Count < Co mmonImageC acheFuncti ons.cacheR eadRetry)  ? " -> ret ry): " : "  FAILING):  ") + iue. getMessage ());
  216                                               try
  217                                               {
  218                                                       Th read.sleep (CommonIma geCacheFun ctions.cac heReadRetr yDelay);
  219                                              
  220                                               catch (Int erruptedEx ception x)
  221                                               {
  222                                                       ge tLogger(). warn(x);
  223                                                       re turn null;
  224                                               }
  225                                      }
  226                             }
  227                    }
  228  
  229                    // = ========== ========== ========== ========== ========== ========== ========== ========== ========== ==
  230                    // t hese excep tions shou ld elicit  an immedia te exit, n o retries  cause it w on't do an y good
  231                    // = ========== ========== ========== ========== ========== ========== ========== ========== ========== ==
  232                    // c aught when  the writi ng thread  still has  the file l ocked
  233                    // I  don't see  that a re try should  be done h ere becaus e the
  234                    // c ache has a lready hel d this thr ead waitin g for the  writable c hannel to  close.  
  235                    // A  retry jus t effectiv ely length ens the wa it time th at the cac he already  implement s.
  236                    // I nstanceWri tableChann elOpenExce ption
  237                    catc h (Instanc eInaccessi bleExcepti on idne) 
  238                    {
  239                             getLog ger().erro r(idne);
  240                    }
  241                    catc h(CacheExc eption cX)  
  242                    {
  243                             getLog ger().erro r(cX);
  244                    }
  245  
  246                    retu rn null;
  247           }
  248           
  249           
  250           
  251           pr ivate Immu tableInsta nce getCac heItemImmu tableInsta nce()
  252           {
  253                    Immu tableInsta nce instan ce = null;
  254                    try
  255                    {
  256                             instan ce = getIt emFromCach e();                    
  257                    } 
  258                    catc h (CacheEx ception cX )
  259                    {
  260                             getLog ger().erro r(cX);
  261                             instan ce = null;  // not re ally neces sary but m akes it cl earer that  the excep tion is tr eated as n o instance  in the ca che
  262                    }
  263                    
  264                    if(i nstance !=  null)
  265                             getLog ger().info (getCacheI temName()  +  " for "  + getCach eItemDescr iption() +  " in cach e, returni ng readabl e byte cha nnel.");
  266                    else
  267                             getLog ger().info (getCacheI temName()  +  " for "  + getCach eItemDescr iption() +  " NOT in  cache.");
  268                             
  269                    retu rn instanc e;
  270           }
  271  
  272   }