31. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 3/25/2019 8:58:02 AM Central Daylight 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.

31.1 Files compared

# Location File Last Modified
1 C:\AraxisMergeCompare\Pri_un\IMAG_Source\VISA\Java\ImagingCacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl\jcifs JcifsByteChannelFactory.java Mon Mar 18 20:39:17 2019 UTC
2 C:\AraxisMergeCompare\Pri_re\IMAG_Source\VISA\Java\ImagingCacheImpl\main\src\java\gov\va\med\imaging\storage\cache\impl\jcifs JcifsByteChannelFactory.java Tue Mar 19 12:03:42 2019 UTC

31.2 Comparison summary

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

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

31.4 Active regular expressions

No regular expressions were active.

31.5 Comparison detail

  1   /**
  2    * 
  3    */
  4   package go v.va.med.i maging.sto rage.cache .impl.jcif s;
  5  
  6  
  7   import gov .va.med.im aging.Stac kTraceAnal yzer;
  8   import gov .va.med.im aging.stor age.cache. *;
  9   import gov .va.med.im aging.stor age.cache. exceptions .CacheExce ption;
  10   import gov .va.med.im aging.stor age.cache. exceptions .CacheStat eException ;
  11   import gov .va.med.im aging.stor age.cache. exceptions .Persisten ceIOExcept ion;
  12   import gov .va.med.im aging.stor age.cache. memento.By teChannelF actoryMeme nto;
  13  
  14   import jav a.io.IOExc eption;
  15   import jav a.text.Dat eFormat;
  16   import jav a.text.Sim pleDateFor mat;
  17   import jav a.util.*;
  18  
  19   import jav ax.managem ent.*;
  20   import jav ax.managem ent.openmb ean.*;
  21  
  22   import jci fs.smb.Smb File;
  23  
  24   import org .apache.lo gging.log4 j.LogManag er;
  25   import org .apache.lo gging.log4 j.Logger;
  26  
  27   /**
  28    * @author   DN S      BECKEC
  29    *
  30    * A facto ry class t hat provid es some ma nagement o f instance  file chan nels.
  31    * 
  32    */
  33   public cla ss JcifsBy teChannelF actory 
  34   implements  InstanceB yteChannel Factory<Sm bFile>, Dy namicMBean , CacheLif ecycleList ener
  35   {
  36           pu blic stati c final lo ng default MaxChannel OpenDurati on = 30000 0L;        // long de fault fore  remote ju keboxes
  37           pu blic stati c final lo ng default SweepTime  = 10000L;
  38           pu blic stati c final bo olean defa ultTraceCh annelInsta ntiation =  true;
  39           
  40           pr ivate Date Format df  = new Simp leDateForm at("ddMMMy yyy hh:mm: ss");
  41           
  42           pr ivate long  maxChanne lOpenDurat ion = defa ultMaxChan nelOpenDur ation;
  43           pr ivate long  sweepTime  = default SweepTime;
  44           pr ivate bool ean traceC hannelInst antiation  = defaultT raceChanne lInstantia tion;
  45           
  46           Lo gger log =  LogManage r.getLogge r(this.get Class());
  47           pr ivate Chan nelCleanup Thread cle anupThread ;
  48           
  49           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ======
  50           //  Factory M ethods
  51           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ======
  52           pu blic stati c JcifsByt eChannelFa ctory crea te()
  53           {
  54                    retu rn new Jci fsByteChan nelFactory (defaultMa xChannelOp enDuration , defaultS weepTime);
  55           }
  56           
  57           pu blic stati c JcifsByt eChannelFa ctory crea te(ByteCha nnelFactor yMemento m emento)
  58           {
  59                    retu rn new Jci fsByteChan nelFactory (memento);
  60           }
  61           
  62           /* *
  63            *  
  64            *  @param me mento
  65            * /
  66           pr ivate Jcif sByteChann elFactory( ByteChanne lFactoryMe mento meme nto)
  67           {
  68                    this (
  69                             mement o == null  ? defaultM axChannelO penDuratio n : mement o.getMaxCh annelOpenD uration(),  
  70                             mement o == null  ? defaultS weepTime :  memento.g etSweepTim e() 
  71                    );
  72           }
  73           
  74           /* *
  75            *  
  76            *  @param ma xChannelOp enDuration  - the max imum time  a channel  is allowed  to be ope n
  77            *  @param sw eepTime -  the delay  in the bac kground th read that  looks for  open chann els
  78            * /
  79           pr ivate Jcif sByteChann elFactory( Long maxCh annelOpenD uration, L ong sweepT ime)
  80           {
  81                    this .maxChanne lOpenDurat ion = maxC hannelOpen Duration.l ongValue() ;
  82                    this .sweepTime  = sweepTi me;
  83           }
  84  
  85           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =========
  86           //  InstanceB yteChannel Factory Im plementati on
  87           //  Behaviora l Modifica tion Metho ds
  88           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =========
  89           
  90           /*  (non-Java doc)
  91            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Insta nceByteCha nnelFactor yImplMBean #getMaxCha nnelOpenDu ration()
  92            * /
  93           pu blic long  getMaxChan nelOpenDur ation()
  94           {
  95                    retu rn maxChan nelOpenDur ation;
  96           }
  97           pu blic void  setMaxChan nelOpenDur ation(long  maxChanne lOpenDurat ion)
  98           {
  99                    if(m axChannelO penDuratio n > 0L)
  100                             this.m axChannelO penDuratio n = maxCha nnelOpenDu ration;
  101           }
  102  
  103           /*  (non-Java doc)
  104            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Insta nceByteCha nnelFactor yImplMBean #getSweepT ime()
  105            * /
  106           pu blic long  getSweepTi me()
  107           {
  108                    retu rn sweepTi me;
  109           }
  110           pu blic void  setSweepTi me(long sw eepTime)
  111           {
  112                    if(s weepTime >  0L)
  113                             this.s weepTime =  sweepTime ;
  114           }
  115           
  116           /*  (non-Java doc)
  117            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Insta nceByteCha nnelFactor yImplMBean #getCurren tlyOpenRea dableByteC hannels()
  118            * /
  119           pu blic int g etCurrentl yOpenReada bleByteCha nnels()
  120           {
  121                    retu rn openRea dChannels. size();
  122           }
  123  
  124           /*  (non-Java doc)
  125            *  @see gov. va.med.ima ging.stora ge.cache.i mpl.filesy stem.Insta nceByteCha nnelFactor yImplMBean #getCurren tlyOpenWri tableByteC hannels()
  126            * /
  127           pu blic int g etCurrentl yOpenWrita bleByteCha nnels()
  128           {
  129                    retu rn openWri teChannels .size();
  130           }
  131  
  132           /* *
  133            *  If traceC hannelInst antiation  is set the n the fact ory will r ecord
  134            *  the stack  trace whe n a channe l is insta ntiated an d report t he stack
  135            *  trace whe n the chan nel is clo sed due to  a timeout
  136            *  
  137            *  @return
  138            * /
  139           pu blic boole an isTrace ChannelIns tantiation ()
  140           {
  141                    retu rn this.tr aceChannel Instantiat ion;
  142           }
  143  
  144           pu blic void  setTraceCh annelInsta ntiation(b oolean tra ceChannelI nstantiati on)
  145           {
  146                    this .traceChan nelInstant iation = t raceChanne lInstantia tion;
  147           }
  148  
  149           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =========
  150           //  InstanceB yteChannel Factory Im plementati on
  151           //  Business  Methods
  152           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =========
  153           /*  (non-Java doc)
  154            *  @see gov. va.med.ima ging.stora ge.cache.f ilesystem. InstanceBy teChannelF actory#get InstanceRe adableByte Channel(ja va.io.File )
  155            * /
  156           pu blic Insta nceReadabl eByteChann el getInst anceReadab leByteChan nel(SmbFil e instance File, Inst anceByteCh annelListe ner timeou tListener)
  157           th rows Persi stenceIOEx ception, C acheExcept ion
  158           {
  159                    try
  160                    {
  161                             Instan ceReadable ByteChanne lImpl read able = new  InstanceR eadableByt eChannelIm pl(this, i nstanceFil e);
  162                             if(tim eoutListen er != null )
  163                                      this.put ReadableCh annel(read able, time outListene r);
  164                                      
  165                             return  readable;
  166                    } 
  167                    catc h (IOExcep tion ioX)
  168                    {
  169                             throw  new Persis tenceIOExc eption(ioX );
  170                    }
  171           }
  172           
  173           /*  (non-Java doc)
  174            *  @see gov. va.med.ima ging.stora ge.cache.f ilesystem. InstanceBy teChannelF actory#get InstanceWr itableByte Channel(ja va.io.File )
  175            * /
  176           pu blic Insta nceWritabl eByteChann el getInst anceWritab leByteChan nel(SmbFil e instance File, Inst anceByteCh annelListe ner timeou tListener)  
  177           th rows Persi stenceIOEx ception, C acheExcept ion
  178           {
  179                    try
  180                    {
  181                             Instan ceWritable ByteChanne lImpl writ able = new  InstanceW ritableByt eChannelIm pl(this, i nstanceFil e );
  182  
  183                             if(tim eoutListen er != null )
  184                                      putWrita bleChannel (writable,  timeoutLi stener);
  185                             
  186                             return  writable;
  187                    } 
  188                    catc h (IOExcep tion ioX)
  189                    {
  190                             throw  new Persis tenceIOExc eption(ioX );
  191                    }
  192           }
  193           
  194           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ======
  195           //  Open Read /Write Cha nnels list  managemen t.
  196           //  All acces s to these  maps shou ld go thro ugh the ca lls provid ed below s o that cor rect
  197           //  synchroni zation may  be provid ed.
  198           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ======
  199           pr ivate Map< InstanceWr itableByte ChannelImp l, Instanc eByteChann elListener > openWrit eChannels 
  200                    Coll ections.sy nchronized Map( new H ashMap<Ins tanceWrita bleByteCha nnelImpl,  InstanceBy teChannelL istener>()  );
  201           pr ivate Map< InstanceRe adableByte ChannelImp l, Instanc eByteChann elListener > openRead Channels =  
  202                    Coll ections.sy nchronized Map( new H ashMap<Ins tanceReada bleByteCha nnelImpl,  InstanceBy teChannelL istener>()  );
  203           
  204           pr ivate void  putWritab leChannel( InstanceWr itableByte ChannelImp l writable , Instance ByteChanne lListener  listener)
  205           {
  206                    open WriteChann els.put(wr itable, li stener);
  207           }
  208  
  209           pr ivate void  putReadab leChannel( InstanceRe adableByte ChannelImp l readable , Instance ByteChanne lListener  listener)
  210           {
  211                    open ReadChanne ls.put(rea dable, lis tener);
  212           }
  213           
  214           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =========
  215           //  InstanceB yteChannel Factory Im plementati on
  216           //  Statistic s Gatherin g Methods
  217           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =========
  218           /* *
  219            *  Look thro ugh our in ternal lis t of open  writable c hannels an d return a
  220            *  reference  to the by te channel  that is o pen on the  given fil e,
  221            *  or return  null if n ot open.
  222            *  
  223            *  @param in stanceFile
  224            *  @return
  225            * /
  226           In stanceWrit ableByteCh annelImpl  getOpenWri tableByteC hannel(Smb File insta nceFile)
  227           {
  228                    if(i nstanceFil e == null)
  229                             return  null;
  230                    
  231                    sync hronized(o penWriteCh annels)
  232                    {
  233                             for(In stanceWrit ableByteCh annelImpl  channel: o penWriteCh annels.key Set() )
  234                             {
  235                                      SmbFile  channelFil e = channe l.getFile( );
  236                                      
  237                                      if(insta nceFile.eq uals(chann elFile))
  238                                               return cha nnel;
  239                             }
  240                    }
  241                    
  242                    retu rn null;
  243           }
  244           
  245           /* *
  246            *  Look thro ugh our in ternal lis t of open  readable c hannels an d return a
  247            *  reference  to the by te channel  that is o pen on the  given fil e,
  248            *  or return  null if n ot open.
  249            *  
  250            *  @param in stanceFile
  251            *  @return
  252            * /
  253           In stanceRead ableByteCh annelImpl  getOpenRea dableByteC hannel(Smb File insta nceFile)
  254           {
  255                    if(i nstanceFil e == null)
  256                             return  null;
  257                    
  258                    sync hronized(o penReadCha nnels)
  259                    {
  260                             for(In stanceRead ableByteCh annelImpl  channel: o penReadCha nnels.keyS et() )
  261                             {
  262                                      SmbFile  channelFil e = channe l.getFile( );
  263                                      
  264                                      if(insta nceFile.eq uals(chann elFile))
  265                                               return cha nnel;
  266                             }
  267                    }
  268                    
  269                    retu rn null;
  270           }
  271           
  272           /* *
  273            *  This is N OT an idem potent met hod, it RE MOVES the  writable m ap entry.
  274            *  
  275            *  @param wr itable
  276            * /
  277           pr ivate void  notifyTim eoutWritab leChannelL isteners(I nstanceWri tableByteC hannelImpl  writable)
  278           {
  279                    writ ableByteCh annelClose d(writable , true);
  280           }
  281           
  282           /* *
  283            *  This is N OT an idem potent met hod, it RE MOVES the  readable m ap entry.
  284            *  
  285            *  @param re adable
  286            * /
  287           pr ivate void  notifyTim eoutReadab leChannelL isteners(I nstanceRea dableByteC hannelImpl  readable)
  288           {
  289                    read ableByteCh annelClose d(readable , true);
  290           }
  291           
  292           
  293           /* *
  294            *  Any shoul d call thi s to remov e the writ able byte  channel,
  295            *  else the  listeners  will get t imeout sig nals. 
  296            *  
  297            *  @param wr itable
  298            * /
  299           vo id writabl eByteChann elClosed(I nstanceWri tableByteC hannelImpl  writable,  boolean e rrorClose)
  300           {
  301                    Inst anceByteCh annelListe ner listen er = openW riteChanne ls.get(wri table);
  302                    open WriteChann els.remove (writable) ;
  303                    
  304                    if(l istener !=  null)
  305                    {
  306                             if(err orClose)
  307                                      listener .writeChan nelIdleTim eout(writa ble);
  308                             else
  309                                      listener .writeChan nelClose(w ritable);
  310                    }
  311           }
  312           /* *
  313            *  A 'normal ' close sh ould call  this to re move the r eadable by te channel ,
  314            *  else the  listeners  will get t imeout sig nals. 
  315            *  
  316            *  @param re adable
  317            * /
  318           vo id readabl eByteChann elClosed(I nstanceRea dableByteC hannelImpl  readable,  boolean e rrorClose)
  319           {
  320                    Inst anceByteCh annelListe ner listen er = openR eadChannel s.get(read able);
  321                    open ReadChanne ls.remove( readable);
  322                    
  323                    if(l istener !=  null)
  324                    {
  325                             if(err orClose)
  326                                      listener .readChann elIdleTime out(readab le);
  327                             else
  328                                      listener .readChann elClose(re adable);
  329                    }
  330           }
  331           
  332           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =
  333           //  State per sistence i mplementat ion
  334           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== =
  335           /* *
  336            *  Create a  Serializab le represe ntation of  our state  that may  be
  337            *  used late r to recre ate our st ate.
  338            *  
  339            *  @return
  340            * /
  341           pu blic ByteC hannelFact oryMemento  createMem ento()
  342           {
  343                    Byte ChannelFac toryMement o memento  = new Byte ChannelFac toryMement o();
  344                    
  345                    meme nto.setMax ChannelOpe nDuration( getMaxChan nelOpenDur ation());
  346                    meme nto.setSwe epTime(get SweepTime( ));
  347                    
  348                    retu rn memento ;
  349           }
  350  
  351           pu blic void  restoreMem ento(ByteC hannelFact oryMemento  memento)
  352           {
  353                    setM axChannelO penDuratio n( memento .getMaxCha nnelOpenDu ration() ) ;
  354                    setS weepTime(  memento.ge tSweepTime () );
  355           }
  356  
  357           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ======
  358           //  CacheLife cycleListe ner 
  359           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ======
  360           pu blic void  cacheLifec ycleEvent( CacheLifec ycleEvent  event) thr ows CacheS tateExcept ion
  361           {
  362                    if(e vent == Ca cheLifecyc leEvent.ST ART)
  363                    {
  364                             if(thi s.sweepTim e > 0L &&  this.maxCh annelOpenD uration >  0L)
  365                             {
  366                                      cleanupT hread = ne w ChannelC leanupThre ad(this.sw eepTime, t his.maxCha nnelOpenDu ration);
  367                                      cleanupT hread.star t();
  368                             }
  369                    }
  370                    else  if (event  == CacheL ifecycleEv ent.STOP)
  371                    {
  372                             if(cle anupThread  != null)
  373                                      cleanupT hread.kill ();
  374                    }
  375           }
  376  
  377           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ======
  378           //  JMX (mana gement) re lated meth ods (Dynam icMBean im plementati on)
  379           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ======
  380           
  381           /* *
  382            *  @see java x.manageme nt.Dynamic MBean#getM BeanInfo()
  383            * /
  384           pr ivate MBea nInfo open MBeanInfo;
  385           pu blic synch ronized MB eanInfo ge tMBeanInfo ()
  386           {
  387                    if(o penMBeanIn fo == null )
  388                    {
  389                             openMB eanInfo =  new OpenMB eanInfoSup port(
  390                                               getClass() .getName() ,
  391                         "Byte chan nel factor y for file  system ba sed cache  implementa tions.",
  392                         new OpenMB eanAttribu teInfo[] 
  393                         {
  394                                                       ne w OpenMBea nAttribute InfoSuppor t("maxChan nelOpenDur ation", "M aximum tim e in milli seconds be tween chan nel usage" , SimpleTy pe.LONG, t rue, true,  false),
  395                                                       ne w OpenMBea nAttribute InfoSuppor t("sweepTi me", "Time  to delay  between sw eeping ope n channels ", SimpleT ype.LONG,  true, true , false),
  396                                                       ne w OpenMBea nAttribute InfoSuppor t("traceCh annelInsta ntiation",  "Trace th e code tha t opened c hannels",  SimpleType .BOOLEAN,  true, true , true),
  397                                                       ne w OpenMBea nAttribute InfoSuppor t("openRea dableByteC hannels",  "Number of  read chan nels curre ntly open" , SimpleTy pe.INTEGER , true, fa lse, false ),
  398                                                       ne w OpenMBea nAttribute InfoSuppor t("openWri tableByteC hannels",  "Number of  write cha nnels curr ently open ", SimpleT ype.INTEGE R, true, f alse, fals e)
  399                         },
  400                         new OpenMB eanConstru ctorInfo[] {},
  401                         new OpenMB eanOperati onInfo[]{} ,
  402                         new MBeanN otificatio nInfo[]{}
  403                             );
  404                    }
  405                    
  406                    retu rn openMBe anInfo;
  407           }
  408  
  409           /* *
  410            *  @see java x.manageme nt.Dynamic MBean#getA ttribute(j ava.lang.S tring)
  411            * /
  412           pu blic Objec t getAttri bute(Strin g attribut e) 
  413           th rows Attri buteNotFou ndExceptio n, MBeanEx ception, R eflectionE xception
  414           {
  415                    if(  "maxChanne lOpenDurat ion".equal s(attribut e) )
  416                             return  new Long( getMaxChan nelOpenDur ation());
  417                    else  if( "swee pTime".equ als(attrib ute) )
  418                             return  new Long( getSweepTi me());
  419                    else  if( "trac eChannelIn stantiatio n".equals( attribute)  )
  420                             return  new Boole an(isTrace ChannelIns tantiation ());
  421                    else  if( "open ReadableBy teChannels ".equals(a ttribute)  )
  422                             return  new Integ er(getCurr entlyOpenR eadableByt eChannels( ));
  423                    else  if( "open WritableBy teChannels ".equals(a ttribute)  )
  424                             return  new Integ er(getCurr entlyOpenW ritableByt eChannels( ));
  425                    else
  426                             throw  new Attrib uteNotFoun dException ("Attribut e '" + att ribute + " ' not foun d");
  427           }
  428  
  429           /* *
  430            *  @see java x.manageme nt.Dynamic MBean#getA ttributes( java.lang. String[])
  431            * /
  432           pu blic Attri buteList g etAttribut es(String[ ] attribut es)
  433           {
  434                    Attr ibuteList  list = new  Attribute List();
  435                    for( String att ribute:att ributes)
  436                             try
  437                             {
  438                                      list.add ( new Attr ibute(attr ibute, get Attribute( attribute) ) );
  439                             } 
  440                             catch  (Attribute NotFoundEx ception x)
  441                             {
  442                                      x.printS tackTrace( );
  443                             } 
  444                             catch  (MBeanExce ption x)
  445                             {
  446                                      x.printS tackTrace( );
  447                             } 
  448                             catch  (Reflectio nException  x)
  449                             {
  450                                      x.printS tackTrace( );
  451                             }
  452                    retu rn list;
  453           }
  454  
  455           /* *
  456            *  @see java x.manageme nt.Dynamic MBean#setA ttribute(j avax.manag ement.Attr ibute)
  457            * /
  458           pu blic void  setAttribu te(Attribu te attribu te) 
  459           th rows Attri buteNotFou ndExceptio n, Invalid AttributeV alueExcept ion, MBean Exception,  Reflectio nException
  460           {
  461                    try
  462                    {
  463                             if( "m axChannelO penDuratio n".equals( attribute. getName())  )
  464                                      setMaxCh annelOpenD uration( ( Long)attri bute.getVa lue() );
  465                             else i f( "sweepT ime".equal s(attribut e.getName( )) )
  466                                      setSweep Time( (Lon g)attribut e.getValue () );
  467                             else i f( "traceC hannelInst antiation" .equals(at tribute.ge tName()) )
  468                                      setTrace ChannelIns tantiation ( (Boolean )attribute .getValue( ) );
  469                             else
  470                                      throw ne w Attribut eNotFoundE xception(" Attribute  '" + attri bute + "'  not found. ");
  471                    } 
  472                    catc h (ClassCa stExceptio n x)
  473                    {
  474                             throw  new Invali dAttribute ValueExcep tion("Attr ibute '" +  attribute  + "' valu es was of  incorrect  type.");
  475                    }
  476           }
  477  
  478           /* *
  479            *  @see java x.manageme nt.Dynamic MBean#setA ttributes( javax.mana gement.Att ributeList )
  480            * /
  481           pu blic Attri buteList s etAttribut es(Attribu teList att ributes)
  482           {
  483                    for( int index= 0; index <  attribute s.size();  ++index)
  484                    {
  485                             Attrib ute attrib ute = (Att ribute)att ributes.ge t(index);
  486                             
  487                             try
  488                             {
  489                                      setAttri bute(attri bute);
  490                             } 
  491                             catch  (Attribute NotFoundEx ception x)
  492                             {
  493                                      x.printS tackTrace( );
  494                             } 
  495                             catch  (InvalidAt tributeVal ueExceptio n x)
  496                             {
  497                                      x.printS tackTrace( );
  498                             } 
  499                             catch  (MBeanExce ption x)
  500                             {
  501                                      x.printS tackTrace( );
  502                             } 
  503                             catch  (Reflectio nException  x)
  504                             {
  505                                      x.printS tackTrace( );
  506                             }
  507                    }
  508                    
  509                    retu rn attribu tes;
  510           }
  511           
  512           /* *
  513            *  @see java x.manageme nt.Dynamic MBean#invo ke(java.la ng.String,  java.lang .Object[],  java.lang .String[])
  514            * /
  515           pu blic Objec t invoke(S tring acti onName, Ob ject[] par ams, Strin g[] signat ure) 
  516           th rows MBean Exception,  Reflectio nException
  517           {
  518                    retu rn null;
  519           }
  520  
  521           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ======
  522           //  The threa d that mon itors and  cleans up  channels t hat have b een left h anging
  523           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ======
  524           /* *
  525            *  
  526              * @author  DN S      BECKEC
  527            *
  528            * /
  529           cl ass Channe lCleanupTh read 
  530           ex tends Thre ad
  531           {
  532                    priv ate long s weepInterv al;
  533                    priv ate long m axChannelO penDuratio n;
  534                    priv ate boolea n running  = true;
  535                    
  536                    Chan nelCleanup Thread(lon g sweepInt erval, lon g maxChann elOpenDura tion)
  537                    {
  538                             this.s weepInterv al = sweep Interval;
  539                             this.m axChannelO penDuratio n = maxCha nnelOpenDu ration;
  540                             
  541                             this.s etDaemon(t rue);
  542                    }
  543                    
  544                    publ ic void ki ll()
  545                    {
  546                             this.r unning = f alse;
  547                             this.i nterrupt() ;
  548                    }
  549  
  550                    @Ove rride
  551                    publ ic void ru n()
  552                    {
  553                             while( running)
  554                             {
  555                                      long min OpenTime =  System.cu rrentTimeM illis() -  maxChannel OpenDurati on;
  556                                      
  557                                      log.info ("Sweeping  write cha nnels open  before "  + df.forma t(minOpenT ime));
  558                                      try
  559                                      {
  560                                               List<Insta nceWritabl eByteChann elImpl> wr iteChannel KillList =  new Array List<Insta nceWritabl eByteChann elImpl>();
  561                                               try
  562                                               {
  563                                                       //  do the ki ll/close i n two loop s to avoid  concurren t modifica tion excep tions
  564                                                       fo r( Instanc eWritableB yteChannel Impl write Channel:op enWriteCha nnels.keyS et() )
  565                                                       {
  566                                                                if(  writeChann el.getLast AccessedTi me() < min OpenTime )
  567                                                                {
  568                                                                         log.wa rn("Writab le Byte Ch annel " +  writeChann el.toStrin g() + " ha s remained  open past  the maxim um allowab le, forcin g close!"  );
  569                                                                         writeC hannelKill List.add(w riteChanne l);
  570                                                                         
  571                                                                         if(isT raceChanne lInstantia tion())
  572                                                                         {
  573                                                                                  StackTra ceElement[ ] instanti atingStack Trace = wr iteChannel .getInstan tiatingSta ckTrace();
  574                                                                                  warnInst antiatingS tackTrace( instantiat ingStackTr ace);
  575                                                                         }
  576                                                                }
  577                                                       }
  578                                               }
  579                                               catch(Conc urrentModi ficationEx ception cm X)
  580                                               {
  581                                                       //  note that  if we get  a concurr ent modifi cation (i. e. another  thread is  opening o r closing  readable c hannels)
  582                                                       //  then log  it but don 't fail 'c ause we ca n always c lose the c hannel lat er
  583                                                       lo g.info("Co ncurrent m odificatio n exceptio n while it erating op en write c hannels, s ome overdu e channels  may not b e closed i mmediately .");
  584                                               }
  585                                              
  586                                               log.info(" Closing "  + writeCha nnelKillLi st.size()  + " write  channels d ue to inac tivity tim eout");
  587                                               for(Instan ceWritable ByteChanne lImpl dead Channel:wr iteChannel KillList)
  588                                               {
  589                                                       tr y
  590                                                       {
  591                                                                dead Channel.er ror();
  592                                                       } 
  593                                                       ca tch (IOExc eption e)
  594                                                       {
  595                                                                log. error(e);
  596                                                       }
  597                                                       no tifyTimeou tWritableC hannelList eners(dead Channel);
  598                                                       op enWriteCha nnels.remo ve(deadCha nnel);
  599                                               }
  600                                              
  601                                               log.info(" Sweeping r ead channe ls open be fore " + d f.format(m inOpenTime ));
  602                                               List<Insta nceReadabl eByteChann elImpl> re adChannelK illList =  new ArrayL ist<Instan ceReadable ByteChanne lImpl>();
  603                                              
  604                                               // do the  kill/close  in two lo ops to avo id concurr ent modifi cation exc eptions
  605                                               try
  606                                               {
  607                                                       fo r( Instanc eReadableB yteChannel Impl readC hannel:ope nReadChann els.keySet () )
  608                                                       {
  609                                                                if(  readChanne l.getLastA ccessedTim e() < minO penTime )
  610                                                                {
  611                                                                         log.wa rn("Readab le Byte Ch annel " +  readChanne l.toString () + " has  remained  open past  the maximu m allowabl e, notifyi ng listene rs" );
  612                                                                         readCh annelKillL ist.add(re adChannel) ;
  613                                                                         
  614                                                                         if(isT raceChanne lInstantia tion())
  615                                                                         {
  616                                                                                  StackTra ceElement[ ] instanti atingStack Trace = re adChannel. getInstant iatingStac kTrace();
  617                                                                                  warnInst antiatingS tackTrace( instantiat ingStackTr ace);
  618                                                                         }
  619                                                                }
  620                                                       }
  621                                               }
  622                                               catch(Conc urrentModi ficationEx ception cm X)
  623                                               {
  624                                                       //  note that  if we get  a concurr ent modifi cation (i. e. another  thread is  opening o r closing  readable c hannels)
  625                                                       //  then log  it but don 't fail 'c ause we ca n always c lose the c hannel lat er
  626                                                       lo g.info("Co ncurrent m odificatio n exceptio n while it erating op en read ch annels, so me overdue  channels  may not be  closed im mediately. ");
  627                                               }
  628                                              
  629                                               log.info(" Closing "  + readChan nelKillLis t.size() +  " read ch annels due  to inacti vity timeo ut");
  630                                               for(Instan ceReadable ByteChanne lImpl dead Channel:re adChannelK illList)
  631                                               {
  632                                                       tr y
  633                                                       {
  634                                                                dead Channel.cl ose();
  635                                                       } 
  636                                                       ca tch (IOExc eption e)
  637                                                       {
  638                                                                log. error(e);
  639                                                       }
  640                                                       no tifyTimeou tReadableC hannelList eners(dead Channel);
  641                                                       op enReadChan nels.remov e(deadChan nel);
  642                                               }
  643                                              
  644                                               sleep(swee pInterval) ;
  645                                      } 
  646                                      catch (I nterrupted Exception  e)
  647                                      {
  648                                               // if some one interr upts us th en run the  thread ou t, we're d one
  649                                               log.error( e);
  650                                               break;
  651                                      }
  652                             }
  653                    }
  654                    
  655                    /*
  656                     * L og warning  about who  is leavin g channels  open, if  the info i s availabl e, else
  657                     * j ujst log m essages th at a chann el was lef t open.
  658                     */
  659                    priv ate void w arnInstant iatingStac kTrace(Sta ckTraceEle ment[] ins tantiating StackTrace )
  660                    {
  661                             if(ins tantiating StackTrace  != null)
  662                             {
  663                                      StackTra ceAnalyzer  stAnalyze r = new St ackTraceAn alyzer(ins tantiating StackTrace );
  664                                      StackTra ceElement  element =  stAnalyzer .getFirstE lementNotI nPackageHi erarchy("g ov.va.med. imaging.st orage.cach e");
  665                                      if(eleme nt != null )
  666                                               log.warn(" Method '"  + element. getClassNa me() + "."  + element .getMethod Name() + " ' (or some thing it c alls) is o pening cha nnels that  are not b eing close d." + 
  667                                                                "Ent ire call s tack is:\n " + stAnal yzer.toStr ing());
  668                                      else
  669                                               log.warn(" Some metho d in this  stack trac e is openi ng channel s that are  not being  closed:\n " + stAnal yzer.toStr ing());
  670                             }
  671                             else
  672                                      log.warn ("Stack Tr ace analys is of chan nel instan tiating me thod is no t availabl e.  Turn T raceChanne lInstantia tion on to  find the  offending  code.");
  673                             
  674                    }
  675           }                 // end  ChannelCl eanup
  676   }